Author: bugman Date: Fri Jul 15 11:57:49 2011 New Revision: 13640 URL: http://svn.gna.org/viewcvs/relax?rev=13640&view=rev Log: Redesign of the Spectra_list GUI element. This now initialises to a single row and column, and updates dynamically as spectra are added. The additional columns displaying the information associated with the spectrum ID are still to be added. Modified: branches/gui_testing/gui/analyses/auto_noe.py branches/gui_testing/gui/analyses/auto_rx_base.py branches/gui_testing/gui/components/spectrum.py Modified: branches/gui_testing/gui/analyses/auto_noe.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/auto_noe.py?rev=13640&r1=13639&r2=13640&view=diff ============================================================================== --- branches/gui_testing/gui/analyses/auto_noe.py (original) +++ branches/gui_testing/gui/analyses/auto_noe.py Fri Jul 15 11:57:49 2011 @@ -230,7 +230,7 @@ # Add the peak list selection GUI element, with spacing. box.AddSpacer(10) - self.peak_intensity = Spectra_list(gui=self.gui, parent=self.parent, data=self.data, label="NOE", box=box, fn_add=self.peak_wizard) + self.peak_intensity = Spectra_list(gui=self.gui, parent=self.parent, box=box, id=str(self.data_index), fn_add=self.peak_wizard) box.AddSpacer(10) # Add the execution GUI element. Modified: branches/gui_testing/gui/analyses/auto_rx_base.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/auto_rx_base.py?rev=13640&r1=13639&r2=13640&view=diff ============================================================================== --- branches/gui_testing/gui/analyses/auto_rx_base.py (original) +++ branches/gui_testing/gui/analyses/auto_rx_base.py Fri Jul 15 11:57:49 2011 @@ -240,7 +240,7 @@ # Add the peak list selection GUI element, with spacing. box.AddSpacer(10) - self.peak_intensity = Spectra_list(gui=self.gui, parent=self.parent, data=self.data, label=self.label, box=box) + self.peak_intensity = Spectra_list(gui=self.gui, parent=self.parent, id=str(self.data_index), box=box) box.AddSpacer(10) # Add the execution GUI element. Modified: branches/gui_testing/gui/components/spectrum.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/components/spectrum.py?rev=13640&r1=13639&r2=13640&view=diff ============================================================================== --- branches/gui_testing/gui/components/spectrum.py (original) +++ branches/gui_testing/gui/components/spectrum.py Fri Jul 15 11:57:49 2011 @@ -28,7 +28,10 @@ import wx import wx.lib.buttons -# relaxGUI module imports. +# relax module imports. +from status import Status; status = Status() + +# relax GUI module imports. from gui.misc import add_border from gui import paths @@ -38,10 +41,8 @@ # Class variables. col_label_width = 40 - col1_width = 160 - col2_width = 140 - - def __init__(self, gui=None, parent=None, data=None, label=None, width=688, height=300, box=None, fn_add=None, buttons=True): + + def __init__(self, gui=None, parent=None, box=None, id=None, fn_add=None, buttons=True): """Build the spectral list GUI element. @keyword gui: The main GUI object. @@ -50,14 +51,10 @@ @type parent: wx object @keyword data: The data storage container. @type data: class instance - @keyword label: The type of analysis. - @type label: str - @keyword width: The initial width of the GUI element. - @type width: int - @keyword height: The initial height of the GUI element. - @type height: int @keyword box: The vertical box sizer to pack this GUI component into. @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. @@ -67,16 +64,11 @@ # Store the arguments. self.gui = gui self.parent = parent - self.data = data - self.label = label self.fn_add = fn_add # GUI variables. self.spacing = 5 self.border = 5 - - # The number of rows. - self.num_rows = 50 # A static box to hold all the widgets, and its sizer. stat_box = wx.StaticBox(self.parent, -1, "Spectra list") @@ -93,33 +85,19 @@ if buttons: self.add_buttons(box_centre) - # Add the grid. + # Initialise the grid. box_centre.AddSpacer(self.spacing) - self.add_grid(box_centre) + self.init_grid(box_centre) box_centre.AddSpacer(self.spacing) - - def resize(self, event): - """Catch the resize to allow the grid to be resized. - - @param event: The wx event. - @type event: wx event - """ - - # The new grid size. - x, y = event.GetSize() - - # The expandable column width. - width = x - self.col_label_width - self.col1_width - self.col2_width - 20 - - # Set the column sizes. - self.grid.SetRowLabelSize(self.col_label_width) - self.grid.SetColSize(0, width) - self.grid.SetColSize(1, self.col1_width) - self.grid.SetColSize(2, self.col2_width) - - # Continue with the normal resizing. - event.Skip() + # Update the grid. + self.update() + + # Initialise observer name. + self.name = 'spectra list: %s' % id + + # Register the grid for updating when a user function completes. + status.observers.uf_gui.register(self.name, self.update) def add_buttons(self, sizer): @@ -146,8 +124,8 @@ button.SetToolTipString("Read a spectral data file.") - def add_grid(self, sizer): - """Add the grid for the peak list files and delay times. + def init_grid(self, sizer): + """Initialise the grid for the spectra listing. @param box: The sizer element to pack the grid into. @type box: wx.BoxSizer instance @@ -156,49 +134,81 @@ # Grid of peak list file names and relaxation time. self.grid = wx.grid.Grid(self.parent, -1) - # Create entries. - self.grid.CreateGrid(self.num_rows, 3) - - # Create headers. - self.grid.SetColLabelValue(0, "%s peak list" % self.label) - self.grid.SetColLabelValue(1, "Relaxation delay [s]") - self.grid.SetColLabelValue(2, "No. of cycles") + # Initialise to a single row and column. + self.grid.CreateGrid(1, 1) # Properties. self.grid.SetDefaultCellFont(self.gui.font_normal) self.grid.SetLabelFont(self.gui.font_normal_bold) - # Column properties. + # Set the row label widths. + self.grid.SetRowLabelSize(self.col_label_width) + + # No cell resizing allowed. + self.grid.EnableDragColSize(False) + self.grid.EnableDragRowSize(False) + + # Bind some events. + self.grid.Bind(wx.EVT_SIZE, self.resize) + + # Add grid to sizer, with spacing. + sizer.Add(self.grid, 1, wx.ALL|wx.EXPAND, 0) + + + def resize(self, event): + """Catch the resize to allow the grid to be resized. + + @param event: The wx event. + @type event: wx event + """ + + # The new grid size. + x, y = event.GetSize() + + # The expandable column width. + width = x - self.col_label_width - 20 + + # Set the column sizes. + self.grid.SetColSize(0, width) + + # Continue with the normal resizing. + event.Skip() + + + def update(self): + """Update the spectra listing.""" + + # First freeze the grid, so that the GUI element doesn't update until the end. + self.grid.Freeze() + + # Delete all rows and columns. + 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'): + # The number of IDs. + n = len(cdp.spectrum_ids) + + # Append the appropriate number of rows. + self.grid.AppendRows(numRows=n) + + # Set the IDs. + for i in range(n): + self.grid.SetCellValue(i, 0, cdp.spectrum_ids[i]) + + # Set the headers. + self.grid.SetColLabelValue(0, "Spectrum ID string") + + # Set the grid properties once finalised. for i in range(self.grid.GetNumberRows()): # Row properties. self.grid.SetRowSize(i, 27) - # No cell resizing allowed. - self.grid.EnableDragColSize(False) - self.grid.EnableDragRowSize(False) - - # Bind some events. - self.grid.Bind(wx.EVT_SIZE, self.resize) - - # Add grid to sizer, with spacing. - sizer.Add(self.grid, 1, wx.ALL|wx.EXPAND, 0) - - - def update_grid(self): - """Update the grid, changing the relaxation delay times as needed.""" - - # Loop over the rows. - for i in range(self.grid.GetNumberRows()): - # The number of cycles. - ncyc = str(self.grid.GetCellValue(i, 2)) - - # Update the relaxation time. - if time != '' and ncyc not in ['', '0']: - self.grid.SetCellValue(i, 1, str(int(ncyc) * time)) - - # The relaxation time and number of cycles. - relax_time = str(self.grid.GetCellValue(i, 1)) - - # Clear the relaxation time if set to zero. - if relax_time == '0.0': - self.grid.SetCellValue(i, 1, '') + # Loop over the columns. + for j in range(self.grid.GetNumberCols()): + # Cell properties. + self.grid.SetReadOnly(i, j) + + # Unfreeze. + self.grid.Thaw()