Author: bugman Date: Wed May 2 21:01:53 2012 New Revision: 15882 URL: http://svn.gna.org/viewcvs/relax?rev=15882&view=rev Log: Created a new wizard element for inputting strings. This will be used for user function args which should be strings. The wizard page element_string() method creates the element from the wizard_elements.String class. This class inherits from wizard_elements.Base_value which contains most of the executable code. Modified: 1.3/gui/wizard.py 1.3/gui/wizard_elements.py Modified: 1.3/gui/wizard.py URL: http://svn.gna.org/viewcvs/relax/1.3/gui/wizard.py?rev=15882&r1=15881&r2=15882&view=diff ============================================================================== --- 1.3/gui/wizard.py (original) +++ 1.3/gui/wizard.py Wed May 2 21:01:53 2012 @@ -41,7 +41,7 @@ from gui.misc import add_border, bool_to_gui, gui_to_int, gui_to_str, int_to_gui, open_file, protected_exec, str_to_gui from gui.message import Question from gui import paths -from gui.wizard_elements import String_list, String_list_of_lists +from gui.wizard_elements import String, String_list, String_list_of_lists class Wiz_page(wx.Panel): @@ -549,6 +549,32 @@ # Return the combo box element. return combo + + + def element_string(self, key=None, sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None): + """Set up the element and store it. + + @keyword key: The dictionary key to store the element with. + @type key: str + @keyword sizer: The sizer to put the input field widget into. + @type sizer: wx.Sizer instance + @keyword desc: The text description. + @type desc: str + @keyword tooltip: The tooltip which appears on hovering over the text or input field. + @type tooltip: str + @keyword divider: The optional position of the divider. If None, the class variable _div_left will be used. + @type divider: None or int + @keyword padding: Spacing to the left and right of the widgets. + @type padding: int + @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used. + @type spacer: None or int + """ + + # Create the element. + element = String(name=key, parent=self, sizer=sizer, desc=desc, tooltip=tooltip, divider=divider, padding=padding, spacer=spacer) + + # Store it. + self._elements[key] = element def element_string_list(self, key=None, sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None): Modified: 1.3/gui/wizard_elements.py URL: http://svn.gna.org/viewcvs/relax/1.3/gui/wizard_elements.py?rev=15882&r1=15881&r2=15882&view=diff ============================================================================== --- 1.3/gui/wizard_elements.py (original) +++ 1.3/gui/wizard_elements.py Wed May 2 21:01:53 2012 @@ -38,6 +38,109 @@ from gui import paths +class Base_value: + """Base wizard GUI element for the input of all types of lists.""" + + def __init__(self, name=None, parent=None, sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None): + """Set up the base value element. + + + @keyword name: The name of the element to use in titles, etc. + @type name: str + @keyword parent: The wizard GUI element. + @param sizer: The sizer to put the input field widget into. + @type sizer: wx.Sizer instance + @param desc: The text description. + @type desc: str + @keyword tooltip: The tooltip which appears on hovering over the text or input field. + @type tooltip: str + @keyword divider: The optional position of the divider. If None, the class variable _div_left will be used. + @type divider: None or int + @keyword padding: Spacing to the left and right of the widgets. + @type padding: int + @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used. + @type spacer: None or int + """ + + # Store the args. + self.name = name + + # Init. + sub_sizer = wx.BoxSizer(wx.HORIZONTAL) + + # Left padding. + sub_sizer.AddSpacer(padding) + + # The description. + text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT) + text.SetFont(font.normal) + sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) + + # The divider. + if not divider: + divider = parent._div_left + + # Spacing. + x, y = text.GetSize() + sub_sizer.AddSpacer((divider - x, 0)) + + # The input field. + self._field = wx.TextCtrl(parent, -1, '') + self._field.SetMinSize((50, parent.height_element)) + self._field.SetFont(font.normal) + sub_sizer.Add(self._field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) + + # Right padding. + sub_sizer.AddSpacer(padding) + + # Add to the main sizer. + sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) + + # Spacing below the widget. + if spacer == None: + sizer.AddStretchSpacer() + else: + sizer.AddSpacer(spacer) + + # Tooltip. + if tooltip: + text.SetToolTipString(tooltip) + self._field.SetToolTipString(tooltip) + + # Set up the specific conversion functions. + self.conversion_fns() + + + def conversion_fns(self): + """Dummy method for setting up the conversion functions. + + This should define the self.convert_to_gui() and self.convert_from_gui() function aliases. + """ + + + def GetValue(self): + """Special method for returning the value of the GUI element. + + @return: The string list value. + @rtype: list of str + """ + + # Convert and return the value. + return self.convert_from_gui(self._field.GetValue()) + + + def SetValue(self, value): + """Special method for setting the value of the GUI element. + + @param value: The value to set. + @type value: list of str + """ + + # Convert and set the value. + self._field.SetValue(self.convert_to_gui(value)) + + + class List: """Base wizard GUI element for the input of all types of lists.""" @@ -169,6 +272,17 @@ # Destroy the window. del win + + + +class String(Base_value): + """Wizard GUI element for the input of strings.""" + + def conversion_fns(self): + """Set up the conversion functions.""" + + self.convert_from_gui = gui_to_str + self.convert_to_gui = str_to_gui