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

Source Code for Module gui.components.molecule

  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 molecules.""" 
 25   
 26  # Python module imports. 
 27  import wx 
 28  import wx.lib.buttons 
 29   
 30  # relax module imports. 
 31  import dep_check 
 32  from graphics import fetch_icon 
 33  from gui.components.base_list import Base_list 
 34  from gui.string_conv import gui_to_str, str_to_gui 
 35  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 36  from pipe_control.mol_res_spin import molecule_loop, return_molecule 
 37  from status import Status; status = Status() 
 38  from user_functions.data import Uf_info; uf_info = Uf_info() 
 39   
 40   
 41  # Some IDs for the menu entries. 
 42  MENU_MOLECULE_NAME = wx.NewId() 
 43  MENU_MOLECULE_TYPE = wx.NewId() 
 44  MENU_BMRB_THIOL_STATE = wx.NewId() 
 45   
 46   
 47   
48 -class Molecule(Base_list):
49 """The GUI element for listing loaded molecules.""" 50
51 - def action_bmrb_thiol_state(self, event):
52 """Launch the bmrb.thiol_state user function. 53 54 @param event: The wx event. 55 @type event: wx event 56 """ 57 58 # The current selection. 59 item = self.element.GetFirstSelected() 60 61 # The current state. 62 state = None 63 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'thiol_state'): 64 state = cdp.exp_info.thiol_state 65 66 # Launch the dialog. 67 if state == None: 68 uf_store['bmrb.thiol_state'](wx_parent=self.parent) 69 else: 70 uf_store['bmrb.thiol_state'](wx_parent=self.parent, state=state)
71 72
73 - def action_molecule_name(self, event):
74 """Launch the molecule.name 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['molecule.name'](wx_parent=self.parent, mol_id=id)
88 89
90 - def action_molecule_type(self, event):
91 """Launch the molecule.type 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 type. 104 type = None 105 mol = return_molecule(id) 106 if hasattr(mol, 'type') and mol.type != None: 107 type = mol.type 108 109 # Launch the dialog. 110 if type == None: 111 uf_store['molecule.type'](wx_parent=self.parent, mol_id=id) 112 else: 113 uf_store['molecule.type'](wx_parent=self.parent, mol_id=id, type=type)
114 115
116 - def is_complete(self):
117 """Determine if the data input is complete. 118 119 @return: The answer to the question. 120 @rtype: bool 121 """ 122 123 # Loop over the molecules. 124 for mol in molecule_loop(): 125 # No name. 126 if mol.name == None: 127 return False 128 129 # No molecule type. 130 if not hasattr(mol, 'type') or mol.type == None: 131 return False 132 133 # No thiol state. 134 if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'thiol_state'): 135 return False 136 137 # Data input is complete. 138 return True
139 140
141 - def set_box_label(self):
142 """Set the label of the StaticBox.""" 143 144 # Determine if the data input is complete. 145 label = self.title 146 if self.is_complete(): 147 label += " (complete)" 148 else: 149 label += " (incomplete)" 150 151 # Set the label. 152 self.data_box.SetLabel(label)
153 154
155 - def setup(self):
156 """Override the base variables.""" 157 158 # GUI variables. 159 self.title = "Molecule information" 160 self.observer_base_name = "molecule" 161 self.button_placement = None 162 163 # The column titles. 164 self.columns = [ 165 "ID string", 166 "Name", 167 "Type", 168 "Thiol state" 169 ] 170 171 # The right click popup menu. 172 self.popup_menus = [ 173 { 174 'id': MENU_MOLECULE_NAME, 175 'text': "&Name the molecule", 176 'icon': fetch_icon(uf_info.get_uf('molecule.name').gui_icon), 177 'method': self.action_molecule_name 178 }, { 179 'id': MENU_MOLECULE_TYPE, 180 'text': "Set the molecule &type", 181 'icon': fetch_icon(uf_info.get_uf('molecule.type').gui_icon), 182 'method': self.action_molecule_type 183 }, { 184 'id': MENU_BMRB_THIOL_STATE, 185 'text': "Set the thiol &state", 186 'icon': fetch_icon(uf_info.get_uf('bmrb.thiol_state').gui_icon), 187 'method': self.action_bmrb_thiol_state 188 } 189 ]
190 191
192 - def update_data(self):
193 """Method called from self.build_element_safe() to update the list data.""" 194 195 # Expand the number of rows to match the number of molecules, and add the data. 196 i = 0 197 for mol, mol_id in molecule_loop(return_id=True): 198 # Set the index. 199 if dep_check.wx_classic: 200 self.element.InsertStringItem(i, str_to_gui(mol_id)) 201 else: 202 self.element.InsertItem(i, str_to_gui(mol_id)) 203 204 # Set the molecule name. 205 if mol.name != None: 206 if dep_check.wx_classic: 207 self.element.SetStringItem(i, 1, str_to_gui(mol.name)) 208 else: 209 self.element.SetItem(i, 1, str_to_gui(mol.name)) 210 211 # Set the molecule type. 212 if hasattr(mol, 'type'): 213 if dep_check.wx_classic: 214 self.element.SetStringItem(i, 2, str_to_gui(mol.type)) 215 else: 216 self.element.SetItem(i, 2, str_to_gui(mol.type)) 217 218 # Set the thiol state. 219 if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'thiol_state'): 220 if dep_check.wx_classic: 221 self.element.SetStringItem(i, 3, str_to_gui(cdp.exp_info.thiol_state)) 222 else: 223 self.element.SetItem(i, 3, str_to_gui(cdp.exp_info.thiol_state)) 224 225 # Increment the counter. 226 i += 1
227