Author: bugman Date: Sun May 6 17:44:31 2012 New Revision: 16020 URL: http://svn.gna.org/viewcvs/relax?rev=16020&view=rev Log: Better checking of the contents of the GUI element by Value.GetValue(). Modified: branches/uf_redesign/gui/wizard_elements.py Modified: branches/uf_redesign/gui/wizard_elements.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/wizard_elements.py?rev=16020&r1=16019&r2=16020&view=diff ============================================================================== --- branches/uf_redesign/gui/wizard_elements.py (original) +++ branches/uf_redesign/gui/wizard_elements.py Sun May 6 17:44:31 2012 @@ -35,6 +35,7 @@ # relax GUI module imports. from gui.components.combo_list import Combo_list +from gui.errors import gui_raise from gui.filedialog import RelaxFileDialog from gui.fonts import font 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 @@ -1062,12 +1063,15 @@ if value_type == 'float': self.convert_from_gui = gui_to_float self.convert_to_gui = float_to_gui + self.type_string = 'float' elif value_type == 'int': self.convert_from_gui = gui_to_int self.convert_to_gui = int_to_gui + self.type_string = 'integer' elif value_type == 'str': self.convert_from_gui = gui_to_str self.convert_to_gui = str_to_gui + self.type_string = 'string' else: raise RelaxError("Unknown value type '%s'." % value_type) @@ -1161,7 +1165,19 @@ # Convert and return the value from a TextCtrl. if self.element_type == 'text': - return self.convert_from_gui(self._field.GetValue()) + # The value. + value = self._field.GetValue() + + # Convert. + try: + value = self.convert_from_gui(value) + + # Raise a clear error for user feedback. + except: + gui_raise(RelaxError("The value '%s' is not of the Python %s type." % (value, self.type_string))) + return None + + return value # Convert and return the value from a ComboBox. if self.element_type == 'combo':