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

Source Code for Module gui.user_functions.grace

  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  import wx 
 28   
 29  # relax module imports. 
 30  from relax_errors import RelaxImplementError, RelaxNoPipeError 
 31  import specific_fns 
 32   
 33  # GUI module imports. 
 34  from base import UF_base, UF_page 
 35  from gui.errors import gui_raise 
 36  from gui.misc import gui_to_bool, gui_to_str, str_to_gui 
 37  from gui.paths import WIZARD_IMAGE_PATH 
 38   
 39   
 40  # The container class. 
41 -class Grace(UF_base):
42 """The container class for holding all GUI elements.""" 43
44 - def view(self, file=None):
45 """The grace.view user function. 46 47 @keyword file: The file to start the user function with. 48 @type file: str 49 """ 50 51 # Create the wizard. 52 wizard, page = self.create_wizard(size_x=900, size_y=500, name='grace.view', uf_page=View_page, return_page=True) 53 54 # Default file name. 55 if file: 56 page.file.SetValue(str_to_gui(file)) 57 58 # Execute the wizard. 59 wizard.run()
60 61
62 - def write(self, file=None):
63 """The grace.write user function. 64 65 @keyword file: The file to start the user function with. 66 @type file: str 67 """ 68 69 # Create the wizard. 70 wizard, page = self.create_wizard(size_x=1000, size_y=700, name='grace.write', uf_page=Write_page, return_page=True) 71 72 # Default file name. 73 if file: 74 page.file.SetValue(str_to_gui(file)) 75 76 # Execute the wizard. 77 wizard.run()
78 79 80
81 -class View_page(UF_page):
82 """The grace.view() user function page.""" 83 84 # Some class variables. 85 image_path = WIZARD_IMAGE_PATH + 'grace.png' 86 uf_path = ['grace', 'view'] 87
88 - def add_contents(self, sizer):
89 """Add the specific GUI elements. 90 91 @param sizer: A sizer object. 92 @type sizer: wx.Sizer instance 93 """ 94 95 # Add a file selection. 96 self.file = self.file_selection(sizer, "The Grace file:", message="Grace file selection", wildcard="Grace files (*.agr)|*.agr", style=wx.FD_OPEN, tooltip=self.uf._doc_args_dict['file']) 97 98 # The Grace exec file. 99 self.grace_exe = self.file_selection(sizer, "The Grace executable:", message="Grace executable file selection", style=wx.FD_OPEN, tooltip=self.uf._doc_args_dict['grace_exe']) 100 self.grace_exe.SetValue(str_to_gui('xmgrace'))
101 102
103 - def on_execute(self):
104 """Execute the user function.""" 105 106 # The file name. 107 file = gui_to_str(self.file.GetValue()) 108 109 # The executable. 110 grace_exe = gui_to_str(self.grace_exe.GetValue()) 111 112 # Open the file. 113 self.execute('grace.view', file=file, dir=None, grace_exe=grace_exe)
114 115 116
117 -class Write_page(UF_page):
118 """The grace.write() user function page.""" 119 120 # Some class variables. 121 image_path = WIZARD_IMAGE_PATH + 'grace.png' 122 uf_path = ['grace', 'write'] 123
124 - def add_contents(self, sizer):
125 """Add the specific GUI elements. 126 127 @param sizer: A sizer object. 128 @type sizer: wx.Sizer instance 129 """ 130 131 # The X-axis data. 132 self.x_data_type = self.combo_box(sizer, "The X-axis data type:", tooltip=self.uf._doc_args_dict['x_data_type']) 133 self.update_parameters(self.x_data_type) 134 135 # Failure. 136 if self.setup_fail: 137 return 138 139 # The Y-axis data. 140 self.y_data_type = self.combo_box(sizer, "The Y-axis data type:", tooltip=self.uf._doc_args_dict['y_data_type']) 141 self.update_parameters(self.y_data_type) 142 143 # The spin ID restriction. 144 self.spin_id = self.spin_id_element(sizer, "Restrict plotting to certain spins:") 145 146 # The plot data. 147 self.plot_data = self.combo_box(sizer, "The plot data:", ['value', 'error', 'sims'], tooltip=self.uf._doc_args_dict['plot_data'], read_only=True) 148 self.plot_data.SetValue(str_to_gui('value')) 149 150 # Data normalisation. 151 self.norm = self.boolean_selector(sizer, "Data normalisation flag:", tooltip=self.uf._doc_args_dict['norm'], default=False) 152 153 # Add a file selection. 154 self.file = self.file_selection(sizer, "The Grace file:", message="Grace file selection", wildcard="Grace files (*.agr)|*.agr", style=wx.FD_SAVE, tooltip=self.uf._doc_args_dict['file']) 155 156 # The force flag. 157 self.force = self.boolean_selector(sizer, "Force flag:", tooltip=self.uf._doc_args_dict['force'])
158 159
160 - def on_execute(self):
161 """Execute the user function.""" 162 163 # The X and Y data types. 164 x_data_type = self.x_data_type.GetClientData(self.x_data_type.GetSelection()) 165 y_data_type = self.y_data_type.GetClientData(self.y_data_type.GetSelection()) 166 167 # Get the values. 168 spin_id = gui_to_str(self.spin_id.GetValue()) 169 plot_data = gui_to_str(self.plot_data.GetValue()) 170 norm = gui_to_bool(self.norm.GetValue()) 171 172 # The file name. 173 file = gui_to_str(self.file.GetValue()) 174 if not file: 175 return 176 177 # Force flag. 178 force = gui_to_bool(self.force.GetValue()) 179 180 # Open the file. 181 self.execute('grace.write', x_data_type=x_data_type, y_data_type=y_data_type, spin_id=spin_id, plot_data=plot_data, file=file, dir=None, force=force, norm=norm)
182 183
184 - def update_parameters(self, combo_box):
185 """Fill out the list of parameters and their descriptions. 186 187 @param combo_box: The combo box element to update. 188 @type combo_box: wx.ComboBox instance 189 """ 190 191 # Check the current data pipe. 192 if cdp == None: 193 gui_raise(RelaxNoPipeError()) 194 self.setup_fail = True 195 return 196 197 # Get the specific functions. 198 data_names = specific_fns.setup.get_specific_fn('data_names', cdp.pipe_type, raise_error=False) 199 self.data_type = specific_fns.setup.get_specific_fn('data_type', cdp.pipe_type, raise_error=False) 200 return_data_desc = specific_fns.setup.get_specific_fn('return_data_desc', cdp.pipe_type, raise_error=False) 201 202 # The data names, if they exist. 203 try: 204 names = data_names(set='params') 205 except RelaxImplementError: 206 gui_raise(RelaxImplementError()) 207 self.setup_fail = True 208 return 209 210 # First clear and then add the sequence data. 211 combo_box.Clear() 212 combo_box.Append(str_to_gui("Spin sequence"), 'spin') 213 214 # Loop over the parameters. 215 for name in (data_names(set='params') + data_names(set='generic')): 216 # Get the description. 217 desc = return_data_desc(name) 218 219 # No description. 220 if not desc: 221 text = name 222 223 # The text. 224 else: 225 text = "'%s': %s" % (name, desc) 226 227 # Append the description. 228 combo_box.Append(str_to_gui(text), name) 229 230 # Default to the sequence. 231 combo_box.SetSelection(0)
232