Package gui :: Package components :: Module relax_data
[hide private]
[frames] | no frames]

Source Code for Module gui.components.relax_data

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2011 Michael Bieri                                       # 
  4  # Copyright (C) 2010-2012 Edward d'Auvergne                                   # 
  5  #                                                                             # 
  6  # This file is part of the program relax.                                     # 
  7  #                                                                             # 
  8  # relax is free software; you can redistribute it and/or modify               # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation; either version 2 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # relax is distributed in the hope that it will be useful,                    # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with relax; if not, write to the Free Software                        # 
 20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Module docstring. 
 25  """Module containing the classes for GUI components involving relaxation data.""" 
 26   
 27  # Python module imports. 
 28  import wx 
 29  import wx.lib.buttons 
 30   
 31  # relax module imports. 
 32  from graphics import fetch_icon 
 33  from status import Status; status = Status() 
 34  from user_functions.data import Uf_info; uf_info = Uf_info() 
 35   
 36  # relax GUI module imports. 
 37  from gui.components.base_list import Base_list 
 38  from gui.components.menu import build_menu_item 
 39  from gui.components.relax_data_meta import Relax_data_meta_list 
 40  from gui.fonts import font 
 41  from gui.icons import relax_icons 
 42  from gui.misc import add_border 
 43  from gui.string_conv import float_to_gui, gui_to_str, str_to_gui 
 44  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 45  from gui.wizard import Wiz_window 
 46   
 47   
