mailr16018 - 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 06, 2012 - 17:19:
Author: bugman
Date: Sun May  6 17:19:09 2012
New Revision: 16018

URL: http://svn.gna.org/viewcvs/relax?rev=16018&view=rev
Log:
Floats and tuples of numbers are now supported by the user function GUI 
argument elements.


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=16018&r1=16017&r2=16018&view=diff
==============================================================================
--- branches/uf_redesign/gui/uf_objects.py (original)
+++ branches/uf_redesign/gui/uf_objects.py Sun May  6 17:19:09 2012
@@ -203,6 +203,14 @@
             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'])
 
+            # Float type.
+            elif arg['py_type'] == 'float':
+                self.element_float(key=arg['name'], 
element_type=arg['wiz_element_type'], sizer=sizer, desc=desc, 
tooltip=arg['desc'], read_only=arg['wiz_read_only'])
+
+            # Tuple of numbers.
+            elif arg['py_type'] == 'num_tuple':
+                self.element_float_seq(key=arg['name'], 
element_type=arg['wiz_element_type'], seq_type='tuple', sizer=sizer, 
desc=desc, tooltip=arg['desc'], read_only=arg['wiz_read_only'])
+
             # String type.
             elif arg['py_type'] == 'str':
                 self.element_string(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=16018&r1=16017&r2=16018&view=diff
==============================================================================
--- branches/uf_redesign/gui/wizard.py (original)
+++ branches/uf_redesign/gui/wizard.py Sun May  6 17:19:09 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_bool, Selector_file, 
String, String_list, String_list_of_lists
+from gui.wizard_elements import Integer, List_float, Selector_bool, 
Selector_file, String, String_list, String_list_of_lists, Value_float
 
 
 class Wiz_page(wx.Panel):
@@ -670,6 +670,68 @@
 
         # Create the element.
         element = Selector_file(name=key, parent=self, sizer=sizer, 
desc=desc, message=message, wildcard=wildcard, style=style, tooltip=tooltip, 
divider=divider, padding=padding, spacer=spacer, read_only=read_only)
+
+        # Store it.
+        self._elements[key] = element
+
+
+    def element_float(self, key=None, element_type='default', sizer=None, 
desc=None, tooltip=None, divider=None, padding=0, spacer=None, 
read_only=False):
+        """Set up the 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 'default', the wx.TextCtrl element with a button to bring up a dialog 
with ListCtrl 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 read_only:         A flag which if True means that the text 
of the element cannot be edited.
+        @type read_only:            bool
+        """
+
+        # Create the element.
+        element = Value_float(name=key, element_type=element_type, 
parent=self, sizer=sizer, desc=desc, tooltip=tooltip, divider=divider, 
padding=padding, spacer=spacer, read_only=read_only)
+
+        # Store it.
+        self._elements[key] = element
+
+
+    def element_float_seq(self, key=None, element_type='default', 
seq_type='list', sizer=None, desc=None, tooltip=None, divider=None, 
padding=0, spacer=None, read_only=False):
+        """Set up the 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 'default', the wx.TextCtrl element with a button to bring up a dialog 
with ListCtrl will be used.
+        @type element_type:         str
+        @keyword seq_type:          The Python sequence type, i.e. one of 
'list' or 'tuple'.
+        @type seq_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 read_only:         A flag which if True means that the text 
of the element cannot be edited.
+        @type read_only:            bool
+        """
+
+        # Create the element.
+        element = List_float(name=key, element_type=element_type, 
seq_type=seq_type, parent=self, sizer=sizer, desc=desc, tooltip=tooltip, 
divider=divider, padding=padding, spacer=spacer, read_only=read_only)
 
         # Store it.
         self._elements[key] = element

Modified: branches/uf_redesign/gui/wizard_elements.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/wizard_elements.py?rev=16018&r1=16017&r2=16018&view=diff
==============================================================================
--- branches/uf_redesign/gui/wizard_elements.py (original)
+++ branches/uf_redesign/gui/wizard_elements.py Sun May  6 17:19:09 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, 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.misc import add_border, bool_to_gui, float_to_gui, gui_to_bool, 
gui_to_float, gui_to_int, gui_to_list, gui_to_str, int_to_gui, list_to_gui, 
str_to_gui
 from gui import paths
 
 
@@ -259,7 +259,7 @@
 class List:
     """Base wizard GUI element for the input of all types of lists."""
 
-    def __init__(self, name=None, parent=None, element_type='default', 
sizer=None, desc=None, combo_choices=None, combo_data=None, 
combo_default=None, combo_list_size=None, tooltip=None, divider=None, 
padding=0, spacer=None, read_only=False):
+    def __init__(self, name=None, parent=None, element_type='default', 
seq_type='list', sizer=None, desc=None, combo_choices=None, combo_data=None, 
combo_default=None, combo_list_size=None, tooltip=None, divider=None, 
padding=0, spacer=None, read_only=False):
         """Set up the element.
 
         @keyword name:              The name of the element to use in 
titles, etc.
@@ -268,6 +268,8 @@
         @type parent:               wx.Panel instance
         @keyword element_type:      The type of GUI element to create.  If 
set to 'default', the wx.TextCtrl element with a button to bring up a dialog 
with ListCtrl will be used.  If set to 'combo_list', the special 
gui.components.combo_list.Combo_list element will be used.
         @type element_type:         str
+        @keyword seq_type:          The type of Python sequence.  This 
should be one of 'list' or 'tuple'.
+        @type seq_type:             str
         @keyword sizer:             The sizer to put the input field widget 
into.
         @type sizer:                wx.Sizer instance
         @keyword desc:              The text description.
@@ -295,6 +297,7 @@
         # Store the args.
         self.name = name
         self.element_type = element_type
+        self.seq_type = seq_type
 
         # Initialise the default element.
         if self.element_type == 'default':
@@ -465,6 +468,18 @@
 
         # Destroy the window.
         del win
+
+
+
+class List_float(List):
+    """Wizard GUI element for the input of lists of strings."""
+
+    def init_window(self):
+        """Set up the specific window type."""
+
+        # Specify the window type to open.
+        return Sequence_window(name=self.name, seq_type=self.seq_type, 
base_type='float')
+
 
 
 class Selector_bool:
@@ -736,7 +751,7 @@
         """Set up the specific window type."""
 
         # Specify the window type to open.
-        return String_list_window(name=self.name)
+        return Sequence_window(name=self.name, seq_type='list', 
base_type='str')
 
 
 
@@ -798,7 +813,7 @@
 
 
 
-class String_list_window(wx.Dialog):
+class Sequence_window(wx.Dialog):
     """The string list editor window."""
 
     # The window size.
@@ -810,15 +825,33 @@
     # Sizes.
     SIZE_BUTTON = (150, 33)
 
-    def __init__(self, name=''):
+    def __init__(self, name='', seq_type='list', base_type='str'):
         """Set up the string list editor window.
 
-        @keyword name:  The name of the window.
-        @type name:     str
+        @keyword name:      The name of the window.
+        @type name:         str
+        @keyword seq_type:  The type of Python sequence.  This should be one 
of 'list' or 'tuple'.
+        @type seq_type:     str
+        @keyword base_type: The type of Python data expected in the 
sequence.  This should be one of 'float', 'int', or 'str'.
+        @type base_type:    str
         """
 
         # Store the args.
         self.name = name
+        self.seq_type = seq_type
+
+        # The base types.
+        if base_type == 'float':
+            self.convert_from_gui = gui_to_float
+            self.convert_to_gui =   float_to_gui
+        elif base_type == 'int':
+            self.convert_from_gui = gui_to_int
+            self.convert_to_gui =   int_to_gui
+        elif base_type == 'str':
+            self.convert_from_gui = gui_to_str
+            self.convert_to_gui =   str_to_gui
+        else:
+            raise RelaxError("Unknown base data type '%s'." % base_type)
 
         # The title of the dialog.
         title = "The list of %s" % name
@@ -856,8 +889,8 @@
     def GetValue(self):
         """Return the values as a list of strings.
 
-        @return:    The list of values.
-        @rtype:     list of str
+        @return:    The sequence of values.
+        @rtype:     sequence type
         """
 
         # Init.
@@ -865,9 +898,13 @@
 
         # Loop over the entries.
         for i in range(self.list.GetItemCount()):
-            values.append(gui_to_str(self.list.GetItemText(i)))
-
-        # Return the list.
+            values.append(self.convert_from_gui(self.list.GetItemText(i)))
+
+        # Sequence conversion.
+        if self.seq_type == 'tuple':
+            values = tuple(values)
+
+        # Return the sequence.
         return values
 
 
@@ -880,7 +917,7 @@
 
         # Loop over the entries.
         for i in range(len(values)):
-            self.list.InsertStringItem(i, str_to_gui(values[i]))
+            self.list.InsertStringItem(i, self.convert_to_gui(values[i]))
 
 
     def add_buttons(self, sizer):
@@ -1194,3 +1231,18 @@
 
         # Delete.
         self.list.DeleteAllItems()
+
+
+
+class Value_float(Base_value):
+    """Wizard GUI element for the input of floating point numbers."""
+
+    def conversion_fns(self):
+        """Set up the conversion functions."""
+
+        self.convert_from_gui = gui_to_float
+        self.convert_to_gui =   float_to_gui
+
+
+
+




Related Messages


Powered by MHonArc, Updated Sun May 06 17:40:02 2012