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