Adding support for using middle button for moving debug graph
authorLaurent Bessard
Fri, 13 Jul 2012 12:42:02 +0200
changeset 724 57b6446d54f8
parent 723 5df934c273e1
child 725 7c44fc339889
Adding support for using middle button for moving debug graph
Adding button for resetting zoom and of position of debug graph
GraphicViewer.py
Images/fit.png
Images/icons.svg
--- a/GraphicViewer.py	Fri Jul 13 12:27:05 2012 +0200
+++ b/GraphicViewer.py	Fri Jul 13 12:42:02 2012 +0200
@@ -75,12 +75,14 @@
         self.Canvas.SetYSpec('border')
         self.Canvas.canvas.Bind(wx.EVT_LEFT_DOWN, self.OnCanvasLeftDown)
         self.Canvas.canvas.Bind(wx.EVT_LEFT_UP, self.OnCanvasLeftUp)
+        self.Canvas.canvas.Bind(wx.EVT_MIDDLE_DOWN, self.OnCanvasMiddleDown)
+        self.Canvas.canvas.Bind(wx.EVT_MIDDLE_UP, self.OnCanvasMiddleUp)
         self.Canvas.canvas.Bind(wx.EVT_MOTION, self.OnCanvasMotion)
         self.Canvas.canvas.Bind(wx.EVT_MOUSEWHEEL, self.OnCanvasMouseWheel)
         self.Canvas.canvas.Bind(wx.EVT_SIZE, self.OnCanvasResize)
         main_sizer.AddWindow(self.Canvas, 0, border=0, flag=wx.GROW)
         
-        range_sizer = wx.FlexGridSizer(cols=9, hgap=5, rows=1, vgap=0)
+        range_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=0)
         range_sizer.AddGrowableCol(5)
         range_sizer.AddGrowableRow(0)
         main_sizer.AddSizer(range_sizer, 0, border=5, flag=wx.GROW|wx.ALL)
@@ -131,6 +133,13 @@
         self.Bind(wx.EVT_BUTTON, self.OnCurrentButton, self.CurrentButton)
         range_sizer.AddWindow(self.CurrentButton, 0, border=0, flag=0)
         
+        self.ResetZoomOffsetButton = wx.lib.buttons.GenBitmapButton(self.Editor, 
+              bitmap=GetBitmap("fit"), size=wx.Size(28, 28), style=wx.NO_BORDER)
+        self.CurrentButton.SetToolTipString(_("Reset zoom and offset"))
+        self.Bind(wx.EVT_BUTTON, self.OnResetZoomOffsetButton, 
+              self.ResetZoomOffsetButton)
+        range_sizer.AddWindow(self.ResetZoomOffsetButton, 0, border=0, flag=0)
+        
         self.ExportGraphButton = wx.lib.buttons.GenBitmapButton(self.Editor, 
               bitmap=GetBitmap("export_graph"), size=wx.Size(28, 28), style=wx.NO_BORDER)
         self.ExportGraphButton.SetToolTipString(_("Export graph values to clipboard"))
@@ -162,7 +171,7 @@
         self.MinValue = None
         self.MaxValue = None
         self.YCenter = 0
-        self.CurrentZoom = 1
+        self.CurrentZoom = 1.0
         self.Fixed = False
         self.Ticktime = self.DataProducer.GetTicktime()
         self.RefreshCanvasRange()
@@ -285,7 +294,8 @@
         return self.InstancePath == tagname
     
     def NewValue(self, tick, value, forced=False):
-        self.Datas.append((float(tick), {True:1., False:0.}.get(value, float(value))))
+        value = {True:1., False:0.}.get(value, float(value))
+        self.Datas.append((float(tick), value))
         if self.MinValue is None:
             self.MinValue = value
         else:
@@ -340,10 +350,11 @@
         event.Skip()
     
     def OnPositionChanging(self, event):
-        self.ResetBounds()
-        self.StartTick = self.Datas[0][0] + event.GetPosition()
-        self.Fixed = True
-        self.NewDataAvailable(True)
+        if len(self.Datas) > 0:
+            self.ResetBounds()
+            self.StartTick = self.Datas[0][0] + event.GetPosition()
+            self.Fixed = True
+            self.NewDataAvailable(True)
         event.Skip()
 
     def OnResetButton(self, event):
@@ -352,10 +363,21 @@
         event.Skip()
 
     def OnCurrentButton(self, event):
