Package gui :: Package user_functions :: Module value
[hide private]
[frames] | no frames]

Source Code for Module gui.user_functions.value

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """The value user function GUI elements.""" 
 25   
 26  # Python module imports. 
 27  from os import sep 
 28   
 29  # relax module imports. 
 30  from generic_fns import pipes 
 31  from relax_errors import RelaxError, RelaxImplementError, RelaxNoPipeError 
 32  import specific_fns 
 33   
 34  # GUI module imports. 
 35  from base import UF_base, UF_page 
 36  from gui.errors import gui_raise 
 37  from gui.misc import gui_to_str, str_to_gui 
 38  from gui.paths import WIZARD_IMAGE_PATH 
 39   
 40   
 41  # The container class. 
42 -class Value(UF_base):
43 """The container class for holding all GUI elements.""" 44
45 - def set(self, param=None):
46 """The value.set user function. 47 48 @keyword param: The starting parameter. 49 @type param: str 50 """ 51 52 # Create the wizard. 53 wizard, page = self.create_wizard(size_x=1000, size_y=800, name='value.set', uf_page=Set_page, return_page=True) 54 55 # Default parameter. 56 page.set_param(param) 57 58 # Execute the wizard. 59 wizard.run()
60 61 62
63 -class Set_page(UF_page):
64 """The value.set() user function page.""" 65 66 # Some class variables. 67 image_path = WIZARD_IMAGE_PATH + 'value' + sep + 'value.png' 68 uf_path = ['value', 'set'] 69 height_desc = 400 70
71 - def add_contents(self, sizer):
72 """Add the sequence specific GUI elements. 73 74 @param sizer: A sizer object. 75 @type sizer: wx.Sizer instance 76 """ 77 78 # The parameter. 79 self.param = self.combo_box(sizer, "The parameter:", tooltip=self.uf._doc_args_dict['param'], evt_fn=self.set_default_value) 80 self.update_parameters() 81 82 # The value. 83 self.val = self.input_field(sizer, "The value:", tooltip=self.uf._doc_args_dict['val']) 84 85 # The spin ID restriction. 86 self.spin_id = self.spin_id_element(sizer, "Restrict value setting to certain spins:")
87 88
89 - def on_execute(self):
90 """Execute the user function.""" 91 92 # The parameter. 93 param = self.param.GetClientData(self.param.GetSelection()) 94 95 # The value (converted to the correct type). 96 val_str = gui_to_str(self.val.GetValue()) 97 val_type = self.data_type(param) 98 99 # Evaluate numbers. 100 if val_type in [float, int]: 101 fn = eval 102 else: 103 fn = val_type 104 105 # Convert. 106 try: 107 val = fn(val_str) 108 except (ValueError, NameError): 109 gui_raise(RelaxError("The value '%s' should be of the type %s." % (val_str, val_type)), raise_flag=False) 110 return 111 112 # The spin ID. 113 spin_id = gui_to_str(self.spin_id.GetValue()) 114 115 # Set the value. 116 self.execute('value.set', val=val, param=param, spin_id=spin_id)
117 118
119 - def set_default_value(self, event=None):
120 """Set the value to the default once a parameter is selected. 121 122 @param event: The wx event. 123 @type event: wx event 124 """ 125 126 # The parameter. 127 param = self.param.GetClientData(self.param.GetSelection()) 128 129 # Clear the previous data. 130 self.val.Clear() 131 132 # Nothing to do. 133 if param == '': 134 return 135 136 # Get the default value. 137 default_value = specific_fns.setup.get_specific_fn('default_value', cdp.pipe_type, raise_error=False) 138 value = default_value(param) 139 140 # Set the default value. 141 if value != None: 142 self.val.SetValue(str_to_gui(str(value)))
143 144
145 - def set_param(self, param):
146 """Set the selection to the given parameter. 147 148 @keyword param: The starting parameter. 149 @type param: str 150 """ 151 152 # Nothing to do. 153 if param == None: 154 return 155 156 # Find the parameter in the list. 157 for i in range(self.param.GetCount()): 158 if param == self.param.GetClientData(i): 159 self.param.SetSelection(i) 160 161 # Set the default value. 162 self.set_default_value()
163 164
165 - def update_parameters(self):
166 """Fill out the list of parameters and their descriptions.""" 167 168 # Check the current data pipe. 169 if cdp == None: 170 gui_raise(RelaxNoPipeError()) 171 self.setup_fail = True 172 return 173 174 # Get the specific functions. 175 data_names = specific_fns.setup.get_specific_fn('data_names', cdp.pipe_type, raise_error=False) 176 self.data_type = specific_fns.setup.get_specific_fn('data_type', cdp.pipe_type, raise_error=False) 177 return_data_desc = specific_fns.setup.get_specific_fn('return_data_desc', cdp.pipe_type, raise_error=False) 178 179 # The data names, if they exist. 180 try: 181 names = data_names(set='params') 182 except RelaxImplementError: 183 gui_raise(RelaxImplementError()) 184 self.setup_fail = True 185 return 186 187 # Clear the previous data. 188 self.param.Clear() 189 190 # Loop over the parameters. 191 for name in (data_names(set='params') + data_names(set='generic')): 192 # Get the description. 193 desc = return_data_desc(name) 194 195 # No description. 196 if not desc: 197 text = name 198 199 # The text. 200 else: 201 text = "'%s': %s" % (name, desc) 202 203 # Append the description. 204 self.param.Append(str_to_gui(text), name)
205