Fix display of string variables value in debug
authorLaurent Bessard
Thu, 08 Nov 2012 18:23:32 +0100
changeset 878 37256069baed
parent 877 7e695249be8d
child 879 55b8a16ead2b
Fix display of string variables value in debug
controls/DebugVariablePanel.py
dialogs/ForceVariableDialog.py
graphics/GraphicCommons.py
--- a/controls/DebugVariablePanel.py	Mon Nov 05 20:16:45 2012 +0100
+++ b/controls/DebugVariablePanel.py	Thu Nov 08 18:23:32 2012 +0100
@@ -69,6 +69,11 @@
             self.Parent.HasNewData = True
             
     def GetValue(self):
+        variable_type = self.Parent.GetDataType(self.Variable.upper())
+        if variable_type == "STRING":
+            return "'%s'" % self.Value
+        elif variable_type == "WSTRING":
+            return "\"%s\"" % self.Value
         return self.Value
 
 class DebugVariableTable(CustomTable):
--- a/dialogs/ForceVariableDialog.py	Mon Nov 05 20:16:45 2012 +0100
+++ b/dialogs/ForceVariableDialog.py	Thu Nov 08 18:23:32 2012 +0100
@@ -44,19 +44,29 @@
             return None
     return get_function
 
+def gen_get_string(delimiter):
+    STRING_MODEL = re.compile("%(delimiter)s([^%(delimiter)s]*)%(delimiter)s$" % {"delimiter": delimiter})
+    def get_string(v):
+        result = STRING_MODEL.match(v)
+        if result is not None:
+            return result.group(1)
+        return None
+    return get_string
+
 getinteger = gen_get_function(int)
 getfloat = gen_get_function(float)
-getstring = gen_get_function(str)
+getstring = gen_get_string("'")
+getwstring = gen_get_string('"')
 
 SECOND = 1000000
 MINUTE = 60 * SECOND
 HOUR = 60 * MINUTE
 DAY = 24 * HOUR
 
-IEC_TIME_MODEL = re.compile("(?:(?:T|TIME)#)?(-)?(?:(%(float)s)D_?)?(?:(%(float)s)H_?)?(?:(%(float)s)M(?!S)_?)?(?:(%(float)s)S_?)?(?:(%(float)s)MS)?" % {"float": "[0-9]+(?:\.[0-9]+)?"})
-IEC_DATE_MODEL = re.compile("(?:(?:D|DATE)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})")
-IEC_DATETIME_MODEL = re.compile("(?:(?:DT|DATE_AND_TIME)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})-([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)")
-IEC_TIMEOFDAY_MODEL = re.compile("(?:(?:TOD|TIME_OF_DAY)#)?([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)")
+IEC_TIME_MODEL = re.compile("(?:(?:T|TIME)#)?(-)?(?:(%(float)s)D_?)?(?:(%(float)s)H_?)?(?:(%(float)s)M(?!S)_?)?(?:(%(float)s)S_?)?(?:(%(float)s)MS)?$" % {"float": "[0-9]+(?:\.[0-9]+)?"})
+IEC_DATE_MODEL = re.compile("(?:(?:D|DATE)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})$")
+IEC_DATETIME_MODEL = re.compile("(?:(?:DT|DATE_AND_TIME)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})-([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$")
+IEC_TIMEOFDAY_MODEL = re.compile("(?:(?:TOD|TIME_OF_DAY)#)?([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$")
 
 def gettime(v):    
     result = IEC_TIME_MODEL.match(v.upper())
@@ -136,7 +146,7 @@
                 "REAL": getfloat,
                 "LREAL": getfloat,
                 "STRING": getstring,
-                "WSTRING": getstring,
+                "WSTRING": getwstring,
                 "TIME": gettime,
                 "DATE": getdate,
                 "DT": getdatetime,
--- a/graphics/GraphicCommons.py	Mon Nov 05 20:16:45 2012 +0100
+++ b/graphics/GraphicCommons.py	Thu Nov 08 18:23:32 2012 +0100
@@ -1964,7 +1964,10 @@
     
     def GetToolTipValue(self):
         if self.Value is not None and self.Value != "undefined" and not isinstance(self.Value, BooleanType):
-            if isinstance(self.Value, StringType) and self.Value.find("#") == -1:
+            wire_type = self.GetEndConnectedType()
+            if wire_type == "STRING":
+                return "'%s'"%self.Value
+            elif wire_type == "WSTRING":
                 return "\"%s\""%self.Value
             else:
                 return str(self.Value)
@@ -2131,7 +2134,10 @@
         if self.Value != value:
             self.Value = value
             if value is not None and not isinstance(value, BooleanType):
-                if isinstance(value, StringType) and value.find('#') == -1:
+                wire_type = self.GetEndConnectedType()
+                if wire_type == "STRING":
+                    self.ComputedValue = "'%s'"%value
+                elif wire_type == "WSTRING":
                     self.ComputedValue = "\"%s\""%value
                 else:
                     self.ComputedValue = str(value)