graphics/GraphicCommons.py
changeset 525 e8d5ab0855d3
parent 519 722714c04dcd
child 529 cbfbd0f7135b
--- a/graphics/GraphicCommons.py	Tue Apr 05 19:01:51 2011 +0200
+++ b/graphics/GraphicCommons.py	Tue Apr 05 19:06:00 2011 +0200
@@ -26,6 +26,7 @@
 from time import time as gettime
 from math import *
 from types import *
+import datetime
 
 #-------------------------------------------------------------------------------
 #                               Common constants
@@ -198,7 +199,32 @@
     data += "%gms" % (microseconds % SECOND / 1000.)
     return data
 
-TYPE_TRANSLATOR = {"TIME": generate_time}
+def generate_date(value):
+    base_date = datetime.datetime(1970, 1, 1)
+    date = base_date + value 
+    return date.strftime("DATE#%Y-%m-%d")
+
+def generate_datetime(value):
+    base_date = datetime.datetime(1970, 1, 1)
+    date_time = base_date + value 
+    return date_time.strftime("DT#%Y-%m-%d-%H:%M:%S.%f")
+
+def generate_timeofday(value):
+    microseconds = float(value.days * DAY + value.seconds * SECOND + value.microseconds)
+    negative = microseconds < 0
+    microseconds = abs(microseconds)
+    data = "TOD#"
+    for val, format in [(int(microseconds) / HOUR, "%2.2d:"),
+                        ((int(microseconds) % HOUR) / MINUTE, "%2.2d:"),
+                        ((int(microseconds) % MINUTE) / SECOND, "%2.2d."),
+                        (microseconds % SECOND, "%6.6d")]:
+        data += format % val
+    return data
+
+TYPE_TRANSLATOR = {"TIME": generate_time,
+                   "DATE": generate_date,
+                   "DT": generate_datetime,
+                   "TOD": generate_timeofday}
 
 #-------------------------------------------------------------------------------
 #                            Debug Data Consumer Class
@@ -2596,31 +2622,27 @@
             connector = self.Parent.FindBlockConnector(new_pos, self.GetConnectionDirection())
             if connector:
                 if handle == 0 and self.EndConnected != connector:
-                    if connector.IsCompatible(self.GetEndConnectedType()):
-                        connector.HighlightParentBlock(True)
-                        connector.Connect((self, handle))
-                        self.SetStartPointDirection(connector.GetDirection())
-                        self.ConnectStartPoint(connector.GetPosition(), connector)
-                        pos = connector.GetPosition()
-                        movex = pos.x - self.oldPos.x
-                        movey = pos.y - self.oldPos.y
-                        self.Dragging = False
-                    else:
+                    connector.HighlightParentBlock(True)
+                    connector.Connect((self, handle))
+                    self.SetStartPointDirection(connector.GetDirection())
+                    self.ConnectStartPoint(connector.GetPosition(), connector)
+                    pos = connector.GetPosition()
+                    movex = pos.x - self.oldPos.x
+                    movey = pos.y - self.oldPos.y
+                    if not connector.IsCompatible(self.GetEndConnectedType()):
                         self.SetValid(False)
-                        self.MoveStartPoint(new_pos)
+                    self.Dragging = False
                 elif handle != 0 and self.StartConnected != connector:
-                    if connector.IsCompatible(self.GetStartConnectedType()):
-                        connector.HighlightParentBlock(True)
-                        connector.Connect((self, handle))
-                        self.SetEndPointDirection(connector.GetDirection())
-                        self.ConnectEndPoint(connector.GetPosition(), connector)
-                        pos = connector.GetPosition()
-                        movex = pos.x - self.oldPos.x
-                        movey = pos.y - self.oldPos.y
-                        self.Dragging = False
-                    else:
+                    connector.HighlightParentBlock(True)
+                    connector.Connect((self, handle))
+                    self.SetEndPointDirection(connector.GetDirection())
+                    self.ConnectEndPoint(connector.GetPosition(), connector)
+                    pos = connector.GetPosition()
+                    movex = pos.x - self.oldPos.x
+                    movey = pos.y - self.oldPos.y
+                    if not connector.IsCompatible(self.GetStartConnectedType()):
                         self.SetValid(False)
-                        self.MoveEndPoint(new_pos)
+                    self.Dragging = False
                 elif handle == 0:
                     self.MoveStartPoint(new_pos)
                 else: