Author: bugman Date: Thu May 3 15:20:24 2012 New Revision: 15899 URL: http://svn.gna.org/viewcvs/relax?rev=15899&view=rev Log: A number of the pipe GUI user function front ends now use the wizard page element_*() methods. This is to simplify the code base. Modified: 1.3/gui/user_functions/pipe.py Modified: 1.3/gui/user_functions/pipe.py URL: http://svn.gna.org/viewcvs/relax/1.3/gui/user_functions/pipe.py?rev=15899&r1=15898&r2=15899&view=diff ============================================================================== --- 1.3/gui/user_functions/pipe.py (original) +++ 1.3/gui/user_functions/pipe.py Thu May 3 15:20:24 2012 @@ -27,12 +27,11 @@ import wx # relax module imports. -from generic_fns.pipes import PIPE_DESC, VALID_TYPES, cdp_name, pipe_names +from generic_fns.pipes import PIPE_DESC_LIST, VALID_TYPES, cdp_name, pipe_names # GUI module imports. from base import UF_base, UF_page from gui.misc import gui_to_list, gui_to_str, str_to_gui -from gui.components.combo_list import Combo_list from gui.paths import WIZARD_IMAGE_PATH @@ -142,22 +141,17 @@ @type sizer: wx.Sizer instance """ - # The pipe name input. - self.pipe_name = self.input_field(sizer, "The data pipe name:", tooltip=self.uf._doc_args_dict['pipe_name']) - - # The type selection. - self.pipe_type = self.combo_box(sizer, "The type of data pipe:", tooltip=self.uf._doc_args_dict['pipe_type'], read_only=True) - for i in range(len(VALID_TYPES)): - self.pipe_type.Append(PIPE_DESC[VALID_TYPES[i]]) - self.pipe_type.SetClientData(i, VALID_TYPES[i]) - - - def on_execute(self): - """Execute the user function.""" - - # Get the name and type. - pipe_name = gui_to_str(self.pipe_name.GetValue()) - pipe_type = self.pipe_type.GetClientData(self.pipe_type.GetSelection()) + # The argument GUI elements. + self.element_string(key='pipe_name', sizer=sizer, desc="The data pipe name:", tooltip=self.uf._doc_args_dict['pipe_name']) + self.element_string(key='pipe_type', element_type='combo', sizer=sizer, desc="The type of data pipe:", combo_choices=PIPE_DESC_LIST, combo_data=VALID_TYPES, tooltip=self.uf._doc_args_dict['pipe_type'], read_only=True) + + + def on_execute(self): + """Execute the user function.""" + + # Get the argument values. + pipe_name = self.GetValue('pipe_name') + pipe_type = self.GetValue('pipe_type') # Set the name. self.execute('pipe.create', pipe_name=pipe_name, pipe_type=pipe_type) @@ -179,18 +173,91 @@ @type sizer: wx.Sizer instance """ + # The argument GUI elements. + self.element_string(key='pipe_name', element_type='combo', sizer=sizer, desc="The pipe:", combo_choices=[], tooltip=self.uf._doc_args_dict['pipe_name']) + + + def on_display(self): + """Clear and update the pipe name list.""" + + # Reset the list. + self.ResetChoices('pipe_name', combo_choices=pipe_names()) + + + def on_execute(self): + """Execute the user function.""" + + # Get the argument values. + pipe_name = self.GetValue('pipe_name') + + # Delete the data pipe. + self.execute('pipe.delete', pipe_name) + + + +class Hybridise_page(UF_page): + """The pipe.hybridise() user function page.""" + + # Some class variables. + image_path = WIZARD_IMAGE_PATH + 'pipe_hybrid.png' + uf_path = ['pipe', 'hybridise'] + + + def add_contents(self, sizer): + """Add the pipe specific GUI elements. + + @param sizer: A sizer object. + @type sizer: wx.Sizer instance + """ + + # The argument GUI elements. + self.element_string(key='hybrid', sizer=sizer, desc="The hybrid pipe name:", tooltip=self.uf._doc_args_dict['hybrid']) + self.element_string_list(key='pipes', element_type='combo_list', sizer=sizer, desc="The pipes to hybridise:", combo_choices=pipe_names(), combo_list_size=2, tooltip=self.uf._doc_args_dict['pipes']) + + + def on_execute(self): + """Execute the user function.""" + + # Get the argument values. + hybrid = self.GetValue('hybrid') + pipes = self.GetValue('pipes') + + # Delete the data pipe. + self.execute('pipe.hybridise', hybrid=hybrid, pipes=pipes) + + + +class Switch_page(UF_page): + """The pipe.switch() user function page.""" + + # Some class variables. + image_path = WIZARD_IMAGE_PATH + 'pipe_switch.png' + uf_path = ['pipe', 'switch'] + + def add_contents(self, sizer): + """Add the pipe specific GUI elements. + + @param sizer: A sizer object. + @type sizer: wx.Sizer instance + """ + + # The current data pipe. + self.cdp = self.text(sizer, "The current data pipe (cdp):") + # The pipe selection. self.pipe_name = self.combo_box(sizer, "The pipe:", [], tooltip=self.uf._doc_args_dict['pipe_name']) def on_display(self): - """Clear and update the pipe name list.""" + """Clear and update the pipe name list and cdp.""" # Clear the previous data. self.pipe_name.Clear() + self.cdp.Clear() # Clear the pipe name. self.pipe_name.SetValue(str_to_gui('')) + self.cdp.SetValue(str_to_gui(cdp_name())) # The list of pipe names. for name in pipe_names(): @@ -203,87 +270,5 @@ # Get the name. pipe_name = str(self.pipe_name.GetValue()) - # Delete the data pipe. - self.execute('pipe.delete', pipe_name) - - - -class Hybridise_page(UF_page): - """The pipe.hybridise() user function page.""" - - # Some class variables. - image_path = WIZARD_IMAGE_PATH + 'pipe_hybrid.png' - uf_path = ['pipe', 'hybridise'] - - - def add_contents(self, sizer): - """Add the pipe specific GUI elements. - - @param sizer: A sizer object. - @type sizer: wx.Sizer instance - """ - - # The hybrid data pipe name input. - self.hybrid = self.input_field(sizer, "The hybrid pipe name:", tooltip=self.uf._doc_args_dict['hybrid']) - - # The pipe selection. - self.pipes = Combo_list(self, sizer, "The pipes to hybridise:", n=2, choices=pipe_names(), tooltip=self.uf._doc_args_dict['pipes']) - - - def on_execute(self): - """Execute the user function.""" - - # Get the name. - hybrid = gui_to_str(self.hybrid.GetValue()) - pipes = gui_to_list(self.pipes.GetValue()) - - # Delete the data pipe. - self.execute('pipe.hybridise', hybrid=hybrid, pipes=pipes) - - - -class Switch_page(UF_page): - """The pipe.switch() user function page.""" - - # Some class variables. - image_path = WIZARD_IMAGE_PATH + 'pipe_switch.png' - uf_path = ['pipe', 'switch'] - - def add_contents(self, sizer): - """Add the pipe specific GUI elements. - - @param sizer: A sizer object. - @type sizer: wx.Sizer instance - """ - - # The current data pipe. - self.cdp = self.text(sizer, "The current data pipe (cdp):") - - # The pipe selection. - self.pipe_name = self.combo_box(sizer, "The pipe:", [], tooltip=self.uf._doc_args_dict['pipe_name']) - - - def on_display(self): - """Clear and update the pipe name list and cdp.""" - - # Clear the previous data. - self.pipe_name.Clear() - self.cdp.Clear() - - # Clear the pipe name. - self.pipe_name.SetValue(str_to_gui('')) - self.cdp.SetValue(str_to_gui(cdp_name())) - - # The list of pipe names. - for name in pipe_names(): - self.pipe_name.Append(str_to_gui(name)) - - - def on_execute(self): - """Execute the user function.""" - - # Get the name. - pipe_name = str(self.pipe_name.GetValue()) - # Switch the data pipe. self.execute('pipe.switch', pipe_name)