-        self.ResetBounds()
-        self.StartTick = max(self.Datas[0][0], self.Datas[-1][0] - self.CurrentRange)
-        self.Fixed = False
-        self.NewDataAvailable(True)
+        if len(self.Datas) > 0:
+            self.ResetBounds()
+            self.StartTick = max(self.Datas[0][0], self.Datas[-1][0] - self.CurrentRange)
+            self.Fixed = False
+            self.NewDataAvailable(True)
+        event.Skip()
+    
+    def OnResetZoomOffsetButton(self, event):
+        if len(self.Datas) > 0:
+            self.YCenter = (self.MaxValue + self.MinValue) / 2
+        else:
+            self.YCenter = 0.0
+        self.CurrentZoom = 1.0
+        self.CanvasZoom.SetSelection(0)
+        wx.CallAfter(self.RefreshView, True)
         event.Skip()
     
     def OnExportGraphButtonClick(self, event):
@@ -380,7 +402,7 @@
                 self.CurrentMousePos = event.GetPosition()
                 self.CurrentMotionValue = self.Datas[self.StartIdx][0]
         event.Skip()
-        
+    
     def OnCanvasLeftUp(self, event):
         self.Dragging = False
         if self.Mode == MODE_MOTION:
@@ -389,6 +411,22 @@
         if self.Canvas.canvas.HasCapture():
             self.Canvas.canvas.ReleaseMouse()
         event.Skip()
+    
+    def OnCanvasMiddleDown(self, event):
+        self.Fixed = True
+        self.Canvas.canvas.CaptureMouse()
+        if len(self.Datas) > 0:
+            self.GetBounds()
+            self.CurrentMousePos = event.GetPosition()
+            self.CurrentMotionValue = self.Datas[self.StartIdx][0]
+        event.Skip()
+        
+    def OnCanvasMiddleUp(self, event):
+        self.CurrentMousePos = None
+        self.CurrentMotionValue = None
+        if self.Canvas.canvas.HasCapture():
+            self.Canvas.canvas.ReleaseMouse()
+        event.Skip()
         
     def OnCanvasMotion(self, event):
         if self.Mode == MODE_SELECTION and self.Dragging:
Binary file Images/fit.png has changed
--- a/Images/icons.svg	Fri Jul 13 12:27:05 2012 +0200
+++ b/Images/icons.svg	Fri Jul 13 12:42:02 2012 +0200
@@ -8942,6 +8942,207 @@
          style="stop-color:#acbbff;stop-opacity:0"
          id="stop2194-4" />
     </linearGradient>
