Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
authorlaurent
Wed, 25 Jan 2012 01:26:29 +0100
changeset 632 3ea55a5db68e
parent 631 e4dd5bf1f1db
child 633 3536f4469cde
Adding support for choosing graph range in duration instead of tick number when Common_Ticktime is available
GraphicViewer.py
--- a/GraphicViewer.py	Tue Jan 24 21:43:29 2012 +0100
+++ b/GraphicViewer.py	Wed Jan 25 01:26:29 2012 +0100
@@ -36,8 +36,14 @@
 #                       Debug Variable Graphic Viewer class
 #-------------------------------------------------------------------------------
 
-
-RANGE_VALUES = [str(25 * 2 ** i) for i in xrange(6)]
+SECOND = 1000000000
+MINUTE = 60 * SECOND
+HOUR = 60 * MINUTE
+
+RANGE_VALUES = [(str(25 * 2 ** i), 25 * 2 ** i) for i in xrange(6)]
+TIME_RANGE_VALUES = [("%ds" % i, i * SECOND) for i in (10, 20, 30)] + \
+                    [("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
+                    [("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
 
 [ID_GRAPHICVIEWER, ID_GRAPHICVIEWERCANVAS,
  ID_GRAPHICVIEWERCANVASRANGE, ID_GRAPHICVIEWERCANVASPOSITION,
@@ -108,8 +114,7 @@
         
         self.CanvasRange = wx.ComboBox(id=ID_GRAPHICVIEWERCANVASRANGE,
               name='CanvasRange', parent=self.Editor, pos=wx.Point(0, 0),
-              size=wx.Size(100, 28), choices=RANGE_VALUES, style=0)
-        self.CanvasRange.SetStringSelection("25")
+              size=wx.Size(100, 28), style=0)
         self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
         self.Bind(wx.EVT_TEXT_ENTER, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
         
@@ -149,10 +154,12 @@
         DebugViewer.__init__(self, producer, True, False)
         
         self.InstancePath = instancepath
-
+        self.RangeValues = None
+        
         self.Datas = []
         self.CurrentValue = 0
-        self.CurrentRange = 25
+        self.Ticktime = self.DataProducer.GetTicktime()
+        self.RefreshCanvasRange()
         
         self.AddDataConsumer(self.InstancePath.upper(), self)
     
@@ -168,12 +175,32 @@
     def ResetView(self):
         self.Datas = []
         self.CurrentValue = 0
+        self.Ticktime = self.DataProducer.GetTicktime()
+        self.RefreshCanvasRange()
         self.RefreshView()
     
     def RefreshNewData(self):
         self.RefreshView(False)
         DebugViewer.RefreshNewData(self)
     
+    def RefreshCanvasRange(self):
+        if self.Ticktime == 0 and self.RangeValues != RANGE_VALUES:
+            self.RangeValues = RANGE_VALUES
+            self.RangeValues_dict = dict(RANGE_VALUES)
+            self.CanvasRange.Clear()
+            for text, value in RANGE_VALUES:
+                self.CanvasRange.Append(text)
+            self.CanvasRange.SetStringSelection(RANGE_VALUES[0][0])
+            self.CurrentRange = RANGE_VALUES[0][1]
+        elif self.RangeValues != TIME_RANGE_VALUES:
+            self.RangeValues = TIME_RANGE_VALUES
+            self.RangeValues_dict = dict(TIME_RANGE_VALUES)
+            self.CanvasRange.Clear()
+            for text, value in TIME_RANGE_VALUES:
+                self.CanvasRange.Append(text)
+            self.CanvasRange.SetStringSelection(TIME_RANGE_VALUES[0][0])
+            self.CurrentRange = TIME_RANGE_VALUES[0][1] / self.Ticktime
+        
     def RefreshView(self, force=True):
         self.Freeze()
         if force or self.CurrentValue + self.CurrentRange == len(self.Datas) or self.CurrentValue + len(self.Datas) < self.CurrentRange:
@@ -214,7 +241,10 @@
     def OnRangeChanged(self, event):
         old_range = self.CurrentRange
         try:
-            self.CurrentRange = int(self.CanvasRange.GetValue())
+            if self.Ticktime == 0:
+                self.CurrentRange = self.RangeValues_dict[self.CanvasRange.GetValue()]
+            else:
+                self.CurrentRange = self.RangeValues_dict[self.CanvasRange.GetValue()] / self.Ticktime
         except ValueError, e:
             self.CanvasRange.SetValue(str(self.CurrentRange))
         self.CurrentValue = max(0, min(self.CurrentValue + old_range - self.CurrentRange,