Author: bugman Date: Thu May 3 10:59:06 2012 New Revision: 15896 URL: http://svn.gna.org/viewcvs/relax?rev=15896&view=rev Log: Created the wizard page ResetChoices() method for resetting the list of values in a ComboBox. This is currently implemented for the wizard_elements.Base_value class. 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=15896&r1=15895&r2=15896&view=diff ============================================================================== --- 1.3/gui/wizard.py (original) +++ 1.3/gui/wizard.py Thu May 3 10:59:06 2012 @@ -264,7 +264,7 @@ def Clear(self, key): """Special wizard method for clearing the value of the GUI element corresponding to the key. - @param key: The key value of the desired GUI element. + @param key: The key corresponding to the desired GUI element. @type key: str """ @@ -275,7 +275,7 @@ def GetValue(self, key): """Special wizard method for getting the value of the GUI element corresponding to the key. - @param key: The key value of the desired GUI element. + @param key: The key corresponding to the desired GUI element. @type key: str @return: The value that the specific GUI element's GetValue() method returns. @rtype: unknown @@ -285,10 +285,27 @@ return self._elements[key].GetValue() + def ResetChoices(self, key, combo_choices=None, combo_data=None, combo_default=None): + """Special wizard method for resetting the list of choices in a ComboBox type element. + + @param key: The key corresponding to the desired GUI element. + @type key: str + @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 + """ + + # Call the element's method. + self._elements[key].ResetChoices(combo_choices=combo_choices, combo_data=combo_data, combo_default=combo_default) + + def SetValue(self, key, value): """Special wizard method for setting the value of the GUI element corresponding to the key. - @param key: The key value of the desired GUI element. + @param key: The key corresponding to the desired GUI element. @type key: str @param value: The value that the specific GUI element's SetValue() method expects. @type value: unknown Modified: 1.3/gui/wizard_elements.py URL: http://svn.gna.org/viewcvs/relax/1.3/gui/wizard_elements.py?rev=15896&r1=15895&r2=15896&view=diff ============================================================================== --- 1.3/gui/wizard_elements.py (original) +++ 1.3/gui/wizard_elements.py Thu May 3 10:59:06 2012 @@ -121,21 +121,8 @@ # Set up the combo box. self._field = wx.ComboBox(parent, -1, '', style=style) - # 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) + # Update the choices. + self.ResetChoices(combo_choices=combo_choices, combo_data=combo_data, combo_default=combo_default) # Unknown field. else: @@ -189,6 +176,44 @@ # 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 ResetChoices(self, combo_choices=None, combo_data=None, combo_default=None): + """Special wizard method for resetting the list of choices in a ComboBox type element. + + @param key: The key corresponding to the desired GUI element. + @type key: str + @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 + """ + + # A TextCtrl?! + if self.element_type == 'text': + raise RelaxError("Cannot reset the list of ComboBox choices as this is a TextCtrl!") + + # Reset the choices for a ComboBox. + if self.element_type == 'combo': + # First clear all data. + self.Clear() + + # Loop over the choices and data, adding both to the element. + 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) def SetValue(self, value):