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