controls/DebugVariablePanel/DebugVariableGraphicViewer.py
changeset 2459 21164625b393
parent 2450 5024c19ca8f0
child 3303 0ffb41625592
equal deleted inserted replaced
2458:2a70d5240300 2459:21164625b393
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    24 
    24 
    25 
    25 
    26 from __future__ import absolute_import
    26 from __future__ import absolute_import
    27 from types import TupleType
    27 from __future__ import division
    28 from time import time as gettime
    28 from time import time as gettime
    29 from cycler import cycler
    29 from cycler import cycler
    30 
    30 
    31 import numpy
    31 import numpy
    32 import wx
    32 import wx
    34 import matplotlib.pyplot
    34 import matplotlib.pyplot
    35 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
    35 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
    36 from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap
    36 from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap
    37 from matplotlib.backends.backend_agg import FigureCanvasAgg
    37 from matplotlib.backends.backend_agg import FigureCanvasAgg
    38 from mpl_toolkits.mplot3d import Axes3D
    38 from mpl_toolkits.mplot3d import Axes3D
       
    39 from six.moves import xrange
    39 
    40 
    40 from editors.DebugViewer import REFRESH_PERIOD
    41 from editors.DebugViewer import REFRESH_PERIOD
    41 from controls.DebugVariablePanel.DebugVariableViewer import *
    42 from controls.DebugVariablePanel.DebugVariableViewer import *
    42 from controls.DebugVariablePanel.GraphButton import GraphButton
    43 from controls.DebugVariablePanel.GraphButton import GraphButton
    43 
    44 
   154         message = None
   155         message = None
   155 
   156 
   156         # Check that data is valid regarding DebugVariablePanel
   157         # Check that data is valid regarding DebugVariablePanel
   157         try:
   158         try:
   158             values = eval(data)
   159             values = eval(data)
   159             if not isinstance(values, TupleType):
   160             if not isinstance(values, tuple):
   160                 raise ValueError
   161                 raise ValueError
   161         except Exception:
   162         except Exception:
   162             message = _("Invalid value \"%s\" for debug variable") % data
   163             message = _("Invalid value \"%s\" for debug variable") % data
   163             values = None
   164             values = None
   164 
   165 
   192             else:
   193             else:
   193                 _width, height = self.ParentControl.GetSize()
   194                 _width, height = self.ParentControl.GetSize()
   194 
   195 
   195                 # Get Before which Viewer the variable has to be moved or added
   196                 # Get Before which Viewer the variable has to be moved or added
   196                 # according to the position of mouse in Viewer.
   197                 # according to the position of mouse in Viewer.
   197                 if y > height / 2:
   198                 if y > height // 2:
   198                     target_idx += 1
   199                     target_idx += 1
   199 
   200 
   200                 # Drag'n Drop is an internal is an internal move inside Debug
   201                 # Drag'n Drop is an internal is an internal move inside Debug
   201                 # Variable Panel
   202                 # Variable Panel
   202                 if len(values) > 2 and values[2] == "move":
   203                 if len(values) > 2 and values[2] == "move":
   440             w, h = button.GetSize()
   441             w, h = button.GetSize()
   441             if direction in [wx.LEFT, wx.RIGHT]:
   442             if direction in [wx.LEFT, wx.RIGHT]:
   442                 x = rect.x + (- w - offset
   443                 x = rect.x + (- w - offset
   443                               if direction == wx.LEFT
   444                               if direction == wx.LEFT
   444                               else rect.width + offset)
   445                               else rect.width + offset)
   445                 y = rect.y + (rect.height - h) / 2
   446                 y = rect.y + (rect.height - h) // 2
   446                 offset += w
   447                 offset += w
   447             else:
   448             else:
   448                 x = rect.x + (rect.width - w) / 2
   449                 x = rect.x + (rect.width - w) // 2
   449                 y = rect.y + (- h - offset
   450                 y = rect.y + (- h - offset
   450                               if direction == wx.TOP
   451                               if direction == wx.TOP
   451                               else rect.height + offset)
   452                               else rect.height + offset)
   452                 offset += h
   453                 offset += h
   453             button.SetPosition(x, y)
   454             button.SetPosition(x, y)
   798 
   799 
   799                 # Move graph along X coordinate
   800                 # Move graph along X coordinate
   800                 self.ParentWindow.SetCanvasPosition(
   801                 self.ParentWindow.SetCanvasPosition(
   801                     self.StartCursorTick +
   802                     self.StartCursorTick +
   802                     (self.MouseStartPos.x - event.x) *
   803                     (self.MouseStartPos.x - event.x) *
   803                     (end_tick - start_tick) / rect.width)
   804                     (end_tick - start_tick) // rect.width)
   804 
   805 
   805     def OnCanvasScroll(self, event):
   806     def OnCanvasScroll(self, event):
   806         """
   807         """
   807         Function called when a wheel mouse is use in Viewer
   808         Function called when a wheel mouse is use in Viewer
   808         @param event: Mouse event
   809         @param event: Mouse event
   816             if self.GraphType == GRAPH_ORTHOGONAL:
   817             if self.GraphType == GRAPH_ORTHOGONAL:
   817                 start_tick, end_tick = self.ParentWindow.GetRange()
   818                 start_tick, end_tick = self.ParentWindow.GetRange()
   818                 tick = (start_tick + end_tick) / 2.
   819                 tick = (start_tick + end_tick) / 2.
   819             else:
   820             else:
   820                 tick = event.xdata
   821                 tick = event.xdata
   821             self.ParentWindow.ChangeRange(int(-event.step) / 3, tick)
   822             self.ParentWindow.ChangeRange(int(-event.step) // 3, tick)
   822 
   823 
   823             # Vetoing event to prevent parent panel to be scrolled
   824             # Vetoing event to prevent parent panel to be scrolled
   824             self.ParentWindow.VetoScrollEvent = True
   825             self.ParentWindow.VetoScrollEvent = True
   825 
   826 
   826     def OnLeftDClick(self, event):
   827     def OnLeftDClick(self, event):
   924         _width, height = self.GetSize()
   925         _width, height = self.GetSize()
   925 
   926 
   926         # Mouse is over Viewer figure and graph is not 3D
   927         # Mouse is over Viewer figure and graph is not 3D
   927         bbox = self.GetAxesBoundingBox()
   928         bbox = self.GetAxesBoundingBox()
   928         if bbox.InsideXY(x, y) and not self.Is3DCanvas():
   929         if bbox.InsideXY(x, y) and not self.Is3DCanvas():
   929             rect = wx.Rect(bbox.x, bbox.y, bbox.width / 2, bbox.height)
   930             rect = wx.Rect(bbox.x, bbox.y, bbox.width // 2, bbox.height)
   930             # Mouse is over Viewer left part of figure
   931             # Mouse is over Viewer left part of figure
   931             if rect.InsideXY(x, y):
   932             if rect.InsideXY(x, y):
   932                 self.SetHighlight(HIGHLIGHT_LEFT)
   933                 self.SetHighlight(HIGHLIGHT_LEFT)
   933 
   934 
   934             # Mouse is over Viewer right part of figure
   935             # Mouse is over Viewer right part of figure
   935             else:
   936             else:
   936                 self.SetHighlight(HIGHLIGHT_RIGHT)
   937                 self.SetHighlight(HIGHLIGHT_RIGHT)
   937 
   938 
   938         # Mouse is over upper part of Viewer
   939         # Mouse is over upper part of Viewer
   939         elif y < height / 2:
   940         elif y < height // 2:
   940             # Viewer is upper one in Debug Variable Panel, show highlight
   941             # Viewer is upper one in Debug Variable Panel, show highlight
   941             if self.ParentWindow.IsViewerFirst(self):
   942             if self.ParentWindow.IsViewerFirst(self):
   942                 self.SetHighlight(HIGHLIGHT_BEFORE)
   943                 self.SetHighlight(HIGHLIGHT_BEFORE)
   943 
   944 
   944             # Viewer is not the upper one, show highlight in previous one
   945             # Viewer is not the upper one, show highlight in previous one
  1322             self.Axes.set_ylim(y_min, y_max)
  1323             self.Axes.set_ylim(y_min, y_max)
  1323 
  1324 
  1324         # Get value and forced flag for each variable displayed in graph
  1325         # Get value and forced flag for each variable displayed in graph
  1325         # If cursor tick is not defined get value and flag of last received
  1326         # If cursor tick is not defined get value and flag of last received
  1326         # or get value and flag of variable at cursor tick
  1327         # or get value and flag of variable at cursor tick
  1327         values, forced = apply(zip, [(
  1328         args = [(
  1328             item.GetValue(self.CursorTick)
  1329             item.GetValue(self.CursorTick)
  1329             if self.CursorTick is not None
  1330             if self.CursorTick is not None
  1330             else (item.GetValue(), item.IsForced())
  1331             else (item.GetValue(), item.IsForced())) for item in self.Items]
  1331         ) for item in self.Items])
  1332         values, forced = zip(*args)
  1332 
  1333 
  1333         # Get path of each variable displayed simplified using panel variable
  1334         # Get path of each variable displayed simplified using panel variable
  1334         # name mask
  1335         # name mask
  1335         labels = [item.GetVariable(self.ParentWindow.GetVariableNameMask())
  1336         labels = [item.GetVariable(self.ParentWindow.GetVariableNameMask())
  1336                   for item in self.Items]
  1337                   for item in self.Items]
  1397         # rectangle on left or right part of figure depending on highlight type
  1398         # rectangle on left or right part of figure depending on highlight type
  1398         elif self.Highlight in [HIGHLIGHT_LEFT, HIGHLIGHT_RIGHT]:
  1399         elif self.Highlight in [HIGHLIGHT_LEFT, HIGHLIGHT_RIGHT]:
  1399             destGC.SetPen(HIGHLIGHT['DROP_PEN'])
  1400             destGC.SetPen(HIGHLIGHT['DROP_PEN'])
  1400             destGC.SetBrush(HIGHLIGHT['DROP_BRUSH'])
  1401             destGC.SetBrush(HIGHLIGHT['DROP_BRUSH'])
  1401 
  1402 
  1402             x_offset = (bbox.width / 2
  1403             x_offset = (bbox.width // 2
  1403                         if self.Highlight == HIGHLIGHT_RIGHT
  1404                         if self.Highlight == HIGHLIGHT_RIGHT
  1404                         else 0)
  1405                         else 0)
  1405             destGC.DrawRectangle(bbox.x + x_offset, bbox.y,
  1406             destGC.DrawRectangle(bbox.x + x_offset, bbox.y,
  1406                                  bbox.width / 2, bbox.height)
  1407                                  bbox.width // 2, bbox.height)
  1407 
  1408 
  1408         # Draw other Viewer common elements
  1409         # Draw other Viewer common elements
  1409         self.DrawCommonElements(destGC, self.GetButtons())
  1410         self.DrawCommonElements(destGC, self.GetButtons())
  1410 
  1411 
  1411         destGC.EndDrawing()
  1412         destGC.EndDrawing()