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