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