mailr16368 - /branches/uf_redesign/gui/string_conv.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on May 22, 2012 - 10:52:
Author: bugman
Date: Tue May 22 10:52:01 2012
New Revision: 16368

URL: http://svn.gna.org/viewcvs/relax?rev=16368&view=rev
Log:
Created a pair of Python object to GUI string and reverse conversion 
functions.


Modified:
    branches/uf_redesign/gui/string_conv.py

Modified: branches/uf_redesign/gui/string_conv.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/string_conv.py?rev=16368&r1=16367&r2=16368&view=diff
==============================================================================
--- branches/uf_redesign/gui/string_conv.py (original)
+++ branches/uf_redesign/gui/string_conv.py Tue May 22 10:52:01 2012
@@ -219,6 +219,31 @@
 
     # Return the list.
     return val
+
+
+def gui_to_py(string):
+    """Super function for converting the GUI string to a Python object.
+
+    @param string:  The Python object in string form.
+    @type string:   str or unicode
+    @return:        The value.
+    @rtype:         python object
+    """
+
+    # No value.
+    if string in ['', u'', None]:
+        return None
+
+    # Use an eval call to create a standard object.
+    try:
+        value = eval(string)
+
+    # A string or sequence of strings.
+    except NameError:
+        value = str(string)
+
+    # Return the python type.
+    return value
 
 
 def gui_to_str(string):
@@ -334,6 +359,23 @@
     return value
 
 
+def py_to_gui(value):
+    """Super function for converting a Python object to a GUI string.
+
+    @param string:  The value.
+    @type string:   anything
+    @return:        The Python object in GUI string form.
+    @rtype:         unicode
+    """
+
+    # No input.
+    if string == None:
+        string = ''
+
+    # Return the unicode version of the string.
+    return unicode(string)
+
+
 def str_to_gui(string):
     """Convert the string into the GUI string.
 




Related Messages


Powered by MHonArc, Updated Tue May 22 11:00:02 2012