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

Source Code for Module gui.components.molecule

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