mailr15988 - in /branches/uf_redesign/gui: uf_objects.py wizard.py wizard_elements.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on May 04, 2012 - 20:05:
Author: bugman
Date: Fri May  4 20:05:54 2012
New Revision: 15988

URL: http://svn.gna.org/viewcvs/relax?rev=15988&view=rev
Log:
Boolean argument types are now supported by the auto-generated GUI user 
functions.

The Selector_bool object and element_bool() wizard page method have been 
written for this.


Modified:
    branches/uf_redesign/gui/uf_objects.py
    branches/uf_redesign/gui/wizard.py
    branches/uf_redesign/gui/wizard_elements.py

Modified: branches/uf_redesign/gui/uf_objects.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/uf_objects.py?rev=15988&r1=15987&r2=15988&view=diff
==============================================================================
--- branches/uf_redesign/gui/uf_objects.py (original)
+++ branches/uf_redesign/gui/uf_objects.py Fri May  4 20:05:54 2012
@@ -194,6 +194,10 @@
             elif arg['arg_type'] == 'dir sel':
                 self.element_dir_sel(key=arg['name'], sizer=sizer, 
desc=desc, tooltip=arg['desc'], read_only=arg['wiz_read_only'])
 
+            # Bool type.
+            elif arg['py_type'] == 'bool':
+                self.element_bool(key=arg['name'], 
element_type=arg['wiz_element_type'], sizer=sizer, desc=desc, 
tooltip=arg['desc'], default=arg['default'])
+
             # Int type.
             elif arg['py_type'] == 'int':
                 self.element_int(key=arg['name'], 
element_type=arg['wiz_element_type'], sizer=sizer, desc=desc, 
combo_choices=arg['wiz_combo_choices'], combo_data=arg['wiz_combo_data'], 
combo_default=arg['wiz_combo_default'], tooltip=arg['desc'], 
read_only=arg['wiz_read_only'])

Modified: branches/uf_redesign/gui/wizard.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/wizard.py?rev=15988&r1=15987&r2=15988&view=diff
==============================================================================
--- branches/uf_redesign/gui/wizard.py (original)
+++ branches/uf_redesign/gui/wizard.py Fri May  4 20:05:54 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 Integer, Selector_file, String, String_list, 
String_list_of_lists
+from gui.wizard_elements import Integer, Selector_bool, Selector_file, 
String, String_list, String_list_of_lists
 
 
 class Wiz_page(wx.Panel):
@@ -581,6 +581,36 @@
 
         # Return the combo box element.
         return combo
+
+
+    def element_bool(self, key=None, element_type='default', sizer=None, 
desc=None, tooltip=None, divider=None, padding=0, spacer=None, default=True):
+        """Set up the integer element and store it.
+
+        @keyword key:           The dictionary key to store the element with.
+        @type key:              str
+        @keyword element_type:  The type of GUI element to create.  If set 
to 'text', a wx.TextCtrl element will be used.  If set to 'combo', a 
wx.ComboBox element will be used.
+        @type element_type:     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
+        @keyword default:       The default value.
+        @type default:          bool
+        """
+
+        # Create the element.
+        element = Selector_bool(name=key, parent=self, 
element_type=element_type, sizer=sizer, desc=desc, tooltip=tooltip, 
divider=divider, padding=padding, spacer=spacer, default=default)
+
+        # Store it.
+        self._elements[key] = element
 
 
     def element_dir_sel(self, key=None, sizer=None, desc=None, tooltip=None, 
divider=None, padding=0, spacer=None, read_only=False):

Modified: branches/uf_redesign/gui/wizard_elements.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/wizard_elements.py?rev=15988&r1=15987&r2=15988&view=diff
==============================================================================
--- branches/uf_redesign/gui/wizard_elements.py (original)
+++ branches/uf_redesign/gui/wizard_elements.py Fri May  4 20:05:54 2012
@@ -37,7 +37,7 @@
 from gui.components.combo_list import Combo_list
 from gui.filedialog import RelaxFileDialog
 from gui.fonts import font
-from gui.misc import add_border, gui_to_int, gui_to_list, gui_to_str, 
int_to_gui, list_to_gui, str_to_gui
+from gui.misc import add_border, bool_to_gui, gui_to_bool, gui_to_int, 
gui_to_list, gui_to_str, int_to_gui, list_to_gui, str_to_gui
 from gui import paths
 
 
@@ -424,6 +424,113 @@
         del win
 
 
+class Selector_bool:
+    """Wizard GUI element for boolean selection."""
+
+    def __init__(self, name=None, parent=None, element_type='default', 
sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None, 
default=True):
+        """Build the boolean selector widget for selecting between True and 
False.
+
+        @keyword name:          The name of the element to use in titles, 
etc.
+        @type name:             str
+        @keyword parent:        The wizard GUI element.
+        @type parent:           wx.Panel instance
+        @keyword element_type:  The type of GUI element to create.  This is 
currently unused, but can in the future specify alternative selector widgets.
+        @type element_type:     str
+        @keyword sizer:         The sizer to put the combo box 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
+        @keyword default:       The default boolean value.
+        @type default:          bool
+        """
+
+        # Store the args.
+        self.default = default
+        self.name = name
+        self.element_type = element_type
+
+        # 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 combo box element.
+        style = wx.CB_DROPDOWN | wx.CB_READONLY
+        self.combo = wx.ComboBox(parent, -1, value=bool_to_gui(default), 
style=style, choices=['True', 'False'])
+        self.combo.SetMinSize((50, parent.height_element))
+        self.combo.SetFont(font.normal)
+        sub_sizer.Add(self.combo, 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.combo.SetToolTipString(tooltip)
+
+
+    def Clear(self):
+        """Special method for clearing or resetting the GUI element."""
+
+        # Reset to the default.
+        self.combo.SetStringSelection(bool_to_gui(self.default))
+
+
+    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 from a ComboBox.
+        return 
gui_to_bool(self.combo.GetClientData(self.combo.GetSelection()))
+
+
+    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
+        """
+
+        # Set the selection.
+        self.combo.SetStringSelection(bool_to_gui(value))
+
+
+
 class Selector_file:
     """Wizard GUI element for selecting files."""
 




Related Messages


Powered by MHonArc, Updated Fri May 04 20:40:01 2012