+    <linearGradient
+       id="linearGradient5533"
+       y2="609.51001"
+       gradientUnits="userSpaceOnUse"
+       x2="302.85999"
+       gradientTransform="matrix(0.031048,0,0,0.013668,0.77854,15.669)"
+       y1="366.64999"
+       x1="302.85999">
+      <stop
+         id="stop5050-7"
+         style="stop-opacity:0"
+         offset="0" />
+      <stop
+         id="stop5056-19"
+         offset=".5" />
+      <stop
+         id="stop5052-4"
+         style="stop-opacity:0"
+         offset="1" />
+    </linearGradient>
+    <radialGradient
+       id="radialGradient5535"
+       xlink:href="#linearGradient5060-1"
+       gradientUnits="userSpaceOnUse"
+       cy="486.64999"
+       cx="605.71002"
+       gradientTransform="matrix(0.031048,0,0,0.013668,0.78465,15.669)"
+       r="117.14" />
+    <linearGradient
+       id="linearGradient5060-1">
+      <stop
+         id="stop5062-7"
+         offset="0" />
+      <stop
+         id="stop5064-9"
+         style="stop-opacity:0"
+         offset="1" />
+    </linearGradient>
+    <radialGradient
+       id="radialGradient5537"
+       xlink:href="#linearGradient5060-1"
+       gradientUnits="userSpaceOnUse"
+       cy="486.64999"
+       cx="605.71002"
+       gradientTransform="matrix(-0.031048,0,0,0.013668,23.215,15.669)"
+       r="117.14" />
+    <linearGradient
+       id="linearGradient3043">
+      <stop
+         id="stop3045-0"
+         offset="0" />
+      <stop
+         id="stop3047"
+         style="stop-opacity:0"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient5565"
+       y2="39.924"
+       gradientUnits="userSpaceOnUse"
+       x2="21.780001"
+       gradientTransform="matrix(0.63636,0,0,0.62295,-3.9091,-3.1066)"
+       y1="8.5762997"
+       x1="21.865999">
+      <stop
+         id="stop2783"
+         style="stop-color:#505050"
+         offset="0" />
+      <stop
+         id="stop6301"
+         style="stop-color:#6e6e6e"
+         offset=".13216" />
+      <stop
+         id="stop2785"
+         style="stop-color:#8c8c8c"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient5562-5"
+       y2="15.044"
+       gradientUnits="userSpaceOnUse"
+       x2="16.075001"
+       gradientTransform="matrix(0.61291,0,0,0.58621,-3.3226,-2.069)"
+       y1="9.0734997"
+       x1="16.034">
+      <stop
+         id="stop3692"
+         style="stop-color:#fff"
+         offset="0" />
+      <stop
+         id="stop3694"
+         style="stop-color:#fff;stop-opacity:.46875"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient5559"
+       y2="40"
+       gradientUnits="userSpaceOnUse"
+       x2="24"
+       gradientTransform="matrix(0.52632,0,0,0.48148,-0.63158,1.7407)"
+       y1="13"
+       x1="24">
+      <stop
+         id="stop6459"
+         style="stop-color:#fff;stop-opacity:.94118"
+         offset="0" />
+      <stop
+         id="stop6461"
+         style="stop-color:#fff;stop-opacity:.70588"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient6639"
+       y2="22.839001"
+       xlink:href="#linearGradient6388"
+       gradientUnits="userSpaceOnUse"
+       x2="33.25"
+       gradientTransform="matrix(0,1,-1,0,25.121,-26.636)"
+       y1="16.121"
+       x1="39.879002" />
+    <linearGradient
+       id="linearGradient6388">
+      <stop
+         id="stop6390"
+         style="stop-color:#73a300"
+         offset="0" />
+      <stop
+         id="stop6392"
+         style="stop-color:#428300;stop-opacity:0"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient6643"
+       y2="22.839001"
+       xlink:href="#linearGradient6388"
+       gradientUnits="userSpaceOnUse"
+       x2="33.25"
+       gradientTransform="matrix(0,-1,-1,0,25.121,55.879)"
+       y1="16.121"
+       x1="39.879002" />
+    <linearGradient
+       id="linearGradient3064-1">
+      <stop
+         id="stop3066"
+         style="stop-color:#73a300"
+         offset="0" />
+      <stop
+         id="stop3068"
+         style="stop-color:#428300;stop-opacity:0"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient6647"
+       y2="22.839001"
+       xlink:href="#linearGradient6388"
+       gradientUnits="userSpaceOnUse"
+       x2="33.25"
+       gradientTransform="matrix(0,1,1,0,-1.1213,-26.879)"
+       y1="16.121"
+       x1="39.879002" />
+    <linearGradient
+       id="linearGradient3071">
+      <stop
+         id="stop3073"
+         style="stop-color:#73a300"
+         offset="0" />
+      <stop
+         id="stop3075"
+         style="stop-color:#428300;stop-opacity:0"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient6651"
+       y2="22.839001"
+       xlink:href="#linearGradient6388"
+       gradientUnits="userSpaceOnUse"
+       x2="33.25"
+       gradientTransform="matrix(0,-1,1,0,-1.1213,55.879)"
+       y1="16.121"
+       x1="39.879002" />
+    <linearGradient
+       id="linearGradient3078">
+      <stop
+         id="stop3080"
+         style="stop-color:#73a300"
+         offset="0" />
+      <stop
+         id="stop3082"
+         style="stop-color:#428300;stop-opacity:0"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       y2="22.839001"
+       x2="33.25"
+       y1="16.121"
+       x1="39.879002"
+       gradientTransform="matrix(0,-1,1,0,-1.1213,55.879)"
+       gradientUnits="userSpaceOnUse"
+       id="linearGradient3099-5"
+       xlink:href="#linearGradient6388"
+       inkscape:collect="always" />
   </defs>
   <sodipodi:namedview
      id="base"
@@ -8951,8 +9152,8 @@
      inkscape:pageopacity="0"
      inkscape:pageshadow="2"
      inkscape:zoom="7.9999996"
-     inkscape:cx="-132.22424"
-     inkscape:cy="-178.90149"
+     inkscape:cx="-9.9597451"
+     inkscape:cy="-165.16747"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      width="16px"
@@ -13334,5 +13535,110 @@
          d="m 101.87045,376.48331 c 15.88269,-21.97532 15.54068,-22.2933 15.54068,-22.2933 l 11.1987,-2.03784 15.62825,-9.76202 8.0733,23.90355 11.92414,-15.63516 6.6307,13.14898"
          inkscape:connector-curvature="0" />
     </g>
