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 - def update_data(self):
302 """Method called from self.build_element_safe() to update the list data.""" 303 304 # Expand the number of rows to match the number of relaxation IDs, and add the IDs. 305 n = 0 306 if hasattr(cdp, 'ri_ids'): 307 # The number of IDs. 308 n = len(cdp.ri_ids) 309 310 # Add all the data. 311 for i in range(n): 312 # Set the IDs. 313 id = cdp.ri_ids[i] 314 self.element.InsertStringItem(i, str_to_gui(id)) 315 316 # Set the data types. 317 self.element.SetStringItem(i, 1, str_to_gui(cdp.ri_type[id])) 318 319 # Set the frequencies. 320 self.element.SetStringItem(i, 2, float_to_gui(cdp.frq[id]))
321 322
323 - def view_metadata(self, event=None):
324 """Launch the metadata window. 325 326 @keyword event: The wx event. 327 @type event: wx event 328 """ 329 330 # Launch. 331 Metadata_window(self.gui)
332 333
334 - def wizard_bruker(self, event):
335 """Launch the Bruker Dynamics Centre data reading wizard. 336 337 @param event: The wx event. 338 @type event: wx event 339 """ 340 341 # The wizard. 342 self.wizard_exec(bruker=True)
343 344
345 - def wizard_exec(self, bruker=False):
346 """Launch the Rx peak loading wizard. 347 348 @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 349 @type bruker: bool 350 """ 351 352 # Change the cursor to busy. 353 wx.BeginBusyCursor() 354 355 # The title. 356 if bruker: 357 title = "The Bruker Dynamics Centre data reading wizard" 358 else: 359 title = "The relaxation data reading wizard" 360 361 # Initialise a wizard. 362 self.wizard = Wiz_window(parent=self.gui, size_x=1000, size_y=800, title=title) 363 self.page_indices = {} 364 365 # The reading page. 366 if bruker: 367 page = uf_store['bruker.read'].create_page(self.wizard, sync=True) 368 else: 369 page = uf_store['relax_data.read'].create_page(self.wizard, sync=True) 370 self.page_indices['read'] = self.wizard.add_page(page, skip_button=True, proceed_on_error=False) 371 372 # The peak intensity type page. 373 page = uf_store['relax_data.peak_intensity_type'].create_page(self.wizard, sync=True) 374 self.page_indices['peak_intensity_type'] = self.wizard.add_page(page, apply_button=True, skip_button=True) 375 page.on_display_post = self.wizard_update_int_type 376 377 # The temperature calibration page. 378 page = uf_store['relax_data.temp_calibration'].create_page(self.wizard, sync=True) 379 self.page_indices['temp_calibration'] = self.wizard.add_page(page, apply_button=True, skip_button=True) 380 page.on_display_post = self.wizard_update_temp_calibration 381 382 # The temperature control page. 383 page = uf_store['relax_data.temp_control'].create_page(self.wizard, sync=True) 384 self.page_indices['temp_control'] = self.wizard.add_page(page, apply_button=True) 385 page.on_display_post = self.wizard_update_temp_control 386 387 # Reset the cursor. 388 if wx.IsBusy(): 389 wx.EndBusyCursor() 390 391 # Run the wizard. 392 self.wizard.run()
393 394
395 - def wizard_relax_data(self, event):
396 """Launch the relaxation data reading wizard. 397 398 @param event: The wx event. 399 @type event: wx event 400 """ 401 402 # The wizard. 403 self.wizard_exec(bruker=False)
404 405
406 - def wizard_update_int_type(self):
407 """Update the relax_data.peak_intensity_type page based on previous data.""" 408 409 # The relax_data.peak_intensity_type page. 410 page = self.wizard.get_page(self.page_indices['read']) 411 412 # Get the Rx ID. 413 id = page.uf_args['ri_id'].GetValue() 414 415 # Set the ID in the relax_data.peak_intensity_type page. 416 page = self.wizard.get_page(self.page_indices['peak_intensity_type']) 417 page.uf_args['ri_id'].SetValue(value=id)
418 419
421 """Update the relax_data.temp_calibration page based on previous data.""" 422 423 # The relax_data.temp_calibration page. 424 page = self.wizard.get_page(self.page_indices['read']) 425 426 # Get the Rx ID. 427 id = page.uf_args['ri_id'].GetValue() 428 429 # Set the ID in the relax_data.temp_calibration page. 430 page = self.wizard.get_page(self.page_indices['temp_calibration']) 431 page.uf_args['ri_id'].SetValue(value=id)
432 433
435 """Update the relax_data.temp_control page based on previous data.""" 436 437 # The relax_data.temp_control page. 438 page = self.wizard.get_page(self.page_indices['read']) 439 440 # Get the Rx ID. 441 id = page.uf_args['ri_id'].GetValue() 442 443 # Set the ID in the relax_data.temp_control page. 444 page = self.wizard.get_page(self.page_indices['temp_control']) 445 page.uf_args['ri_id'].SetValue(value=id)
446 447 448
449 -class Metadata_window(wx.Frame):
450 """The relaxation data metadata window.""" 451
452 - def __init__(self, parent):
453 """Set up the export window. 454 455 @param parent: The parent object. 456 @type parent: wx.Frame instance 457 """ 458 459 # The window style. 460 style = wx.DEFAULT_FRAME_STYLE 461 462 # Initialise the base class, setting the main GUI window as the parent. 463 super(Metadata_window, self).__init__(parent, -1, style=style) 464 465 # Some default values. 466 self.size_x = 1200 467 self.size_y = 500 468 self.border = 5 469 self.spacer = 10 470 471 # Set up the frame. 472 sizer = self.setup_frame() 473 474 # Add the relaxation data metadata list GUI element, with spacing. 475 sizer.AddSpacer(15) 476 self.relax_data = Relax_data_meta_list(parent=self.main_panel, box=sizer, id='BMRB export', proportion=1) 477 478 # Open the window. 479 if status.show_gui: 480 self.Show()
481 482
483 - def handler_close(self, event):
484 """Event handler for the close window action. 485 486 @param event: The wx event. 487 @type event: wx event 488 """ 489 490 # Unregister the observers. 491 self.relax_data.observer_register(remove=True) 492 493 # Close the window. 494 event.Skip()
495 496
497 - def setup_frame(self):
498 """Set up the relax controller frame. 499 @return: The sizer object. 500 @rtype: wx.Sizer instance 501 """ 502 503 # Set the frame title. 504 self.SetTitle("Relaxation data metadata") 505 506 # Set up the window icon. 507 self.SetIcons(relax_icons) 508 509 # Place all elements within a panel (to remove the dark grey in MS Windows). 510 self.main_panel = wx.Panel(self, -1) 511 512 # Use a grid sizer for packing the main elements. 513 main_sizer = wx.BoxSizer(wx.VERTICAL) 514 self.main_panel.SetSizer(main_sizer) 515 516 # Build the central sizer, with borders. 517 sizer = add_border(main_sizer, border=self.border, packing=wx.VERTICAL) 518 519 # Close the window cleanly (unregistering observers). 520 self.Bind(wx.EVT_CLOSE, self.handler_close) 521 522 # Set the default size of the controller. 523 self.SetSize((self.size_x, self.size_y)) 524 525 # Centre the frame. 526 self.Centre() 527 528 # Return the central sizer. 529 return sizer
530