Author: bugman Date: Tue May 22 16:43:36 2012 New Revision: 16394 URL: http://svn.gna.org/viewcvs/relax?rev=16394&view=rev Log: Renamed all of the ResetChoices() GUI methods to UpdateChoices(). This is because they are for updating a list while retaining the current selection. Modified: branches/uf_redesign/gui/input_elements/combo_list.py branches/uf_redesign/gui/input_elements/sequence.py branches/uf_redesign/gui/input_elements/value.py branches/uf_redesign/gui/uf_objects.py Modified: branches/uf_redesign/gui/input_elements/combo_list.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/input_elements/combo_list.py?rev=16394&r1=16393&r2=16394&view=diff ============================================================================== --- branches/uf_redesign/gui/input_elements/combo_list.py (original) +++ branches/uf_redesign/gui/input_elements/combo_list.py Tue May 22 16:43:36 2012 @@ -291,8 +291,50 @@ return text - 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. + def SetValue(self, value=None, index=None): + """Special method for setting the value of the GUI element. + + @keyword value: The value to set. + @type value: value or list of values + @keyword index: The index of the value to set. + @type index: int + """ + + # Single element. + if not isinstance(value, list): + # The index default. + if index == None: + index = 0 + + # Add elements as needed. + if len(self._combo_boxes) <= index: + for i in range(len(self._combo_boxes) - index + 1): + self._add(None) + + # Loop until the proper client data is found. + for j in range(self._combo_boxes[index].GetCount()): + if self._combo_boxes[index].GetClientData(j) == value: + self._combo_boxes[index].SetSelection(j) + break + + # A list of values. + else: + # Add elements as needed. + if len(self._combo_boxes) <= len(value): + for i in range(len(value) - len(self._combo_boxes)): + self._add(None) + + # Loop over the list. + for i in range(len(value)): + # Loop until the proper client data is found. + for j in range(self._combo_boxes[i].GetCount()): + if self._combo_boxes[i].GetClientData(j) == value: + self._combo_boxes[i].SetSelection(j) + break + + + def UpdateChoices(self, combo_choices=None, combo_data=None, combo_default=None): + """Special wizard method for updating the list of choices in a ComboBox type element. @param key: The key corresponding to the desired GUI element. @type key: str @@ -348,45 +390,3 @@ for j in range(self._combo_boxes[i].GetCount()): if self._combo_boxes[i].GetClientData(j) == sel: self._combo_boxes[i].SetSelection(j) - - - def SetValue(self, value=None, index=None): - """Special method for setting the value of the GUI element. - - @keyword value: The value to set. - @type value: value or list of values - @keyword index: The index of the value to set. - @type index: int - """ - - # Single element. - if not isinstance(value, list): - # The index default. - if index == None: - index = 0 - - # Add elements as needed. - if len(self._combo_boxes) <= index: - for i in range(len(self._combo_boxes) - index + 1): - self._add(None) - - # Loop until the proper client data is found. - for j in range(self._combo_boxes[index].GetCount()): - if self._combo_boxes[index].GetClientData(j) == value: - self._combo_boxes[index].SetSelection(j) - break - - # A list of values. - else: - # Add elements as needed. - if len(self._combo_boxes) <= len(value): - for i in range(len(value) - len(self._combo_boxes)): - self._add(None) - - # Loop over the list. - for i in range(len(value)): - # Loop until the proper client data is found. - for j in range(self._combo_boxes[i].GetCount()): - if self._combo_boxes[i].GetClientData(j) == value: - self._combo_boxes[i].SetSelection(j) - break Modified: branches/uf_redesign/gui/input_elements/sequence.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/input_elements/sequence.py?rev=16394&r1=16393&r2=16394&view=diff ============================================================================== --- branches/uf_redesign/gui/input_elements/sequence.py (original) +++ branches/uf_redesign/gui/input_elements/sequence.py Tue May 22 16:43:36 2012 @@ -270,8 +270,34 @@ return value - 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. + def SetValue(self, value=None, index=None): + """Special method for setting the value of the GUI element. + + @keyword value: The value to set. + @type value: value or list of values + @keyword index: The index of the value to set, if the full list is not given. + @type index: int or None + """ + + # The ComboBox list. + if self.element_type == 'combo_list': + self._field.SetValue(value=value, index=index) + + # The other elements. + else: + # Handle single values. + if self.single_value and isinstance(value, list): + if len(value) == 1: + value = value[0] + else: + raise RelaxError("The list of values '%s' cannot be converted to a single value." % value) + + # Convert and set the value. + self._field.SetValue(self.convert_to_gui(value)) + + + def UpdateChoices(self, combo_choices=None, combo_data=None, combo_default=None): + """Special wizard method for updating the list of choices in a ComboBox type element. @param key: The key corresponding to the desired GUI element. @type key: str @@ -285,33 +311,7 @@ # The ComboBox list. if self.element_type == 'combo_list': - self._field.ResetChoices(combo_choices=combo_choices, combo_data=combo_data, combo_default=combo_default) - - - def SetValue(self, value=None, index=None): - """Special method for setting the value of the GUI element. - - @keyword value: The value to set. - @type value: value or list of values - @keyword index: The index of the value to set, if the full list is not given. - @type index: int or None - """ - - # The ComboBox list. - if self.element_type == 'combo_list': - self._field.SetValue(value=value, index=index) - - # The other elements. - else: - # Handle single values. - if self.single_value and isinstance(value, list): - if len(value) == 1: - value = value[0] - else: - raise RelaxError("The list of values '%s' cannot be converted to a single value." % value) - - # Convert and set the value. - self._field.SetValue(self.convert_to_gui(value)) + self._field.UpdateChoices(combo_choices=combo_choices, combo_data=combo_data, combo_default=combo_default) def open_dialog(self, event): 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=16394&r1=16393&r2=16394&view=diff ============================================================================== --- branches/uf_redesign/gui/input_elements/value.py (original) +++ branches/uf_redesign/gui/input_elements/value.py Tue May 22 16:43:36 2012 @@ -195,7 +195,7 @@ self._field = wx.ComboBox(parent, -1, '', style=style) # Update the choices. - self.ResetChoices(combo_choices=combo_choices, combo_data=combo_data, combo_default=default) + self.UpdateChoices(combo_choices=combo_choices, combo_data=combo_data, combo_default=default) # Unknown field. else: @@ -278,8 +278,48 @@ return value - 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. + 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 or None + """ + + # No value. + if value == None: + return + + # Convert and set the value for a TextCtrl. + if self.element_type == 'text': + self._field.SetValue(self.convert_to_gui(value)) + + # Set the value for a SpinCtrl. + elif self.element_type == 'spin': + self._field.SetValue(value) + + # 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) + + + def UpdateChoices(self, combo_choices=None, combo_data=None, combo_default=None): + """Special wizard method for updating the list of choices in a ComboBox type element. @param key: The key corresponding to the desired GUI element. @type key: str @@ -293,13 +333,13 @@ # A TextCtrl?! if self.element_type == 'text': - raise RelaxError("Cannot reset the list of ComboBox choices as this is a TextCtrl!") + raise RelaxError("Cannot update the list of ComboBox choices as this is a TextCtrl!") # A SpinCtrl?! if self.element_type == 'spin': - raise RelaxError("Cannot reset the list of ComboBox choices as this is a SpinCtrl!") - - # Reset the choices for a ComboBox. + raise RelaxError("Cannot update the list of ComboBox choices as this is a SpinCtrl!") + + # Update the choices for a ComboBox. if self.element_type == 'combo': # First clear all data. self.Clear() @@ -329,43 +369,3 @@ # Set the selection. self._field.SetStringSelection(string) - - - 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 or None - """ - - # No value. - if value == None: - return - - # Convert and set the value for a TextCtrl. - if self.element_type == 'text': - self._field.SetValue(self.convert_to_gui(value)) - - # Set the value for a SpinCtrl. - elif self.element_type == 'spin': - self._field.SetValue(value) - - # 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) Modified: branches/uf_redesign/gui/uf_objects.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/uf_objects.py?rev=16394&r1=16393&r2=16394&view=diff ============================================================================== --- branches/uf_redesign/gui/uf_objects.py (original) +++ branches/uf_redesign/gui/uf_objects.py Tue May 22 16:43:36 2012 @@ -336,8 +336,26 @@ return self.uf_args[key].GetValue() - def ResetChoices(self, key, combo_choices=None, combo_data=None, combo_default=None): - """Special user function page method for resetting the list of choices in a ComboBox type element. + def SetValue(self, key, value): + """Special wizard method for setting the value of the GUI element corresponding to the key. + + @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 + """ + + # Handle the free file format args (for external control, i.e. via the test suite). + if key in ['spin_id_col', 'mol_name_col', 'res_num_col', 'res_name_col', 'spin_num_col', 'spin_name_col', 'data_col', 'error_col', 'sep']: + self.uf_args['free_file_format'].SetValue(key, value) + + # Call the argument element's method. + else: + self.uf_args[key].SetValue(value) + + + def UpdateChoices(self, key, combo_choices=None, combo_data=None, combo_default=None): + """Special user function page method for updating the list of choices in a ComboBox type element. @param key: The key corresponding to the desired GUI element. @type key: str @@ -350,25 +368,7 @@ """ # Call the argument element's method. - self.uf_args[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 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 - """ - - # Handle the free file format args (for external control, i.e. via the test suite). - if key in ['spin_id_col', 'mol_name_col', 'res_num_col', 'res_name_col', 'spin_num_col', 'spin_name_col', 'data_col', 'error_col', 'sep']: - self.uf_args['free_file_format'].SetValue(key, value) - - # Call the argument element's method. - else: - self.uf_args[key].SetValue(value) + self.uf_args[key].UpdateChoices(combo_choices=combo_choices, combo_data=combo_data, combo_default=combo_default) def add_contents(self, sizer): @@ -740,8 +740,8 @@ # Return as a failure. return False - # Reset. - self.ResetChoices(name, combo_choices=choices, combo_data=data) + # Update the GUI element. + self.UpdateChoices(name, combo_choices=choices, combo_data=data)