48 -class Relax_data_list(Base_list):
49 """The GUI element for listing loaded relaxation data.""" 50
51 - def action_relax_data_delete(self, event):
52 """Launch the relax_data.delete user function. 53 54 @param event: The wx event. 55 @type event: wx event 56 """ 57 58 # The current selection. 59 item = self.element.GetFirstSelected() 60 61 # No selection. 62 if item == -1: 63 id = None 64 65 # Selected item. 66 else: 67 # The spectrum ID. 68 id = gui_to_str(self.element.GetItemText(item)) 69 70 # Launch the dialog. 71 uf_store['relax_data.delete'](ri_id=id)
72 73
74 - def action_relax_data_display(self, event):
75 """Launch the relax_data.display user function. 76 77 @param event: The wx event. 78 @type event: wx event 79 """ 80 81 # The current selection. 82 item = self.element.GetFirstSelected() 83 84 # The spectrum ID. 85 id = gui_to_str(self.element.GetItemText(item)) 86 87 # Launch the dialog. 88 uf_store['relax_data.display'](ri_id=id)
89 90
91 - def action_relax_data_frq(self, event):
92 """Launch the relax_data.frq user function. 93 94 @param event: The wx event. 95 @type event: wx event 96 """ 97 98 # The current selection. 99 item = self.element.GetFirstSelected() 100 101 # The spectrum ID. 102 id = gui_to_str(self.element.GetItemText(item)) 103 104 # The current frequency. 105 frq = None 106 if hasattr(cdp, 'frq') and id in cdp.frq.keys(): 107 frq = cdp.frq[id] 108 109 # Launch the dialog. 110 if frq == None: 111 uf_store['relax_data.frq'](ri_id=id) 112 else: 113 uf_store['relax_data.frq'](ri_id=id, frq=frq)
114 115
117 """Launch the relax_data.peak_intensity_type user function. 118 119 @param event: The wx event. 120 @type event: wx event 121 """ 122 123 # The current selection. 124 item = self.element.GetFirstSelected() 125 126 # The spectrum ID. 127 id = gui_to_str(self.element.GetItemText(item)) 128 129 # The current type. 130 type = None 131 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'peak_intensity_type') and id in cdp.exp_info.peak_intensity_type.keys(): 132 type = cdp.exp_info.peak_intensity_type[id] 133 134 # Launch the dialog. 135 if type == None: 136 uf_store['relax_data.peak_intensity_type'](ri_id=id) 137 else: 138 uf_store['relax_data.peak_intensity_type'](ri_id=id, type=type)
139 140
141 - def action_relax_data_temp_calibration(self, event):
142 """Launch the relax_data.temp_calibration user function. 143 144 @param event: The wx event. 145 @type event: wx event 146 """ 147 148 # The current selection. 149 item = self.element.GetFirstSelected() 150 151 # The spectrum ID. 152 id = gui_to_str(self.element.GetItemText(item)) 153 154 # The current method. 155 method = None 156 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_calibration') and id in cdp.exp_info.temp_calibration.keys(): 157 method = cdp.exp_info.temp_calibration[id] 158 159 # Launch the dialog. 160 if method == None: 161 uf_store['relax_data.temp_calibration'](ri_id=id) 162 else: 163 uf_store['relax_data.temp_calibration'](ri_id=id, method=method)
164 165
166 - def action_relax_data_temp_control(self, event):
167 """Launch the relax_data.temp_control user function. 168 169 @param event: The wx event. 170 @type event: wx event 171 """ 172 173 # The current selection. 174 item = self.element.GetFirstSelected() 175 176 # The spectrum ID. 177 id = gui_to_str(self.element.GetItemText(item)) 178 179 # The current method. 180 method = None 181 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_control') and id in cdp.exp_info.temp_control.keys(): 182 method = cdp.exp_info.temp_control[id] 183 184 # Launch the dialog. 185 if method == None: 186 uf_store['relax_data.temp_control'](ri_id=id) 187 else: 188 uf_store['relax_data.temp_control'](ri_id=id, method=method)
189 190
191 - def action_relax_data_type(self, event):
192 """Launch the relax_data.type user function. 193 194 @param event: The wx event. 195 @type event: wx event 196 """ 197 198 # The current selection. 199 item = self.element.GetFirstSelected() 200 201 # The spectrum ID. 202 id = gui_to_str(self.element.GetItemText(item)) 203 204 # The current type. 205 type = None 206 if hasattr(cdp, 'ri_type') and id in cdp.ri_type.keys(): 207 type = cdp.ri_type[id] 208 209 # Launch the dialog. 210 if type == None: 211 uf_store['relax_data.type'](ri_id=id) 212 else: 213 uf_store['relax_data.type'](ri_id=id, ri_type=type)
214 215
216 - def setup(self):
217 """Override the base variables.""" 218 219 # GUI variables. 220 self.title = "Relaxation data list" 221 self.observer_base_name = "relaxation data list" 222 223 # The column titles. 224 self.columns = [ 225 "Relaxation data ID", 226 "Data type", 227 "Frequency (Hz)" 228 ] 229 230 # Button set up. 231 self.button_placement = 'top' 232 self.button_size = (170, 40) 233 self.button_info = [ 234 { 235 'object': 'button_add', 236 'label': ' Add', 237 'icon': fetch_icon('oxygen.actions.list-add-relax-blue', "22x22"), 238 'method': self.wizard_relax_data, 239 'tooltip': "Read relaxation data from a file." 240 }, { 241 'object': 'button_bruker', 242 'label': ' Add', 243 'icon': fetch_icon('relax.bruker_add', "22x22"), 244 'method': self.wizard_bruker, 245 'tooltip': "Read a Bruker Dynamics Center relaxation data file." 246 }, { 247 'object': 'button_delete', 248 'label': ' Delete', 249 'icon': fetch_icon('oxygen.actions.list-remove', "22x22"), 250 'method': self.action_relax_data_delete, 251 'tooltip': "Delete loaded relaxation data from the relax data store." 252 }, { 253 'object': 'button_metadata', 254 'label': ' View metadata', 255 'icon': fetch_icon('oxygen.mimetypes.text-x-texinfo', "22x22"), 256 'method': self.view_metadata, 257 'tooltip': "View and edit the relaxation data metadata." 258 } 259 ] 260 261 # The right click popup menu. 262 self.popup_menus = [ 263 { 264 'id': wx.NewId(), 265 'text': "&Delete the relaxation data", 266 'icon': fetch_icon(uf_info.get_uf('relax_data.delete').gui_icon), 267 'method': self.action_relax_data_delete 268 }, { 269 'id': wx.NewId(), 270 'text': "Dis&play the relaxation data", 271 'icon': fetch_icon(uf_info.get_uf('relax_data.display').gui_icon), 272 'method': self.action_relax_data_display 273 }, { 274 'id': wx.NewId(), 275 'text': "Set the relaxation data &frequency", 276 'icon': fetch_icon(uf_info.get_uf('relax_data.frq').gui_icon), 277 'method': self.action_relax_data_frq 278 }, { 279 'id': wx.NewId(), 280 'text': "Set the peak &intensity type", 281 'icon': fetch_icon(uf_info.get_uf('relax_data.peak_intensity_type').gui_icon), 282 'method': self.action_relax_data_peak_intensity_type 283 }, { 284 'id': wx.NewId(), 285 'text': "Set the temperature &calibration", 286 'icon': fetch_icon(uf_info.get_uf('relax_data.temp_calibration').gui_icon), 287 'method': self.action_relax_data_temp_calibration 288 }, { 289 'id': wx.NewId(), 290 'text': "Set the temperature c&ontrol", 291 'icon': fetch_icon(uf_info.get_uf('relax_data.temp_control').gui_icon), 292 'method': self.action_relax_data_temp_control 293 }, { 294 'id': wx.NewId(), 295 'text': "Set the relaxation data &type", 296 'icon': fetch_icon(uf_info.get_uf('relax_data.type').gui_icon), 297 'method': self.action_relax_data_type 298 }, { 299 } 300 ]
301 302
303 - def update_data(self):
304 """Method called from self.build_element_safe() to update the list data.""" 305 306 # Expand the number of rows to match the number of relaxation IDs, and add the IDs. 307 n = 0 308 if hasattr(cdp, 'ri_ids'): 309 # The number of IDs. 310 n = len(cdp.ri_ids) 311 312 # Add all the data. 313 for i in range(n): 314 # Set the IDs. 315 id = cdp.ri_ids[i] 316 self.element.InsertStringItem(i, str_to_gui(id)) 317 318 # Set the data types. 319 self.element.SetStringItem(i, 1, str_to_gui(cdp.ri_type[id])) 320 321 # Set the frequencies. 322 self.element.SetStringItem(i, 2, float_to_gui(cdp.frq[id]))
323 324
325 - def view_metadata(self, event=None):
326 """Launch the metadata window. 327 328 @keyword event: The wx event. 329 @type event: wx event 330 """ 331 332 # Launch. 333 Metadata_window(self.gui)
334 335
336 - def wizard_bruker(self, event):
337 """Launch the Bruker Dynamics Centre data reading wizard. 338 339 @param event: The wx event. 340 @type event: wx event 341 """ 342 343 # The wizard. 344 self.wizard_exec(bruker=True)
345 346
347 - def wizard_exec(self, bruker=False):
348 """Launch the Rx peak loading wizard. 349 350 @keyword bruker: A flag which if True will launch the Bruker Dynamics Centre data reading wizard and if False will launch the relaxation data reading wizard 351 @type bruker: bool 352 """ 353 354 # Change the cursor to busy. 355 wx.BeginBusyCursor() 356 357 # The title. 358 if bruker: 359 title = "The Bruker Dynamics Centre data reading wizard" 360 else: 361 title = "The relaxation data reading wizard" 362 363 # Initialise a wizard. 364 self.wizard = Wiz_window(parent=self.gui, size_x=1000, size_y=800, title=title) 365 self.page_indices = {} 366 367 # The reading page. 368 if bruker: 369 page = uf_store['bruker.read'].create_page(self.wizard, sync=True) 370 else: 371 page = uf_store['relax_data.read'].create_page(self.wizard, sync=True) 372 self.page_indices['read'] = self.wizard.add_page(page, skip_button=True, proceed_on_error=False) 373 374 # The peak intensity type page. 375 page = uf_store['relax_data.peak_intensity_type'].create_page(self.wizard, sync=True) 376 self.page_indices['peak_intensity_type'] = self.wizard.add_page(page, apply_button=True, skip_button=True) 377 page.on_display_post = self.wizard_update_int_type 378 379 # The temperature calibration page. 380 page = uf_store['relax_data.temp_calibration'].create_page(self.wizard, sync=True) 381 self.page_indices['temp_calibration'] = self.wizard.add_page(page, apply_button=True, skip_button=True) 382 page.on_display_post = self.wizard_update_temp_calibration 383 384 # The temperature control page. 385 page = uf_store['relax_data.temp_control'].create_page(self.wizard, sync=True) 386 self.page_indices['temp_control'] = self.wizard.add_page(page, apply_button=True) 387 page.on_display_post = self.wizard_update_temp_control 388 389 # Reset the cursor. 390 if wx.IsBusy(): 391 wx.EndBusyCursor() 392 393 # Run the wizard. 394 self.wizard.run()
395 396
397 - def wizard_relax_data(self, event):
398 """Launch the relaxation data reading wizard. 399 400 @param event: The wx event. 401 @type event: wx event 402 """ 403 404 # The wizard. 405 self.wizard_exec(bruker=False)
406 407
408 - def wizard_update_int_type(self):
409 """Update the relax_data.peak_intensity_type page based on previous data.""" 410 411 # The relax_data.peak_intensity_type page. 412 page = self.wizard.get_page(self.page_indices['read']) 413 414 # Get the Rx ID. 415 id = page.uf_args['ri_id'].GetValue() 416 417 # Set the ID in the relax_data.peak_intensity_type page. 418 page = self.wizard.get_page(self.page_indices['peak_intensity_type']) 419 page.uf_args['ri_id'].SetValue(value=id)
420 421
423 """Update the relax_data.temp_calibration page based on previous data.""" 424 425 # The relax_data.temp_calibration page. 426 page = self.wizard.get_page(self.page_indices['read']) 427 428 # Get the Rx ID. 429 id = page.uf_args['ri_id'].GetValue() 430 431 # Set the ID in the relax_data.temp_calibration page. 432 page = self.wizard.get_page(self.page_indices['temp_calibration']) 433 page.uf_args['ri_id'].SetValue(value=id)
434 435
437 """Update the relax_data.temp_control page based on previous data.""" 438 439 # The relax_data.temp_control page. 440 page = self.wizard.get_page(self.page_indices['read']) 441 442 # Get the Rx ID. 443 id = page.uf_args['ri_id'].GetValue() 444 445 # Set the ID in the relax_data.temp_control page. 446 page = self.wizard.get_page(self.page_indices['temp_control']) 447 page.uf_args['ri_id'].SetValue(value=id)
448 449 450
451 -class Metadata_window(wx.Frame):
452 """The relaxation data metadata window.""" 453
454 - def __init__(self, parent):
455 """Set up the export window. 456 457 @param parent: The parent object. 458 @type parent: wx.Frame instance 459 """ 460 461 # The window style. 462 style = wx.DEFAULT_FRAME_STYLE 463 464 # Initialise the base class, setting the main GUI window as the parent. 465 super(Metadata_window, self).__init__(parent, -1, style=style) 466 467 # Some default values. 468 self.size_x = 1200 469 self.size_y = 500 470 self.border = 5 471 self.spacer = 10 472 473 # Set up the frame. 474 sizer = self.setup_frame() 475 476 # Add the relaxation data metadata list GUI element, with spacing. 477 sizer.AddSpacer(15) 478 self.relax_data = Relax_data_meta_list(parent=self.main_panel, box=sizer, id='BMRB export', proportion=1) 479 480 # Open the window. 481 if status.show_gui: 482 self.Show()
483 484
485 - def handler_close(self, event):
486 """Event handler for the close window action. 487 488 @param event: The wx event. 489 @type event: wx event 490 """ 491 492 # Unregister the observers. 493 self.relax_data.observer_register(remove=True) 494 495 # Close the window. 496 event.Skip()
497 498
499 - def setup_frame(self):
500 """Set up the relax controller frame. 501 @return: The sizer object. 502 @rtype: wx.Sizer instance 503 """ 504 505 # Set the frame title. 506 self.SetTitle("Relaxation data metadata") 507 508 # Set up the window icon. 509 self.SetIcons(relax_icons) 510 511 # Place all elements within a panel (to remove the dark grey in MS Windows). 512 self.main_panel = wx.Panel(self, -1) 513 514 # Use a grid sizer for packing the main elements. 515 main_sizer = wx.BoxSizer(wx.VERTICAL) 516 self.main_panel.SetSizer(main_sizer) 517 518 # Build the central sizer, with borders. 519 sizer = add_border(main_sizer, border=self.border, packing=wx.VERTICAL) 520 521 # Close the window cleanly (unregistering observers). 522 self.Bind(wx.EVT_CLOSE, self.handler_close) 523 524 # Set the default size of the controller. 525 self.SetSize((self.size_x, self.size_y)) 526 527 # Centre the frame. 528 self.Centre() 529 530 # Return the central sizer. 531 return sizer
532