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

Source Code for Module gui.components.relax_data_meta

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2010 Michael Bieri                                       # 
  4  # Copyright (C) 2009-2012,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   
 29  # relax module imports. 
 30  from graphics import fetch_icon 
 31  from gui.components.base_list import Base_list 
 32  from gui.string_conv import gui_to_str, str_to_gui 
 33  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 34  from status import Status; status = Status() 
 35  from user_functions.data import Uf_info; uf_info = Uf_info() 
 36   
 37   
 38  # Some IDs for the menu entries. 
 39  MENU_RELAX_DATA_DISPLAY = wx.NewId() 
 40  MENU_RELAX_DATA_PEAK_INTENSITY_TYPE = wx.NewId() 
 41  MENU_RELAX_DATA_TEMP_CALIBRATION = wx.NewId() 
 42  MENU_RELAX_DATA_TEMP_CONTROL = wx.NewId() 
 43   
 44   
 45   
46 -class Relax_data_meta_list(Base_list):
47 """The GUI element for listing loaded relaxation data.""" 48
49 - def action_relax_data_display(self, event):
50 """Launch the relax_data.display user function. 51 52 @param event: The wx event. 53 @type event: wx event 54 """ 55 56 # The current selection. 57 item = self.element.GetFirstSelected() 58 59 # The spectrum ID. 60 id = gui_to_str(self.element.GetItemText(item)) 61 62 # Launch the dialog. 63 uf_store['relax_data.display'](wx_parent=self.parent, ri_id=id)
64 65
67 """Launch the relax_data.peak_intensity_type user function. 68 69 @param event: The wx event. 70 @type event: wx event 71 """ 72 73 # The current selection. 74 item = self.element.GetFirstSelected() 75 76 # The spectrum ID. 77 id = gui_to_str(self.element.GetItemText(item)) 78 79 # The current type. 80 type = None 81 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'peak_intensity_type') and id in cdp.exp_info.peak_intensity_type: 82 type = cdp.exp_info.peak_intensity_type[id] 83 84 # Launch the dialog. 85 if type == None: 86 uf_store['relax_data.peak_intensity_type'](wx_parent=self.parent, ri_id=id) 87 else: 88 uf_store['relax_data.peak_intensity_type'](wx_parent=self.parent, ri_id=id, type=type)
89 90
91 - def action_relax_data_temp_calibration(self, event):
92 """Launch the relax_data.temp_calibration 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 method. 105 method = None 106 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_calibration') and id in cdp.exp_info.temp_calibrations(): 107 method = cdp.exp_info.temp_calibration[id] 108 109 # Launch the dialog. 110 if method == None: 111 uf_store['relax_data.temp_calibration'](wx_parent=self.parent, ri_id=id) 112 else: 113 uf_store['relax_data.temp_calibration'](wx_parent=self.parent, ri_id=id, method=method)
114 115
116 - def action_relax_data_temp_control(self, event):
117 """Launch the relax_data.temp_control 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 method. 130 method = None 131 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_control') and id in cdp.exp_info.temp_control: 132 method = cdp.exp_info.temp_control[id] 133 134 # Launch the dialog. 135 if method == None: 136 uf_store['relax_data.temp_control'](wx_parent=self.parent, ri_id=id) 137 else: 138 uf_store['relax_data.temp_control'](wx_parent=self.parent, ri_id=id, method=method)
139 140
141 - def is_complete(self):
142 """Determine if the data input is complete. 143 144 @return: The answer to the question. 145 @rtype: bool 146 """ 147 148 # No relaxation data. 149 if not hasattr(cdp, 'ri_ids'): 150 return True 151 152 # The number of IDs. 153 n = len(cdp.ri_ids) 154 155 # Add all the data. 156 for i in range(n): 157 # The ID. 158 id = cdp.ri_ids[i] 159 160 # Check the peak intensity types. 161 if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'peak_intensity_type') or not id in cdp.exp_info.peak_intensity_type: 162 return False 163 164 # Check the temperature calibration methods. 165 if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_calibration') or not id in cdp.exp_info.temp_calibration: 166 return False 167 168 # Check the temperature control methods. 169 if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_control') or not id in cdp.exp_info.temp_control: 170 return False 171 172 # Data input is complete! 173 return True
174 175
176 - def set_box_label(self):
177 """Set the label of the StaticBox.""" 178 179 # Determine if the data input is complete. 180 label = self.title 181 if self.is_complete(): 182 label += " (complete)" 183 else: 184 label += " (incomplete)" 185 186 # Set the label. 187 self.data_box.SetLabel(label)
188 189
190 - def setup(self):
191 """Override the base variables.""" 192 193 # GUI variables. 194 self.title = "Relaxation data metadata" 195 self.observer_base_name = "relaxation metadata list" 196 self.button_placement = None 197 198 # The column titles. 199 self.columns = [ 200 "Relaxation data ID", 201 "Peak intensity type", 202 "Temperature calibration", 203 "Temperature control" 204 ] 205 206 # The right click popup menu. 207 self.popup_menus = [ 208 { 209 'id': MENU_RELAX_DATA_DISPLAY, 210 'text': "Dis&play the relaxation data", 211 'icon': fetch_icon(uf_info.get_uf('relax_data.display').gui_icon), 212 'method': self.action_relax_data_display 213 }, { 214 'id': MENU_RELAX_DATA_PEAK_INTENSITY_TYPE, 215 'text': "Set the peak &intensity type", 216 'icon': fetch_icon(uf_info.get_uf('relax_data.peak_intensity_type').gui_icon), 217 'method': self.action_relax_data_peak_intensity_type 218 }, { 219 'id': MENU_RELAX_DATA_TEMP_CALIBRATION, 220 'text': "Set the temperature &calibration", 221 'icon': fetch_icon(uf_info.get_uf('relax_data.temp_calibration').gui_icon), 222 'method': self.action_relax_data_temp_calibration 223 }, { 224 'id': MENU_RELAX_DATA_TEMP_CONTROL, 225 'text': "Set the temperature c&ontrol", 226 'icon': fetch_icon(uf_info.get_uf('relax_data.temp_control').gui_icon), 227 'method': self.action_relax_data_temp_control 228 } 229 ]
230 231
232 - def update_data(self):
233 """Method called from self.build_element_safe() to update the list data.""" 234 235 # Expand the number of rows to match the number of relaxation IDs, and add the IDs. 236 n = 0 237 if hasattr(cdp, 'ri_ids'): 238 # The number of IDs. 239 n = len(cdp.ri_ids) 240 241 # Add all the data. 242 for i in range(n): 243 # Set the IDs. 244 id = cdp.ri_ids[i] 245 self.element.InsertStringItem(i, str_to_gui(id)) 246 247 # Set the peak intensity types. 248 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'peak_intensity_type') and id in cdp.exp_info.peak_intensity_type: 249 self.element.SetStringItem(i, 1, str_to_gui(cdp.exp_info.peak_intensity_type[id])) 250 251 # Set the temperature calibration methods. 252 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_calibration') and id in cdp.exp_info.temp_calibration: 253 self.element.SetStringItem(i, 2, str_to_gui(cdp.exp_info.temp_calibration[id])) 254 255 # Set the temperature control methods. 256 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_control') and id in cdp.exp_info.temp_control: 257 self.element.SetStringItem(i, 3, str_to_gui(cdp.exp_info.temp_control[id]))
258