mailr15888 - /1.3/gui/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 03, 2012 - 09:04:
Author: bugman
Date: Thu May  3 09:04:54 2012
New Revision: 15888

URL: http://svn.gna.org/viewcvs/relax?rev=15888&view=rev
Log:
Better ComboBox support in wizard_elements.Base_value class.

Now strings and data are separate (if the data is supplied), and the 
GetValue() method now returns
the client data rather than the string value.


Modified:
    1.3/gui/wizard_elements.py

Modified: 1.3/gui/wizard_elements.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/wizard_elements.py?rev=15888&r1=15887&r2=15888&view=diff
==============================================================================
--- 1.3/gui/wizard_elements.py (original)
+++ 1.3/gui/wizard_elements.py Thu May  3 09:04:54 2012
@@ -42,7 +42,7 @@
 class Base_value:
     """Base wizard GUI element for the input of all types of lists."""
 
-    def __init__(self, name=None, parent=None, element_type='text', 
sizer=None, desc=None, choices=None, default=None, tooltip=None, 
divider=None, padding=0, spacer=None):
+    def __init__(self, name=None, parent=None, element_type='text', 
sizer=None, desc=None, combo_choices=None, combo_data=None, 
combo_default=None, tooltip=None, divider=None, padding=0, spacer=None):
         """Set up the base value element.
 
 
@@ -56,10 +56,12 @@
         @type sizer:            wx.Sizer instance
         @param desc:            The text description.
         @type desc:             str
-        @keyword choices:       The list of choices to present to the user.  
This is only used if the element_type is set to 'combo'.
-        @type choices:          list of str
-        @keyword default:       The default value of the ComboBox.  This is 
only used if the element_type is set to 'combo'.
-        @type default:          str or None
+        @keyword combo_choices: The list of choices to present to the user.  
This is only used if the element_type is set to 'combo'.
+        @type combo_choices:    list of str
+        @keyword combo_data:    The data returned by a call to GetValue().  
This is only used if the element_type is set to 'combo'.  If supplied, it 
should be the same length at the combo_choices list.  If not supplied, the 
combo_choices list will be used for the returned data.
+        @type combo_data:       list
+        @keyword combo_default: The default value of the ComboBox.  This is 
only used if the element_type is set to 'combo'.
+        @type combo_default:    str or None
         @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.
@@ -72,6 +74,7 @@
 
         # Store the args.
         self.name = name
+        self.element_type = element_type
 
         # Init.
         sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -92,12 +95,32 @@
         x, y = text.GetSize()
         sub_sizer.AddSpacer((divider - x, 0))
 
-        # Initialise the input field.
+        # Initialise the text input field.
         if element_type == 'text':
             self._field = wx.TextCtrl(parent, -1, '')
+
+        # Initialise the combo box input field.
         elif element_type == 'combo':
-            self._field = wx.ComboBox(self, -1, '', choices=choices)
-            self._field.SetValue(str_to_gui(default))
+            # Set up the combo box.
+            self._field = wx.ComboBox(self, -1, '')
+
+            # Loop over the choices and data, adding both to the element.
+            if combo_choices != None:
+                for i in range(len(combo_choices)):
+                    # Set the string value.
+                    self._field.Append(str_to_gui(combo_choices[i]))
+
+                    # Set the data.
+                    if combo_data != None:
+                        self._field.SetClientData(i, combo_data[i])
+                    else:
+                        self._field.SetClientData(i, combo_choices[i])
+
+                # Set the default selection.
+                if combo_default:
+                    self._field.SetStringSelection(combo_default)
+
+        # Unknown field.
         else:
             raise RelaxError("Unknown element type '%s'." % element_type)
 
@@ -141,8 +164,13 @@
         @rtype:     list of str
         """
 
-        # Convert and return the value.
-        return self.convert_from_gui(self._field.GetValue())
+        # Convert and return the value from a TextCtrl.
+        if self.element_type == 'text':
+            return self.convert_from_gui(self._field.GetValue())
+
+        # Convert and return the value from a ComboBox.
+        if self.element_type == 'combo':
+            return 
self.convert_from_gui(self._field.GetClientData(self._field.GetSelection()))
 
 
     def SetValue(self, value):




Related Messages


Powered by MHonArc, Updated Thu May 03 09:40:02 2012