Author: bugman Date: Thu Jun 7 18:40:12 2012 New Revision: 16737 URL: http://svn.gna.org/viewcvs/relax?rev=16737&view=rev Log: Created a GUI element for listing and setting molecule attributes. This will be used in the BMRB export window. Added: branches/uf_redesign/gui/components/molecule.py - copied, changed from r16729, branches/uf_redesign/gui/components/relax_data_meta.py Modified: branches/uf_redesign/gui/components/__init__.py Modified: branches/uf_redesign/gui/components/__init__.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/components/__init__.py?rev=16737&r1=16736&r2=16737&view=diff ============================================================================== --- branches/uf_redesign/gui/components/__init__.py (original) +++ branches/uf_redesign/gui/components/__init__.py Thu Jun 7 18:40:12 2012 @@ -27,6 +27,7 @@ __all__ = ['conversion', 'grid', 'menu', + 'molecule', 'relax_data', 'relax_data_meta', 'spectrum'] Copied: branches/uf_redesign/gui/components/molecule.py (from r16729, branches/uf_redesign/gui/components/relax_data_meta.py) URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/components/molecule.py?p2=branches/uf_redesign/gui/components/molecule.py&p1=branches/uf_redesign/gui/components/relax_data_meta.py&r1=16729&r2=16737&rev=16737&view=diff ============================================================================== --- branches/uf_redesign/gui/components/relax_data_meta.py (original) +++ branches/uf_redesign/gui/components/molecule.py Thu Jun 7 18:40:12 2012 @@ -22,13 +22,15 @@ ############################################################################### # Module docstring. -"""Module containing the classes for GUI components involving relaxation data.""" +"""Module containing the classes for GUI components involving molecules.""" # Python module imports. import wx import wx.lib.buttons # relax module imports. +from generic_fns.mol_res_spin import count_molecules, molecule_loop, return_molecule + from graphics import fetch_icon from status import Status; status = Status() from user_functions.data import Uf_info; uf_info = Uf_info() @@ -37,22 +39,21 @@ from gui.components.menu import build_menu_item from gui.fonts import font from gui.misc import add_border -from gui.string_conv import float_to_gui, gui_to_str, str_to_gui +from gui.string_conv import gui_to_str, str_to_gui from gui.uf_objects import Uf_storage; uf_store = Uf_storage() -class Relax_data_meta_list: - """The GUI element for listing loaded relaxation data.""" +class Molecule: + """The GUI element for listing loaded molecules.""" # Some IDs for the menu entries. - MENU_RELAX_DATA_DISPLAY = wx.NewId() - MENU_RELAX_DATA_PEAK_INTENSITY_TYPE = wx.NewId() - MENU_RELAX_DATA_TEMP_CALIBRATION = wx.NewId() - MENU_RELAX_DATA_TEMP_CONTROL = wx.NewId() + MENU_BMRB_THIOL_STATE = wx.NewId() + MENU_MOLECULE_NAME = wx.NewId() + MENU_MOLECULE_TYPE = wx.NewId() def __init__(self, parent=None, box=None, id=None, stretch=False): - """Build the relaxation data list GUI element. + """Build the molecule list GUI element. @keyword parent: The parent GUI element that this is to be attached to (the panel object). @type parent: wx object @@ -107,22 +108,14 @@ self.build_element() # Initialise observer name. - self.name = 'relaxation metadata list: %s' % id + self.name = 'molecule: %s' % id # Register the element for updating when a user function completes. self.observer_register() - def Enable(self, enable=True): - """Enable or disable the element. - - @keyword enable: The flag specifying if the element should be enabled or disabled. - @type enable: bool - """ - - - def action_relax_data_display(self, event): - """Launch the relax_data.display user function. + def action_bmrb_thiol_state(self, event): + """Launch the bmrb.thiol_state user function. @param event: The wx event. @type event: wx event @@ -131,15 +124,37 @@ # The current selection. item = self.element.GetFirstSelected() + # The current state. + state = None + if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'thiol_state'): + state = cdp.exp_info.thiol_state + + # Launch the dialog. + if state == None: + uf_store['bmrb.thiol_state'](wx_parent=self.parent) + else: + uf_store['bmrb.thiol_state'](wx_parent=self.parent, state=state) + + + def action_molecule_name(self, event): + """Launch the molecule.name user function. + + @param event: The wx event. + @type event: wx event + """ + + # The current selection. + item = self.element.GetFirstSelected() + # The spectrum ID. id = gui_to_str(self.element.GetItemText(item)) # Launch the dialog. - uf_store['relax_data.display'](wx_parent=self.parent, ri_id=id) - - - def action_relax_data_peak_intensity_type(self, event): - """Launch the relax_data.peak_intensity_type user function. + uf_store['molecule.name'](wx_parent=self.parent, mol_id=id) + + + def action_molecule_type(self, event): + """Launch the molecule.type user function. @param event: The wx event. @type event: wx event @@ -153,68 +168,19 @@ # The current type. type = None - if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'peak_intensity_type') and id in cdp.exp_info.peak_intensity_type.keys(): - type = cdp.exp_info.peak_intensity_type[id] + mol = return_molecule(id) + if hasattr(mol, 'type') and mol.type != None: + type = mol.type # Launch the dialog. if type == None: - uf_store['relax_data.peak_intensity_type'](wx_parent=self.parent, ri_id=id) - else: - uf_store['relax_data.peak_intensity_type'](wx_parent=self.parent, ri_id=id, type=type) - - - def action_relax_data_temp_calibration(self, event): - """Launch the relax_data.temp_calibration user function. - - @param event: The wx event. - @type event: wx event - """ - - # The current selection. - item = self.element.GetFirstSelected() - - # The spectrum ID. - id = gui_to_str(self.element.GetItemText(item)) - - # The current method. - method = None - if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_calibration') and id in cdp.exp_info.temp_calibration.keys(): - method = cdp.exp_info.temp_calibration[id] - - # Launch the dialog. - if method == None: - uf_store['relax_data.temp_calibration'](wx_parent=self.parent, ri_id=id) - else: - uf_store['relax_data.temp_calibration'](wx_parent=self.parent, ri_id=id, method=method) - - - def action_relax_data_temp_control(self, event): - """Launch the relax_data.temp_control user function. - - @param event: The wx event. - @type event: wx event - """ - - # The current selection. - item = self.element.GetFirstSelected() - - # The spectrum ID. - id = gui_to_str(self.element.GetItemText(item)) - - # The current method. - method = None - if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_control') and id in cdp.exp_info.temp_control.keys(): - method = cdp.exp_info.temp_control[id] - - # Launch the dialog. - if method == None: - uf_store['relax_data.temp_control'](wx_parent=self.parent, ri_id=id) - else: - uf_store['relax_data.temp_control'](wx_parent=self.parent, ri_id=id, method=method) + uf_store['molecule.type'](wx_parent=self.parent, mol_id=id) + else: + uf_store['molecule.type'](wx_parent=self.parent, mol_id=id, type=type) def build_element(self): - """Build the relaxation data listing grid.""" + """Build the molecule listing grid.""" # Execution lock, so do nothing. if status.exec_lock.locked(): @@ -236,29 +202,27 @@ # Delete the previous data. self.element.DeleteAllItems() - # Expand the number of rows to match the number of relaxation IDs, and add the IDs. - n = 0 - if hasattr(cdp, 'ri_ids'): - # The number of IDs. - n = len(cdp.ri_ids) - - # Add all the data. - for i in range(n): - # Set the IDs. - id = cdp.ri_ids[i] - self.element.InsertStringItem(i, str_to_gui(id)) - - # Set the peak intensity types. - if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'peak_intensity_type') and id in cdp.exp_info.peak_intensity_type.keys(): - self.element.SetStringItem(i, 1, str_to_gui(cdp.exp_info.peak_intensity_type[id])) - - # Set the temperature calibration methods. - if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_calibration') and id in cdp.exp_info.temp_calibration.keys(): - self.element.SetStringItem(i, 2, str_to_gui(cdp.exp_info.temp_calibration[id])) - - # Set the temperature control methods. - if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'temp_control') and id in cdp.exp_info.temp_control.keys(): - self.element.SetStringItem(i, 3, str_to_gui(cdp.exp_info.temp_control[id])) + # Expand the number of rows to match the number of molecules, and add the data. + n = count_molecules() + i = 0 + for mol, mol_id in molecule_loop(return_id=True): + # Set the index. + self.element.InsertStringItem(i, str_to_gui(mol_id)) + + # Set the molecule name. + if mol.name != None: + self.element.SetStringItem(i, 1, str_to_gui(mol.name)) + + # Set the molecule type. + if hasattr(mol, 'type'): + self.element.SetStringItem(i, 2, str_to_gui(mol.type)) + + # Set the thiol state. + if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'thiol_state'): + self.element.SetStringItem(i, 3, str_to_gui(cdp.exp_info.thiol_state)) + + # Increment the counter. + i += 1 # Size the columns. self.size_cols() @@ -270,7 +234,7 @@ # Set the minimum height. if not self.stretch: head = self.height_char + 10 - centre = (self.height_char + 6) * n + centre = (self.height_char + 6) * n foot = wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y) height = head + centre + foot self.element.SetMinSize((-1, height)) @@ -280,28 +244,21 @@ self.element.Thaw() - def delete(self): - """Unregister the class.""" - - # Unregister the observer methods. - self.observer_register(remove=True) - - def init_element(self, sizer): - """Initialise the GUI element for the relaxation data listing. + """Initialise the GUI element for the molecule listing. @param sizer: The sizer element to pack the element into. @type sizer: wx.BoxSizer instance """ - # List of relaxation data. + # List of molecules. self.element = wx.ListCtrl(self.panel, -1, style=wx.BORDER_SUNKEN|wx.LC_REPORT) # Initialise to 4 columns. - self.element.InsertColumn(0, str_to_gui("Relaxation data ID")) - self.element.InsertColumn(1, str_to_gui("Peak intensity type")) - self.element.InsertColumn(2, str_to_gui("Temperature calibration")) - self.element.InsertColumn(3, str_to_gui("Temperature control")) + self.element.InsertColumn(0, str_to_gui("ID string")) + self.element.InsertColumn(1, str_to_gui("Name")) + self.element.InsertColumn(2, str_to_gui("Type")) + self.element.InsertColumn(3, str_to_gui("Thiol state")) # Properties. self.element.SetFont(font.normal) @@ -325,32 +282,21 @@ @rtype: bool """ - # No relaxation data. - if not hasattr(cdp, 'ri_ids'): - return True - - # The number of IDs. - n = len(cdp.ri_ids) - - # Add all the data. - for i in range(n): - # The ID. - id = cdp.ri_ids[i] - - # Check the peak intensity types. - if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'peak_intensity_type') or not id in cdp.exp_info.peak_intensity_type.keys(): + # Loop over the molecules. + for mol in molecule_loop(): + # No name. + if mol.name == None: return False - - # Check the temperature calibration methods. - if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_calibration') or not id in cdp.exp_info.temp_calibration.keys(): + # No molecule type. + if not hasattr(mol, 'type') or mol.type == None: return False - # Check the temperature control methods. - if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_control') or not id in cdp.exp_info.temp_control.keys(): + # No thiol state. + if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'thiol_state'): return False - # Data input is complete! + # Data input is complete. return True @@ -385,16 +331,14 @@ menu = wx.Menu() # Add some menu items for the spin user functions. - menu.AppendItem(build_menu_item(menu, id=self.MENU_RELAX_DATA_DISPLAY, text="Dis&play the relaxation data", icon=fetch_icon(uf_info.get_uf('relax_data.display').gui_icon))) - menu.AppendItem(build_menu_item(menu, id=self.MENU_RELAX_DATA_PEAK_INTENSITY_TYPE, text="Set the peak &intensity type", icon=fetch_icon(uf_info.get_uf('relax_data.peak_intensity_type').gui_icon))) - menu.AppendItem(build_menu_item(menu, id=self.MENU_RELAX_DATA_TEMP_CALIBRATION, text="Set the temperature &calibration", icon=fetch_icon(uf_info.get_uf('relax_data.temp_calibration').gui_icon))) - menu.AppendItem(build_menu_item(menu, id=self.MENU_RELAX_DATA_TEMP_CONTROL, text="Set the temperature c&ontrol", icon=fetch_icon(uf_info.get_uf('relax_data.temp_control').gui_icon))) + menu.AppendItem(build_menu_item(menu, id=self.MENU_MOLECULE_NAME, text="&Name the molecule", icon=fetch_icon(uf_info.get_uf('molecule.name').gui_icon))) + menu.AppendItem(build_menu_item(menu, id=self.MENU_MOLECULE_TYPE, text="Set the molecule &type", icon=fetch_icon(uf_info.get_uf('molecule.type').gui_icon))) + menu.AppendItem(build_menu_item(menu, id=self.MENU_BMRB_THIOL_STATE, text="Set the thiol &state", icon=fetch_icon(uf_info.get_uf('bmrb.thiol_state').gui_icon))) # Bind clicks. - self.element.Bind(wx.EVT_MENU, self.action_relax_data_display, id=self.MENU_RELAX_DATA_DISPLAY) - self.element.Bind(wx.EVT_MENU, self.action_relax_data_peak_intensity_type, id=self.MENU_RELAX_DATA_PEAK_INTENSITY_TYPE) - self.element.Bind(wx.EVT_MENU, self.action_relax_data_temp_calibration, id=self.MENU_RELAX_DATA_TEMP_CALIBRATION) - self.element.Bind(wx.EVT_MENU, self.action_relax_data_temp_control, id=self.MENU_RELAX_DATA_TEMP_CONTROL) + self.element.Bind(wx.EVT_MENU, self.action_molecule_name, id=self.MENU_MOLECULE_NAME) + self.element.Bind(wx.EVT_MENU, self.action_molecule_type, id=self.MENU_MOLECULE_TYPE) + self.element.Bind(wx.EVT_MENU, self.action_bmrb_thiol_state, id=self.MENU_BMRB_THIOL_STATE) # Pop up the menu. if status.show_gui: @@ -420,7 +364,7 @@ """Set the label of the StaticBox.""" # Determine if the data input is complete. - label = "Relaxation data metadata " + label = "Molecule information " if self.is_complete(): label += "(complete)" else: