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