1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24  """Module containing the classes for GUI components involving molecules.""" 
 25   
 26   
 27  import wx 
 28  import wx.lib.buttons 
 29   
 30   
 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   
 41  MENU_MOLECULE_NAME = wx.NewId() 
 42  MENU_MOLECULE_TYPE = wx.NewId() 
 43  MENU_BMRB_THIOL_STATE = wx.NewId() 
 44   
 45   
 46   
 48      """The GUI element for listing loaded molecules.""" 
 49   
 51          """Launch the bmrb.thiol_state user function. 
 52   
 53          @param event:   The wx event. 
 54          @type event:    wx event 
 55          """ 
 56   
 57           
 58          item = self.element.GetFirstSelected() 
 59   
 60           
 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           
 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   
 73          """Launch the molecule.name user function. 
 74   
 75          @param event:   The wx event. 
 76          @type event:    wx event 
 77          """ 
 78   
 79           
 80          item = self.element.GetFirstSelected() 
 81   
 82           
 83          id = gui_to_str(self.element.GetItemText(item)) 
 84   
 85           
 86          uf_store['molecule.name'](wx_parent=self.parent, mol_id=id) 
  87   
 88   
 90          """Launch the molecule.type user function. 
 91   
 92          @param event:   The wx event. 
 93          @type event:    wx event 
 94          """ 
 95   
 96           
 97          item = self.element.GetFirstSelected() 
 98   
 99           
100          id = gui_to_str(self.element.GetItemText(item)) 
101   
102           
103          type = None 
104          mol = return_molecule(id) 
105          if hasattr(mol, 'type') and mol.type != None: 
106              type = mol.type 
107   
108           
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   
116          """Determine if the data input is complete. 
117   
118          @return:    The answer to the question. 
119          @rtype:     bool 
120          """ 
121   
122           
123          for mol in molecule_loop(): 
124               
125              if mol.name == None: 
126                  return False 
127   
128               
129              if not hasattr(mol, 'type') or mol.type == None: 
130                  return False 
131   
132               
133              if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'thiol_state'): 
134                  return False 
135   
136           
137          return True 
 138   
139   
141          """Set the label of the StaticBox.""" 
142   
143           
144          label = self.title 
145          if self.is_complete(): 
146              label += " (complete)" 
147          else: 
148              label += " (incomplete)" 
149   
150           
151          self.data_box.SetLabel(label) 
 152   
153   
155          """Override the base variables.""" 
156   
157           
158          self.title = "Molecule information" 
159          self.observer_base_name = "molecule" 
160          self.button_placement = None 
161   
162           
163          self.columns = [ 
164              "ID string", 
165              "Name", 
166              "Type", 
167              "Thiol state" 
168          ] 
169   
170           
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   
192          """Method called from self.build_element_safe() to update the list data.""" 
193   
194           
195          i = 0 
196          for mol, mol_id in molecule_loop(return_id=True): 
197               
198              self.element.InsertStringItem(i, str_to_gui(mol_id)) 
199   
200               
201              if mol.name != None: 
202                  self.element.SetStringItem(i, 1, str_to_gui(mol.name)) 
203   
204               
205              if hasattr(mol, 'type'): 
206                  self.element.SetStringItem(i, 2, str_to_gui(mol.type)) 
207   
208               
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               
213              i += 1 
  214