Author: bugman Date: Fri May 18 18:00:27 2012 New Revision: 16350 URL: http://svn.gna.org/viewcvs/relax?rev=16350&view=rev Log: The Value GUI element as a ComboBox can now handle input values which are not in the list. This allows user functions with the 'wiz_combo_choices' arg arg set and the 'wiz_read_only' arg arg of False to function. This is for the user to select from a list of pre-defined defaults, or input their own value. Modified: branches/uf_redesign/gui/input_elements/value.py Modified: branches/uf_redesign/gui/input_elements/value.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/input_elements/value.py?rev=16350&r1=16349&r2=16350&view=diff ============================================================================== --- branches/uf_redesign/gui/input_elements/value.py (original) +++ branches/uf_redesign/gui/input_elements/value.py Fri May 18 18:00:27 2012 @@ -108,6 +108,7 @@ self.default = default self.element_type = element_type self.can_be_none = can_be_none + self.read_only = read_only # The value types. if value_type in ['float', 'num']: @@ -266,7 +267,15 @@ # Convert and return the value from a ComboBox. if self.element_type == 'combo': - return self.convert_from_gui(self._field.GetClientData(self._field.GetSelection())) + # An element selected from the list. + value = self.convert_from_gui(self._field.GetClientData(self._field.GetSelection())) + + # A non-list value. + if value == None: + value = self.convert_from_gui(self._field.GetValue()) + + # Return the value. + return value def ResetChoices(self, combo_choices=None, combo_data=None, combo_default=None): @@ -344,7 +353,19 @@ # Convert and set the value for a ComboBox. elif self.element_type == 'combo': # Loop until the proper client data is found. + found = False for i in range(self._field.GetCount()): if self._field.GetClientData(i) == value: self._field.SetSelection(i) + found = True break + + # No value found. + if not found: + # Invalid value. + if self.read_only: + raise RelaxError("The Value element is read only, cannot set the value '%s'." % value) + + # Set the unknown value. + else: + self._field.SetValue(value)