Author: bugman Date: Mon Jul 25 21:02:58 2011 New Revision: 13867 URL: http://svn.gna.org/viewcvs/relax?rev=13867&view=rev Log: Implemented the model-free model selector window. Modified: branches/gui_testing/gui/analyses/auto_model_free.py Modified: branches/gui_testing/gui/analyses/auto_model_free.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/auto_model_free.py?rev=13867&r1=13866&r2=13867&view=diff ============================================================================== --- branches/gui_testing/gui/analyses/auto_model_free.py (original) +++ branches/gui_testing/gui/analyses/auto_model_free.py Mon Jul 25 21:02:58 2011 @@ -28,6 +28,7 @@ from os import sep import sys import wx +import wx.lib.mixins.listctrl # relax module imports. from auto_analyses import dauvergne_protocol @@ -48,7 +49,7 @@ from gui.filedialog import opendir from gui.fonts import font from gui.message import error_message, missing_data -from gui.misc import gui_to_int, list_to_gui, protected_exec +from gui.misc import add_border, gui_to_int, list_to_gui, protected_exec, str_to_gui from gui import paths @@ -488,9 +489,6 @@ # Terminate the event. event.Skip() - - - def results_directory(self, event): @@ -664,6 +662,9 @@ for i in range(len(self.models)): self.select.append(True) + # Initialise the model selection window. + self.model_win = Model_sel_window(self.models, self.params) + # Horizontal packing for this element. sizer = wx.BoxSizer(wx.HORIZONTAL) @@ -674,7 +675,7 @@ sizer.AddSpacer((self.parent.spacer_horizontal, -1)) # The text input field. - field = self.parent.add_text_control(sizer, self.parent, text=list_to_gui(self.GetValue()), editable=False) + self.field = self.parent.add_text_control(sizer, self.parent, text=list_to_gui(self.GetValue()), editable=False) # Spacer. sizer.AddSpacer((self.parent.spacer_horizontal, -1)) @@ -732,8 +733,16 @@ @type event: wx event """ - # Initialise the - print "mod" + # Show the model selector window. + if status.show_gui: + self.model_win.ShowModal() + self.model_win.Close() + + # Set the values. + self.select = self.model_win.get_selection() + + # Update the GUI element. + self.field.SetValue(list_to_gui(self.GetValue())) @@ -768,3 +777,110 @@ ] + +class Model_sel_window(wx.Dialog): + """The model-free model selector window object.""" + + def __init__(self, models, params): + """Set up the model-free model selector window. + + @param models: The list of model-free models. + @type models: list of str + @param params: The list of parameters corresponding to the models. + @type params: list of str + """ + + # Set up the frame. + wx.Dialog.__init__(self, None, id=-1, title="Model-free model selector") + + # Initialise some values + size_x = 500 + size_y = 300 + border = 10 + width = size_x - 2*border + + # Set the frame properties. + self.SetSize((size_x, size_y)) + self.Centre() + self.SetFont(font.normal) + + # The main box sizer. + main_sizer = wx.BoxSizer(wx.VERTICAL) + + # Pack the sizer into the frame. + self.SetSizer(main_sizer) + + # Build the central sizer, with borders. + sizer = add_border(main_sizer, border=border, packing=wx.VERTICAL) + + # Add a list control. + self.model_list = ModelSelListCtrl(self) + + # The headers. + self.model_list.InsertColumn(0, "Model-free model") + self.model_list.InsertColumn(1, "Parameters") + + # The widths. + self.model_list.SetColumnWidth(0, int(0.4*width)) + self.model_list.SetColumnWidth(1, int(0.5*width)) + + # Add the models and parameters. + for i in range(len(models)): + # Set the text. + self.model_list.Append((str_to_gui(models[i]), str_to_gui(params[i]))) + + # Set all selections to True. + self.model_list.CheckItem(i) + + # Add the table to the sizer. + sizer.Add(self.model_list, 1, wx.ALL|wx.EXPAND, 0) + + # Bind some events. + self.Bind(wx.EVT_CLOSE, self.handler_close) + + + def get_selection(self): + """Return the selection as a list of booleans. + + @return: The list of models selected. + @rtype: list of bool + """ + + # Init. + select = [] + + # Loop over the entries. + for i in range(self.model_list.GetItemCount()): + select.append(self.model_list.IsChecked(i)) + + # Return the list. + return select + + + def handler_close(self, event): + """Event handler for the close window action. + + @param event: The wx event. + @type event: wx event + """ + + # Close the window. + self.Hide() + + + +class ModelSelListCtrl(wx.ListCtrl, wx.lib.mixins.listctrl.CheckListCtrlMixin): + """A special list control with checkboxes.""" + + def __init__(self, parent): + """Initialise the control. + + @param parent: The parent window. + @type parent: wx.Frame instance + """ + + # Execute the list control __init__() method. + wx.ListCtrl.__init__(self, parent, -1, style=wx.BORDER_SUNKEN|wx.LC_REPORT) + + # Execute the CheckListCtrlMixin __init__() method. + wx.lib.mixins.listctrl.CheckListCtrlMixin.__init__(self)