controls/DebugVariablePanel/DebugVariableGraphicViewer.py
branchpython3
changeset 3750 f62625418bff
parent 3660 0e41dbe6ddcd
child 3752 9f6f46dbe3ae
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    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 
    27 from __future__ import division
    27 
    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
    42 from controls.DebugVariablePanel.DebugVariableViewer import *
    42 from controls.DebugVariablePanel.DebugVariableViewer import *
    43 from controls.DebugVariablePanel.GraphButton import GraphButton
    43 from controls.DebugVariablePanel.GraphButton import GraphButton
    44 
    44 
    45 
    45 
    46 # Graph variable display type
    46 # Graph variable display type
    47 GRAPH_PARALLEL, GRAPH_ORTHOGONAL = range(2)
    47 GRAPH_PARALLEL, GRAPH_ORTHOGONAL = list(range(2))
    48 
    48 
    49 # Canvas height
    49 # Canvas height
    50 [SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = [0, 100, 200]
    50 [SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = [0, 100, 200]
    51 
    51 
    52 CANVAS_BORDER = (30., 20.)  # Border height on at bottom and top of graph
    52 CANVAS_BORDER = (30., 20.)  # Border height on at bottom and top of graph
   565         Update Cursor position according to mouse position and graph type
   565         Update Cursor position according to mouse position and graph type
   566         @param event: Mouse event
   566         @param event: Mouse event
   567         """
   567         """
   568         start_tick, end_tick = self.ParentWindow.GetRange()
   568         start_tick, end_tick = self.ParentWindow.GetRange()
   569         cursor_tick = None
   569         cursor_tick = None
   570         items = self.ItemsDict.values()
   570         items = list(self.ItemsDict.values())
   571 
   571 
   572         # Graph is orthogonal
   572         # Graph is orthogonal
   573         if self.GraphType == GRAPH_ORTHOGONAL:
   573         if self.GraphType == GRAPH_ORTHOGONAL:
   574             # Extract items data displayed in canvas figure
   574             # Extract items data displayed in canvas figure
   575             start_tick = max(start_tick, self.GetItemsMinCommonTick())
   575             start_tick = max(start_tick, self.GetItemsMinCommonTick())
   639 
   639 
   640                 # Start a drag'n drop from mouse position in wx coordinate of
   640                 # Start a drag'n drop from mouse position in wx coordinate of
   641                 # parent
   641                 # parent
   642                 xw, yw = self.GetPosition()
   642                 xw, yw = self.GetPosition()
   643                 self.ParentWindow.StartDragNDrop(
   643                 self.ParentWindow.StartDragNDrop(
   644                     self, self.ItemsDict.values()[item_idx],
   644                     self, list(self.ItemsDict.values())[item_idx],
   645                     x + xw, y + yw,  # Current mouse position
   645                     x + xw, y + yw,  # Current mouse position
   646                     x + xw, y + yw)  # Mouse position when button was clicked
   646                     x + xw, y + yw)  # Mouse position when button was clicked
   647 
   647 
   648             # Don't handle mouse button if canvas is 3D and let matplotlib do
   648             # Don't handle mouse button if canvas is 3D and let matplotlib do
   649             # the default behavior (rotate 3D axes)
   649             # the default behavior (rotate 3D axes)
   677         """
   677         """
   678         # If a drag'n drop is in progress, stop it
   678         # If a drag'n drop is in progress, stop it
   679         if self.ParentWindow.IsDragging():
   679         if self.ParentWindow.IsDragging():
   680             _width, height = self.GetSize()
   680             _width, height = self.GetSize()
   681             xw, yw = self.GetPosition()
   681             xw, yw = self.GetPosition()
   682             item = self.ParentWindow.DraggingAxesPanel.ItemsDict.values()[0]
   682             item = list(self.ParentWindow.DraggingAxesPanel.ItemsDict.values())[0]
   683             # Give mouse position in wx coordinate of parent
   683             # Give mouse position in wx coordinate of parent
   684             self.ParentWindow.StopDragNDrop(item.GetVariable(),
   684             self.ParentWindow.StopDragNDrop(item.GetVariable(),
   685                                             xw + event.x, yw + height - event.y)
   685                                             xw + event.x, yw + height - event.y)
   686 
   686 
   687         else:
   687         else:
   744                     break
   744                     break
   745 
   745 
   746             # If mouse is over an item label,
   746             # If mouse is over an item label,
   747             if item_idx is not None:
   747             if item_idx is not None:
   748                 self.PopupContextualButtons(
   748                 self.PopupContextualButtons(
   749                     self.ItemsDict.values()[item_idx],
   749                     list(self.ItemsDict.values())[item_idx],
   750                     rect, menu_direction)
   750                     rect, menu_direction)
   751                 return
   751                 return
   752 
   752 
   753             # If mouse isn't over a contextual menu, hide the current shown one
   753             # If mouse isn't over a contextual menu, hide the current shown one
   754             # if it exists
   754             # if it exists
   782                 # there is only one item in Viewer, start a drag'n drop
   782                 # there is only one item in Viewer, start a drag'n drop
   783                 elif self.MouseStartPos is not None and len(self.Items) == 1:
   783                 elif self.MouseStartPos is not None and len(self.Items) == 1:
   784                     xw, yw = self.GetPosition()
   784                     xw, yw = self.GetPosition()
   785                     self.ParentWindow.SetCursorTick(self.StartCursorTick)
   785                     self.ParentWindow.SetCursorTick(self.StartCursorTick)
   786                     self.ParentWindow.StartDragNDrop(
   786                     self.ParentWindow.StartDragNDrop(
   787                         self, self.ItemsDict.values()[0],
   787                         self, list(self.ItemsDict.values())[0],
   788                         # Current mouse position
   788                         # Current mouse position
   789                         event.x + xw, height - event.y + yw,
   789                         event.x + xw, height - event.y + yw,
   790                         # Mouse position when button was clicked
   790                         # Mouse position when button was clicked
   791                         self.MouseStartPos.x + xw,
   791                         self.MouseStartPos.x + xw,
   792                         self.MouseStartPos.y + yw)
   792                         self.MouseStartPos.y + yw)
  1027         add_text_func = self.GetAddTextFunction()
  1027         add_text_func = self.GetAddTextFunction()
  1028 
  1028 
  1029         # Graph type is parallel or orthogonal in 3D
  1029         # Graph type is parallel or orthogonal in 3D
  1030         if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas():
  1030         if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas():
  1031             num_item = len(self.Items)
  1031             num_item = len(self.Items)
  1032             for idx in xrange(num_item):
  1032             for idx in range(num_item):
  1033 
  1033 
  1034                 # Get color from color cycle (black if only one item)
  1034                 # Get color from color cycle (black if only one item)
  1035                 color = ('k' if num_item == 1 else
  1035                 color = ('k' if num_item == 1 else
  1036                          COLOR_CYCLE[idx % len(COLOR_CYCLE)])
  1036                          COLOR_CYCLE[idx % len(COLOR_CYCLE)])
  1037 
  1037 
  1091             bottom=CANVAS_BORDER[0] * canvas_ratio)
  1091             bottom=CANVAS_BORDER[0] * canvas_ratio)
  1092 
  1092 
  1093         # Update position of items labels
  1093         # Update position of items labels
  1094         if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas():
  1094         if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas():
  1095             num_item = len(self.Items)
  1095             num_item = len(self.Items)
  1096             for idx in xrange(num_item):
  1096             for idx in range(num_item):
  1097 
  1097 
  1098                 # In 3D graph items variable label are not displayed
  1098                 # In 3D graph items variable label are not displayed
  1099                 if not self.Is3DCanvas():
  1099                 if not self.Is3DCanvas():
  1100                     # Items variable labels are in figure upper left corner
  1100                     # Items variable labels are in figure upper left corner
  1101                     self.AxesLabels[idx].set_position(
  1101                     self.AxesLabels[idx].set_position(
  1187             else:
  1187             else:
  1188                 # Update tick range, removing ticks that don't have a value for
  1188                 # Update tick range, removing ticks that don't have a value for
  1189                 # each variable
  1189                 # each variable
  1190                 start_tick = max(start_tick, self.GetItemsMinCommonTick())
  1190                 start_tick = max(start_tick, self.GetItemsMinCommonTick())
  1191                 end_tick = max(end_tick, start_tick)
  1191                 end_tick = max(end_tick, start_tick)
  1192                 items = self.ItemsDict.values()
  1192                 items = list(self.ItemsDict.values())
  1193 
  1193 
  1194                 # Get data and range for first variable (X coordinate)
  1194                 # Get data and range for first variable (X coordinate)
  1195                 x_data, x_min, x_max = items[0].GetDataAndValueRange(
  1195                 x_data, x_min, x_max = items[0].GetDataAndValueRange(
  1196                     start_tick, end_tick, not self.ZoomFit)
  1196                     start_tick, end_tick, not self.ZoomFit)
  1197 
  1197 
  1329         # or get value and flag of variable at cursor tick
  1329         # or get value and flag of variable at cursor tick
  1330         args = [(
  1330         args = [(
  1331             item.GetValue(self.CursorTick)
  1331             item.GetValue(self.CursorTick)
  1332             if self.CursorTick is not None
  1332             if self.CursorTick is not None
  1333             else (item.GetValue(), item.IsForced())) for item in self.Items]
  1333             else (item.GetValue(), item.IsForced())) for item in self.Items]
  1334         values, forced = zip(*args)
  1334         values, forced = list(zip(*args))
  1335 
  1335 
  1336         # Get path of each variable displayed simplified using panel variable
  1336         # Get path of each variable displayed simplified using panel variable
  1337         # name mask
  1337         # name mask
  1338         labels = [item.GetVariable(self.ParentWindow.GetVariableNameMask())
  1338         labels = [item.GetVariable(self.ParentWindow.GetVariableNameMask())
  1339                   for item in self.Items]
  1339                   for item in self.Items]
  1340 
  1340 
  1341         # Get style for each variable according to
  1341         # Get style for each variable according to
  1342         styles = map(lambda x: {True: 'italic', False: 'normal'}[x], forced)
  1342         styles = [{True: 'italic', False: 'normal'}[x] for x in forced]
  1343 
  1343 
  1344         # Graph is orthogonal 3D, set variables path as 3D axis label
  1344         # Graph is orthogonal 3D, set variables path as 3D axis label
  1345         if self.Is3DCanvas():
  1345         if self.Is3DCanvas():
  1346             for idx, label_func in enumerate([self.Axes.set_xlabel,
  1346             for idx, label_func in enumerate([self.Axes.set_xlabel,
  1347                                               self.Axes.set_ylabel,
  1347                                               self.Axes.set_ylabel,