Author: bugman Date: Fri Sep 16 14:45:54 2011 New Revision: 14666 URL: http://svn.gna.org/viewcvs/relax?rev=14666&view=rev Log: Alphabetical ordering of the functions in the gui.misc module. Modified: 1.3/gui/misc.py Modified: 1.3/gui/misc.py URL: http://svn.gna.org/viewcvs/relax/1.3/gui/misc.py?rev=14666&r1=14665&r2=14666&view=diff ============================================================================== --- 1.3/gui/misc.py (original) +++ 1.3/gui/misc.py Fri Sep 16 14:45:54 2011 @@ -155,121 +155,6 @@ return result -def gui_to_float(string): - """Convert the GUI obtained string to an float. - - @param string: The number in string form. - @type string: str or unicode - @return: The float - @rtype: float or None - """ - - # No input. - if string in ['', u'']: - return None - - # Already a float. - if type(string) == float: - return string - - # Convert. - val = eval(string) - - # An int. - if type(val) == int: - val = float(val) - - # Not a float! - if type(val) != float: - return string - - # A float. - return val - - -def gui_to_int(string): - """Convert the GUI obtained string to an int. - - @param string: The number in string form. - @type string: str or unicode - @return: The integer - @rtype: int or None - """ - - # No input. - if string in ['', u'']: - return None - - # Already an int. - if type(string) == int: - return string - - # Convert. - val = eval(string) - - # Not an int! - if type(val) != int: - return string - - # An int. - return val - - -def gui_to_int_or_list(string): - """Convert the GUI obtained string to a list. - - @param string: The list in string form. - @type string: str or unicode - @return: The integer or list of integers. - @rtype: int or int list - """ - - # No value. - if string in ['', u'']: - return None - - # Already an int or list. - if type(string) == int or type(string) == list: - return string - - # Convert. - try: - val = eval(string) - - # Failure, so return the original value. - except NameError: - return string - - - # Return the list. - return val - - -def gui_to_str_or_list(string): - """Convert the GUI obtained string to a list. - - @param string: The list in string form. - @type string: str or unicode - @return: The integer or list of integers. - @rtype: int or int list - """ - - # No value. - if string in ['', u'']: - return None - - # Try converting to a list. - try: - val = eval(string) - - # Failure, so return the original value. - except NameError: - return string - - # Return the list. - return val - - def float_to_gui(num): """Convert the float into the GUI string. @@ -287,6 +172,177 @@ return unicode(num) +def gui_to_bool(string): + """Convert the GUI obtained string to a bool. + + @param string: The bool in string form. + @type string: str or unicode + @return: The bool. + @rtype: bool + """ + + # No value. + if string in ['', u'']: + return None + + # Convert. + return eval(string) + + +def gui_to_float(string): + """Convert the GUI obtained string to an float. + + @param string: The number in string form. + @type string: str or unicode + @return: The float + @rtype: float or None + """ + + # No input. + if string in ['', u'']: + return None + + # Already a float. + if type(string) == float: + return string + + # Convert. + val = eval(string) + + # An int. + if type(val) == int: + val = float(val) + + # Not a float! + if type(val) != float: + return string + + # A float. + return val + + +def gui_to_int(string): + """Convert the GUI obtained string to an int. + + @param string: The number in string form. + @type string: str or unicode + @return: The integer + @rtype: int or None + """ + + # No input. + if string in ['', u'']: + return None + + # Already an int. + if type(string) == int: + return string + + # Convert. + val = eval(string) + + # Not an int! + if type(val) != int: + return string + + # An int. + return val + + +def gui_to_int_or_list(string): + """Convert the GUI obtained string to a list. + + @param string: The list in string form. + @type string: str or unicode + @return: The integer or list of integers. + @rtype: int or int list + """ + + # No value. + if string in ['', u'']: + return None + + # Already an int or list. + if type(string) == int or type(string) == list: + return string + + # Convert. + try: + val = eval(string) + + # Failure, so return the original value. + except NameError: + return string + + + # Return the list. + return val + + +def gui_to_list(string): + """Convert the GUI obtained string to a list. + + @param string: The list in string form. + @type string: str or unicode + @return: The list. + @rtype: list + """ + + # No value. + if string in ['', u'']: + return [] + + # Convert. + val = eval(string) + if type(val) != list: + val = [val] + + # Return the list. + return val + + +def gui_to_str(string): + """Convert the GUI obtained string to a string. + + @param string: The number in string form. + @type string: str or unicode + @return: The string. + @rtype: str + """ + + # No value. + if string in ['', u'']: + return None + + # Convert. + return str(string) + + +def gui_to_str_or_list(string): + """Convert the GUI obtained string to a list. + + @param string: The list in string form. + @type string: str or unicode + @return: The integer or list of integers. + @rtype: int or int list + """ + + # No value. + if string in ['', u'']: + return None + + # Try converting to a list. + try: + val = eval(string) + + # Failure, so return the original value. + except NameError: + return string + + # Return the list. + return val + + def int_to_gui(num): """Convert the int into the GUI string. @@ -302,62 +358,6 @@ # Convert. return unicode(num) - - -def gui_to_bool(string): - """Convert the GUI obtained string to a bool. - - @param string: The bool in string form. - @type string: str or unicode - @return: The bool. - @rtype: bool - """ - - # No value. - if string in ['', u'']: - return None - - # Convert. - return eval(string) - - -def gui_to_list(string): - """Convert the GUI obtained string to a list. - - @param string: The list in string form. - @type string: str or unicode - @return: The list. - @rtype: list - """ - - # No value. - if string in ['', u'']: - return [] - - # Convert. - val = eval(string) - if type(val) != list: - val = [val] - - # Return the list. - return val - - -def gui_to_str(string): - """Convert the GUI obtained string to a string. - - @param string: The number in string form. - @type string: str or unicode - @return: The string. - @rtype: str - """ - - # No value. - if string in ['', u'']: - return None - - # Convert. - return str(string) def list_to_gui(list):