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