+    <text
+       xml:space="preserve"
+       style="font-size:4.49727678px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;display:inline;font-family:Bitstream Vera Sans"
+       x="20.5"
+       y="177.11613"
+       id="text3638-3-3-2-0-9-8-5-5-9"><tspan
+         sodipodi:role="line"
+         id="tspan3640-1-8-0-6-8-4-3-9-0"
+         x="20.5"
+         y="177.11613">%%fit%%</tspan></text>
+    <rect
+       inkscape:label="#rect3636"
+       y="180.75"
+       x="19"
+       height="24"
+       width="24"
+       id="fit"
+       style="opacity:0;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
+    <g
+       transform="translate(18.875,180.375)"
+       id="g6918">
+      <g
+         id="g3217"
+         transform="matrix(1.0562,0,0,1.205,-0.67489,-5.921)">
+        <rect
+           id="rect4173-9"
+           style="opacity:0.23613;fill:url(#linearGradient5533)"
+           height="3.3194001"
+           width="14.992"
+           y="20.681"
+           x="4.5042" />
+        <path
+           inkscape:connector-curvature="0"
+           id="path5058-55"
+           style="opacity:0.23613;fill:url(#radialGradient5535)"
+           d="m 19.496,20.681 v 3.3192 c 1.5989,0.0062 3.8653,-0.74366 3.8653,-1.6598 0,-0.91615 -1.7842,-1.6594 -3.8653,-1.6594 z" />
+        <path
+           inkscape:connector-curvature="0"
+           id="path5018-3"
+           style="opacity:0.23613;fill:url(#radialGradient5537)"
+           d="m 4.5042,20.681 v 3.3192 c -1.5989,0.0062 -3.8653,-0.74366 -3.8653,-1.6598 0,-0.91615 1.7842,-1.6594 3.8653,-1.6594 z" />
+      </g>
+      <rect
+         id="rect1887"
+         style="fill:url(#linearGradient5565);stroke:#565853;stroke-width:0.99994999"
+         rx="1"
+         ry="1"
+         height="19"
+         width="21"
+         y="2.5"
+         x="1.5" />
+      <rect
+         id="rect2779"
+         style="opacity:0.2;fill:none;stroke:url(#linearGradient5562-5);stroke-width:0.99993998"
+         rx="0.5"
+         ry="0.5"
+         height="17"
+         width="19"
+         y="3.5"
+         x="2.5" />
+      <rect
+         id="rect6287"
+         style="fill:url(#linearGradient5559)"
+         rx="0.50016999"
+         ry="0.5"
+         height="13"
+         width="20"
+         y="8"
+         x="2" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path6293"
+         style="fill:#ffc24c"
+         d="m 21,5 c 0,0.5522 -0.448,1 -1,1 -0.552,0 -1,-0.4478 -1,-1 0,-0.5522 0.448,-1 1,-1 0.55245,0 1.0002,0.44779 1,1 z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path6622"
+         style="fill:#ffc24c"
+         d="m 18,5 c 2.38e-4,0.55221 -0.44755,1 -1,1 -0.55246,0 -1.0002,-0.44779 -1,-1 -2.41e-4,-0.55221 0.44754,-1 1,-1 0.55245,0 1.0002,0.44779 1,1 z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path6630"
+         style="fill:#ffc24c"
+         d="m 15,5 c 2.38e-4,0.55221 -0.44755,1 -1,1 -0.55246,0 -1.0002,-0.44779 -1,-1 -2.41e-4,-0.55221 0.44754,-1 1,-1 0.55245,0 1.0002,0.44779 1,1 z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="rect5590"
+         style="fill:url(#linearGradient6639)"
+         d="M 9,9 7.5858,10.414 6.1716,9 4.7574,10.414 6.1716,11.828 4.7574,13.243 H 9 V 9 z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path6641"
+         style="fill:url(#linearGradient6643)"
+         d="M 9,20.243 7.5858,18.828 6.1716,20.243 4.7574,18.828 6.1716,17.414 4.7574,16 H 9 v 4.243 z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path6645"
+         style="fill:url(#linearGradient6647)"
+         d="m 15,8.7574 1.4142,1.4142 1.4142,-1.4142 1.4142,1.4142 -1.4142,1.4142 1.415,1.414 h -4.243 V 8.7572 z" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path6649"
+         style="fill:url(#linearGradient3099-5)"
+         d="m 15,20.243 1.4142,-1.4142 1.4142,1.4142 1.4142,-1.4142 -1.414,-1.415 1.415,-1.414 h -4.243 v 4.2426 z" />
+    </g>
   </g>
 </svg>