Author: bugman Date: Wed Jul 20 14:20:05 2011 New Revision: 13773 URL: http://svn.gna.org/viewcvs/relax?rev=13773&view=rev Log: Created the relaxation data list GUI element for use in the model-free auto-analysis GUI page. Added: branches/gui_testing/gui/components/relax_data.py - copied, changed from r13770, branches/gui_testing/gui/components/spectrum.py Copied: branches/gui_testing/gui/components/relax_data.py (from r13770, branches/gui_testing/gui/components/spectrum.py) URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/components/relax_data.py?p2=branches/gui_testing/gui/components/relax_data.py&p1=branches/gui_testing/gui/components/spectrum.py&r1=13770&r2=13773&rev=13773&view=diff ============================================================================== --- branches/gui_testing/gui/components/spectrum.py (original) +++ branches/gui_testing/gui/components/relax_data.py Wed Jul 20 14:20:05 2011 @@ -22,7 +22,7 @@ ############################################################################### # Module docstring. -"""Module containing the classes for GUI components involving spectral data.""" +"""Module containing the classes for GUI components involving relaxation data.""" # Python module imports. import wx @@ -30,21 +30,20 @@ # relax module imports. from status import Status; status = Status() -from generic_fns.spectrum import replicated_flags, replicated_ids # relax GUI module imports. -from gui.misc import add_border, float_to_gui, str_to_gui +from gui.misc import add_border from gui import paths -class Spectra_list: - """The GUI element for listing loaded spectral data.""" +class Relax_data_list: + """The GUI element for listing loaded relaxation data.""" # Class variables. col_label_width = 40 - def __init__(self, gui=None, parent=None, box=None, id=None, fn_add=None, buttons=True): - """Build the spectral list GUI element. + def __init__(self, gui=None, parent=None, box=None, id=None, buttons=True): + """Build the relaxation data list GUI element. @keyword gui: The main GUI object. @type gui: wx.Frame instance @@ -56,8 +55,6 @@ @type box: wx.BoxSizer instance @keyword id: A unique identification string. This is used to register the update method with the GUI user function observer object. @type id: str - @keyword fn_add: The function to execute when clicking on the 'Add' button. - @type fn_add: func @keyword buttons: A flag which if True will display the buttons at the top. @type buttons: bool """ @@ -65,14 +62,13 @@ # Store the arguments. self.gui = gui self.parent = parent - self.fn_add = fn_add # GUI variables. self.spacing = 5 self.border = 5 # A static box to hold all the widgets, and its sizer. - stat_box = wx.StaticBox(self.parent, -1, "Spectra list") + stat_box = wx.StaticBox(self.parent, -1, "Relaxation data list") stat_box.SetFont(self.gui.font_subtitle) sub_sizer = wx.StaticBoxSizer(stat_box, wx.VERTICAL) @@ -95,7 +91,7 @@ self.build_grid() # Initialise observer name. - self.name = 'spectra list: %s' % id + self.name = 'relaxation data list: %s' % id # Register the grid for updating when a user function completes. status.observers.uf_gui.register(self.name, self.build_grid) @@ -121,49 +117,46 @@ button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.add, wx.BITMAP_TYPE_ANY)) button.SetSize((80, 40)) button_sizer.Add(button, 0, 0, 0) - self.gui.Bind(wx.EVT_BUTTON, self.fn_add, button) - button.SetToolTipString("Read a spectral data file.") + self.gui.Bind(wx.EVT_BUTTON, self.gui.user_functions.relax_data.read, button) + button.SetToolTipString("Read relaxation data from file.") + + # Delete button. + button = wx.lib.buttons.ThemedGenBitmapTextButton(panel, -1, None, " Delete") + button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.list_remove, wx.BITMAP_TYPE_ANY)) + button.SetSize((80, 40)) + button_sizer.Add(button, 0, 0, 0) + self.gui.Bind(wx.EVT_BUTTON, self.gui.user_functions.relax_data.delete, button) + button.SetToolTipString("Delete loaded relaxation data from the relax data store.") def build_grid(self): - """Build the spectra listing grid.""" + """Build the relaxation data listing grid.""" # First freeze the grid, so that the GUI element doesn't update until the end. self.grid.Freeze() - # Initialise the column index for the data. - index = 1 - # Delete the rows and columns (leaving one row and column). self.grid.DeleteRows(numRows=self.grid.GetNumberRows()-1) - self.grid.DeleteCols(numCols=self.grid.GetNumberCols()-1) - - # Expand the number of rows to match the number of spectrum IDs, and add the IDs. - if hasattr(cdp, 'spectrum_ids'): + + # Expand the number of rows to match the number of relaxation IDs, and add the IDs. + if hasattr(cdp, 'ri_ids'): # The number of IDs. - n = len(cdp.spectrum_ids) + n = len(cdp.ri_ids) # Append the appropriate number of rows. self.grid.AppendRows(numRows=n-1) - # Set the IDs. + # Add all the data. for i in range(n): - self.grid.SetCellValue(i, 0, cdp.spectrum_ids[i]) - - # Set the headers. - self.grid.SetColLabelValue(0, "Spectrum ID string") - - # The NOE spectrum type. - if self.noe_spectrum_type(index): - index += 1 - - # The relaxation times. - if self.relax_times(index): - index += 1 - - # The replicated spectra. - if self.replicates(index): - index += 1 + # Set the IDs. + id = cdp.ri_ids[i] + self.grid.SetCellValue(i, 0, id) + + # Set the data types. + self.grid.SetCellValue(i, 1, cdp.ri_type[id]) + + # Set the frequencies. + self.grid.SetCellValue(i, 1, cdp.frq[id]) # Set the grid properties once finalised. for i in range(self.grid.GetNumberRows()): @@ -190,7 +183,7 @@ def init_grid(self, sizer): - """Initialise the grid for the spectra listing. + """Initialise the grid for the relaxation data listing. @param box: The sizer element to pack the grid into. @type box: wx.BoxSizer instance @@ -199,8 +192,13 @@ # Grid of peak list file names and relaxation time. self.grid = wx.grid.Grid(self.parent, -1) - # Initialise to a single row and column. - self.grid.CreateGrid(1, 1) + # Initialise to a single row and 3 columns. + self.grid.CreateGrid(1, 3) + + # Set the headers. + self.grid.SetColLabelValue(0, "Relaxation data ID") + self.grid.SetColLabelValue(1, "Data type") + self.grid.SetColLabelValue(2, "Frequency (Hz)") # Properties. self.grid.SetDefaultCellFont(self.gui.font_normal) @@ -234,124 +232,6 @@ event.Skip() - def noe_spectrum_type(self, index): - """Add the NOE spectral type info to the grid. - - @param index: The column index for the data. - @type index: int - @return: True if a spectrum type exists, False otherwise. - @rtype: bool - """ - - # No type info. - if not hasattr(cdp, 'spectrum_type') or not len(cdp.spectrum_type): - return False - - # Append a column. - self.grid.AppendCols(numCols=1) - - # Set the column heading. - self.grid.SetColLabelValue(index, "NOE spectrum type") - - # Translation table. - table = { - 'sat': 'Saturated', - 'ref': 'Reference' - } - - # Set the values. - for i in range(len(cdp.spectrum_ids)): - # No value. - if cdp.spectrum_ids[i] not in cdp.spectrum_type.keys(): - continue - - # Set the value. - self.grid.SetCellValue(i, index, table[cdp.spectrum_type[cdp.spectrum_ids[i]]]) - - # Successful. - return True - - - def relax_times(self, index): - """Add the relaxation delay time info to the grid. - - @param index: The column index for the data. - @type index: int - @return: True if relaxation times exist, False otherwise. - @rtype: bool - """ - - # No type info. - if not hasattr(cdp, 'relax_times') or not len(cdp.relax_times): - return False - - # Append a column. - self.grid.AppendCols(numCols=1) - - # Set the column heading. - self.grid.SetColLabelValue(index, "Delay times") - - # Set the values. - for i in range(len(cdp.spectrum_ids)): - # No value. - if cdp.spectrum_ids[i] not in cdp.relax_times.keys(): - continue - - # Set the value. - self.grid.SetCellValue(i, index, float_to_gui(cdp.relax_times[cdp.spectrum_ids[i]])) - - # Successful. - return True - - - def replicates(self, index): - """Add the replicated spectra info to the grid. - - @param index: The column index for the data. - @type index: int - @return: True if relaxation times exist, False otherwise. - @rtype: bool - """ - - # No type info. - if not hasattr(cdp, 'replicates') or not len(cdp.replicates): - return False - - # Replicated spectra. - repl = replicated_flags() - - # Append a column. - self.grid.AppendCols(numCols=1) - - # Set the column heading. - self.grid.SetColLabelValue(index, "Replicate IDs") - - # Set the values. - for i in range(len(cdp.spectrum_ids)): - # No replicates. - if not repl[cdp.spectrum_ids[i]]: - continue - - # The replicated spectra. - id_list = replicated_ids(cdp.spectrum_ids[i]) - - # Convert to a string. - text = '' - for j in range(len(id_list)): - # Add the id. - text = "%s%s" % (text, id_list[j]) - - # Separator. - if j < len(id_list)-1: - text = "%s, " % text - - # Set the value. - self.grid.SetCellValue(i, index, str_to_gui(text)) - - # Successful. - return True - - def size_cols(self): """Set the column sizes."""