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