author | Laurent Bessard |
Thu, 06 Jun 2013 00:22:22 +0200 | |
changeset 1229 | 137fd7e7b102 |
parent 1227 | 01e86190f8c7 |
child 1264 | 27c8578670c8 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
25 |
from types import TupleType |
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
878
diff
changeset
|
26 |
from time import time as gettime |
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
878
diff
changeset
|
27 |
import numpy |
814 | 28 |
|
29 |
import wx |
|
888
baf5dbfd28f4
Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents:
887
diff
changeset
|
30 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
31 |
import matplotlib |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
32 |
matplotlib.use('WX') |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
33 |
import matplotlib.pyplot |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
34 |
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
35 |
from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
36 |
from matplotlib.backends.backend_agg import FigureCanvasAgg |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
37 |
from mpl_toolkits.mplot3d import Axes3D |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
38 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
39 |
from editors.DebugViewer import REFRESH_PERIOD |
814 | 40 |
|
1199
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
41 |
from DebugVariableItem import DebugVariableItem |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
42 |
from DebugVariableViewer import * |
1199
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
43 |
from GraphButton import GraphButton |
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
44 |
|
1209 | 45 |
# Graph variable display type |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
46 |
GRAPH_PARALLEL, GRAPH_ORTHOGONAL = range(2) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
47 |
|
1209 | 48 |
# Canvas height |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
49 |
[SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = [0, 100, 200] |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
50 |
|
1209 | 51 |
CANVAS_BORDER = (20., 10.) # Border height on at bottom and top of graph |
52 |
CANVAS_PADDING = 8.5 # Border inside graph where no label is drawn |
|
53 |
VALUE_LABEL_HEIGHT = 17. # Height of variable label in graph |
|
54 |
AXES_LABEL_HEIGHT = 12.75 # Height of variable value in graph |
|
55 |
||
56 |
# Colors used cyclically for graph curves |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
57 |
COLOR_CYCLE = ['r', 'b', 'g', 'm', 'y', 'k'] |
1209 | 58 |
# Color for graph cursor |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
59 |
CURSOR_COLOR = '#800080' |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
60 |
|
1209 | 61 |
#------------------------------------------------------------------------------- |
62 |
# Debug Variable Graphic Viewer Drop Target |
|
63 |
#------------------------------------------------------------------------------- |
|
64 |
||
65 |
""" |
|
1215 | 66 |
Class that implements a custom drop target class for Debug Variable Graphic |
67 |
Viewer |
|
1209 | 68 |
""" |
69 |
||
70 |
class DebugVariableGraphicDropTarget(wx.TextDropTarget): |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
71 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
72 |
def __init__(self, parent, window): |
1209 | 73 |
""" |
74 |
Constructor |
|
75 |
@param parent: Reference to Debug Variable Graphic Viewer |
|
76 |
@param window: Reference to the Debug Variable Panel |
|
77 |
""" |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
78 |
wx.TextDropTarget.__init__(self) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
79 |
self.ParentControl = parent |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
80 |
self.ParentWindow = window |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
81 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
82 |
def __del__(self): |
1209 | 83 |
""" |
84 |
Destructor |
|
85 |
""" |
|
86 |
# Remove reference to Debug Variable Graphic Viewer and Debug Variable |
|
87 |
# Panel |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
88 |
self.ParentControl = None |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
89 |
self.ParentWindow = None |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
90 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
91 |
def OnDragOver(self, x, y, d): |
1209 | 92 |
""" |
93 |
Function called when mouse is dragged over Drop Target |
|
94 |
@param x: X coordinate of mouse pointer |
|
95 |
@param y: Y coordinate of mouse pointer |
|
96 |
@param d: Suggested default for return value |
|
97 |
""" |
|
98 |
# Signal parent that mouse is dragged over |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
99 |
self.ParentControl.OnMouseDragging(x, y) |
1209 | 100 |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
101 |
return wx.TextDropTarget.OnDragOver(self, x, y, d) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
102 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
103 |
def OnDropText(self, x, y, data): |
1209 | 104 |
""" |
1215 | 105 |
Function called when mouse is released in Drop Target |
1209 | 106 |
@param x: X coordinate of mouse pointer |
107 |
@param y: Y coordinate of mouse pointer |
|
108 |
@param data: Text associated to drag'n drop |
|
109 |
""" |
|
1218 | 110 |
# Signal Debug Variable Panel to reset highlight |
111 |
self.ParentWindow.ResetHighlight() |
|
112 |
||
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
113 |
message = None |
1209 | 114 |
|
115 |
# Check that data is valid regarding DebugVariablePanel |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
116 |
try: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
117 |
values = eval(data) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
118 |
if not isinstance(values, TupleType): |
1207 | 119 |
raise ValueError |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
120 |
except: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
121 |
message = _("Invalid value \"%s\" for debug variable")%data |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
122 |
values = None |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
123 |
|
1209 | 124 |
# Display message if data is invalid |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
125 |
if message is not None: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
126 |
wx.CallAfter(self.ShowMessage, message) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
127 |
|
1209 | 128 |
# Data contain a reference to a variable to debug |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
129 |
elif values[1] == "debug": |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
130 |
target_idx = self.ParentControl.GetIndex() |
1209 | 131 |
|
132 |
# If mouse is dropped in graph canvas bounding box and graph is |
|
133 |
# not 3D canvas, graphs will be merged |
|
134 |
rect = self.ParentControl.GetAxesBoundingBox() |
|
135 |
if not self.ParentControl.Is3DCanvas() and rect.InsideXY(x, y): |
|
136 |
# Default merge type is parallel |
|
137 |
merge_type = GRAPH_PARALLEL |
|
138 |
||
139 |
# If mouse is dropped in left part of graph canvas, graph |
|
140 |
# wall be merged orthogonally |
|
141 |
merge_rect = wx.Rect(rect.x, rect.y, |
|
142 |
rect.width / 2., rect.height) |
|
143 |
if merge_rect.InsideXY(x, y): |
|
144 |
merge_type = GRAPH_ORTHOGONAL |
|
145 |
||
146 |
# Merge graphs |
|
147 |
wx.CallAfter(self.ParentWindow.MergeGraphs, |
|
148 |
values[0], target_idx, |
|
149 |
merge_type, force=True) |
|
150 |
||
151 |
else: |
|
152 |
width, height = self.ParentControl.GetSize() |
|
153 |
||
154 |
# Get Before which Viewer the variable has to be moved or added |
|
155 |
# according to the position of mouse in Viewer. |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
156 |
if y > height / 2: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
157 |
target_idx += 1 |
1209 | 158 |
|
159 |
# Drag'n Drop is an internal is an internal move inside Debug |
|
160 |
# Variable Panel |
|
161 |
if len(values) > 2 and values[2] == "move": |
|
162 |
self.ParentWindow.MoveValue(values[0], |
|
163 |
target_idx) |
|
164 |
||
165 |
# Drag'n Drop was initiated by another control of Beremiz |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
166 |
else: |
1209 | 167 |
self.ParentWindow.InsertValue(values[0], |
168 |
target_idx, |
|
169 |
force=True) |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
170 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
171 |
def OnLeave(self): |
1209 | 172 |
""" |
173 |
Function called when mouse is leave Drop Target |
|
174 |
""" |
|
175 |
# Signal Debug Variable Panel to reset highlight |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
176 |
self.ParentWindow.ResetHighlight() |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
177 |
return wx.TextDropTarget.OnLeave(self) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
178 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
179 |
def ShowMessage(self, message): |
1209 | 180 |
""" |
181 |
Show error message in Error Dialog |
|
182 |
@param message: Error message to display |
|
183 |
""" |
|
1227
01e86190f8c7
Fixed tick not refreshed when in DebugVariablePanel when variable in it
Laurent Bessard
parents:
1218
diff
changeset
|
184 |
dialog = wx.MessageDialog(self.ParentWindow, |
01e86190f8c7
Fixed tick not refreshed when in DebugVariablePanel when variable in it
Laurent Bessard
parents:
1218
diff
changeset
|
185 |
message, |
01e86190f8c7
Fixed tick not refreshed when in DebugVariablePanel when variable in it
Laurent Bessard
parents:
1218
diff
changeset
|
186 |
_("Error"), |
01e86190f8c7
Fixed tick not refreshed when in DebugVariablePanel when variable in it
Laurent Bessard
parents:
1218
diff
changeset
|
187 |
wx.OK|wx.ICON_ERROR) |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
188 |
dialog.ShowModal() |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
189 |
dialog.Destroy() |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
190 |
|
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
191 |
|
1209 | 192 |
#------------------------------------------------------------------------------- |
193 |
# Debug Variable Graphic Viewer Class |
|
194 |
#------------------------------------------------------------------------------- |
|
195 |
||
196 |
""" |
|
197 |
Class that implements a Viewer that display variable values as a graphs |
|
198 |
""" |
|
199 |
||
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
200 |
class DebugVariableGraphicViewer(DebugVariableViewer, FigureCanvas): |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
201 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
202 |
def __init__(self, parent, window, items, graph_type): |
1209 | 203 |
""" |
204 |
Constructor |
|
205 |
@param parent: Parent wx.Window of DebugVariableText |
|
206 |
@param window: Reference to the Debug Variable Panel |
|
207 |
@param items: List of DebugVariableItem displayed by Viewer |
|
208 |
@param graph_type: Graph display type (Parallel or orthogonal) |
|
209 |
""" |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
210 |
DebugVariableViewer.__init__(self, window, items) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
211 |
|
1209 | 212 |
self.GraphType = graph_type # Graph type display |
213 |
self.CursorTick = None # Tick of the graph cursor |
|
214 |
||
215 |
# Mouse position when start dragging |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
216 |
self.MouseStartPos = None |
1209 | 217 |
# Tick when moving tick start |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
218 |
self.StartCursorTick = None |
1209 | 219 |
# Canvas size when starting to resize canvas |
220 |
self.CanvasStartSize = None |
|
221 |
||
222 |
# List of current displayed contextual buttons |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
223 |
self.ContextualButtons = [] |
1209 | 224 |
# Reference to item for which contextual buttons was displayed |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
225 |
self.ContextualButtonsItem = None |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
226 |
|
1209 | 227 |
# Create figure for drawing graphs |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
228 |
self.Figure = matplotlib.figure.Figure(facecolor='w') |
1209 | 229 |
# Defined border around figure in canvas |
230 |
self.Figure.subplotpars.update(top=0.95, left=0.1, |
|
231 |
bottom=0.1, right=0.95) |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
232 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
233 |
FigureCanvas.__init__(self, parent, -1, self.Figure) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
234 |
self.SetWindowStyle(wx.WANTS_CHARS) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
235 |
self.SetBackgroundColour(wx.WHITE) |
1209 | 236 |
|
237 |
# Bind wx events |
|
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
238 |
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
239 |
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
240 |
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
241 |
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
242 |
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
243 |
self.Bind(wx.EVT_SIZE, self.OnResize) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
244 |
|
1209 | 245 |
# Set canvas min size |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
246 |
canvas_size = self.GetCanvasMinSize() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
247 |
self.SetMinSize(canvas_size) |
1209 | 248 |
|
249 |
# Define Viewer drop target |
|
250 |
self.SetDropTarget(DebugVariableGraphicDropTarget(self, window)) |
|
251 |
||
252 |
# Connect matplotlib events |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
253 |
self.mpl_connect('button_press_event', self.OnCanvasButtonPressed) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
254 |
self.mpl_connect('motion_notify_event', self.OnCanvasMotion) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
255 |
self.mpl_connect('button_release_event', self.OnCanvasButtonReleased) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
256 |
self.mpl_connect('scroll_event', self.OnCanvasScroll) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
257 |
|
1209 | 258 |
# Add buttons for changing canvas size with predefined height |
259 |
for size, bitmap in zip( |
|
260 |
[SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI], |
|
261 |
["minimize_graph", "middle_graph", "maximize_graph"]): |
|
262 |
self.Buttons.append( |
|
263 |
GraphButton(0, 0, bitmap, |
|
264 |
self.GetOnChangeSizeButton(size))) |
|
265 |
||
266 |
# Add buttons for exporting graph values to clipboard and close graph |
|
267 |
for bitmap, callback in [ |
|
268 |
("export_graph_mini", self.OnExportGraphButton), |
|
269 |
("delete_graph", self.OnCloseButton)]: |
|
1199
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
270 |
self.Buttons.append(GraphButton(0, 0, bitmap, callback)) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
271 |
|
1209 | 272 |
# Update graphs elements |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
273 |
self.ResetGraphics() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
274 |
self.RefreshLabelsPosition(canvas_size.height) |
1209 | 275 |
|
276 |
def AddItem(self, item): |
|
277 |
""" |
|
278 |
Add an item to the list of items displayed by Viewer |
|
279 |
@param item: Item to add to the list |
|
280 |
""" |
|
281 |
DebugVariableViewer.AddItem(self, item) |
|
282 |
self.ResetGraphics() |
|
283 |
||
284 |
def RemoveItem(self, item): |
|
285 |
""" |
|
286 |
Remove an item from the list of items displayed by Viewer |
|
287 |
@param item: Item to remove from the list |
|
288 |
""" |
|
289 |
DebugVariableViewer.RemoveItem(self, item) |
|
290 |
||
291 |
# If list of items is not empty |
|
292 |
if not self.ItemsIsEmpty(): |
|
293 |
# Return to parallel graph if there is only one item |
|
294 |
# especially if it's actually orthogonal |
|
295 |
if len(self.Items) == 1: |
|
296 |
self.GraphType = GRAPH_PARALLEL |
|
297 |
self.ResetGraphics() |
|
298 |
||
1212 | 299 |
def SetCursorTick(self, cursor_tick): |
300 |
""" |
|
301 |
Set cursor tick |
|
302 |
@param cursor_tick: Cursor tick |
|
303 |
""" |
|
304 |
self.CursorTick = cursor_tick |
|
305 |
||
1209 | 306 |
def SubscribeAllDataConsumers(self): |
307 |
""" |
|
308 |
Function that unsubscribe and remove every item that store values of |
|
309 |
a variable that doesn't exist in PLC anymore |
|
310 |
""" |
|
311 |
DebugVariableViewer.SubscribeAllDataConsumers(self) |
|
312 |
if not self.ItemsIsEmpty(): |
|
313 |
self.ResetGraphics() |
|
314 |
||
315 |
def Is3DCanvas(self): |
|
316 |
""" |
|
317 |
Return if Viewer is a 3D canvas |
|
318 |
@return: True if Viewer is a 3D canvas |
|
319 |
""" |
|
320 |
return self.GraphType == GRAPH_ORTHOGONAL and len(self.Items) == 3 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
321 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
322 |
def GetButtons(self): |
1209 | 323 |
""" |
324 |
Return list of buttons defined in Viewer |
|
325 |
@return: List of buttons |
|
326 |
""" |
|
327 |
# Add contextual buttons to default buttons |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
328 |
return self.Buttons + self.ContextualButtons |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
329 |
|
1209 | 330 |
def PopupContextualButtons(self, item, rect, direction=wx.RIGHT): |
331 |
""" |
|
332 |
Show contextual menu for item aside a label of this item defined |
|
333 |
by the bounding box of label in figure |
|
334 |
@param item: Item for which contextual is shown |
|
335 |
@param rect: Bounding box of label aside which drawing menu |
|
336 |
@param direction: Direction in which buttons must be drawn |
|
337 |
""" |
|
338 |
# Return immediately if contextual menu for item is already shown |
|
339 |
if self.ContextualButtonsItem == item: |
|
340 |
return |
|
341 |
||
342 |
# Close already shown contextual menu |
|
343 |
self.DismissContextualButtons() |
|
344 |
||
345 |
# Save item for which contextual menu is shown |
|
346 |
self.ContextualButtonsItem = item |
|
347 |
||
348 |
# If item variable is forced, add button for release variable to |
|
349 |
# contextual menu |
|
350 |
if self.ContextualButtonsItem.IsForced(): |
|
351 |
self.ContextualButtons.append( |
|
352 |
GraphButton(0, 0, "release", self.OnReleaseItemButton)) |
|
353 |
||
354 |
# Add other buttons to contextual menu |
|
355 |
for bitmap, callback in [ |
|
356 |
("force", self.OnForceItemButton), |
|
357 |
("export_graph_mini", self.OnExportItemGraphButton), |
|
358 |
("delete_graph", self.OnRemoveItemButton)]: |
|
359 |
self.ContextualButtons.append( |
|
360 |
GraphButton(0, 0, bitmap, callback)) |
|
361 |
||
362 |
# If buttons are shown at left side or upper side of rect, positions |
|
363 |
# will be set in reverse order |
|
364 |
buttons = self.ContextualButtons[:] |
|
365 |
if direction in [wx.TOP, wx.LEFT]: |
|
366 |
buttons.reverse() |
|
367 |
||
368 |
# Set contextual menu buttons position aside rect depending on |
|
369 |
# direction given |
|
370 |
offset = 0 |
|
371 |
for button in buttons: |
|
372 |
w, h = button.GetSize() |
|
373 |
if direction in [wx.LEFT, wx.RIGHT]: |
|
374 |
x = rect.x + (- w - offset |
|
375 |
if direction == wx.LEFT |
|
376 |
else rect.width + offset) |
|
377 |
y = rect.y + (rect.height - h) / 2 |
|
378 |
offset += w |
|
379 |
else: |
|
380 |
x = rect.x + (rect.width - w ) / 2 |
|
381 |
y = rect.y + (- h - offset |
|
382 |
if direction == wx.TOP |
|
383 |
else rect.height + offset) |
|
384 |
offset += h |
|
385 |
button.SetPosition(x, y) |
|
386 |
button.Show() |
|
387 |
||
388 |
# Refresh canvas |
|
389 |
self.ParentWindow.ForceRefresh() |
|
390 |
||
391 |
def DismissContextualButtons(self): |
|
392 |
""" |
|
393 |
Close current shown contextual menu |
|
394 |
""" |
|
395 |
# Return immediately if no contextual menu is shown |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
396 |
if self.ContextualButtonsItem is None: |
1209 | 397 |
return |
398 |
||
399 |
# Reset variables corresponding to contextual menu |
|
400 |
self.ContextualButtonsItem = None |
|
401 |
self.ContextualButtons = [] |
|
402 |
||
403 |
# Refresh canvas |
|
404 |
self.ParentWindow.ForceRefresh() |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
405 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
406 |
def IsOverContextualButton(self, x, y): |
1209 | 407 |
""" |
408 |
Return if point is over one contextual button of Viewer |
|
409 |
@param x: X coordinate of point |
|
410 |
@param y: Y coordinate of point |
|
411 |
@return: contextual button where point is over |
|
412 |
""" |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
413 |
for button in self.ContextualButtons: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
414 |
if button.HitTest(x, y): |
1209 | 415 |
return button |
416 |
return None |
|
417 |
||
418 |
def ExportGraph(self, item=None): |
|
419 |
""" |
|
420 |
Export item(s) data to clipboard in CSV format |
|
421 |
@param item: Item from which data to export, all items if None |
|
422 |
(default None) |
|
423 |
""" |
|
424 |
self.ParentWindow.CopyDataToClipboard( |
|
425 |
[(item, [entry for entry in item.GetData()]) |
|
426 |
for item in (self.Items |
|
427 |
if item is None |
|
428 |
else [item])]) |
|
429 |
||
430 |
def GetOnChangeSizeButton(self, height): |
|
431 |
""" |
|
432 |
Function that generate callback function for change Viewer height to |
|
433 |
pre-defined height button |
|
434 |
@param height: Height that change Viewer to |
|
435 |
@return: callback function |
|
436 |
""" |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
437 |
def OnChangeSizeButton(): |
1209 | 438 |
self.SetCanvasSize(200, height) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
439 |
return OnChangeSizeButton |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
440 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
441 |
def OnExportGraphButton(self): |
1209 | 442 |
""" |
443 |
Function called when Viewer Export button is pressed |
|
444 |
""" |
|
445 |
# Export data of every item in Viewer |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
446 |
self.ExportGraph() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
447 |
|
1209 | 448 |
def OnForceItemButton(self): |
449 |
""" |
|
450 |
Function called when contextual menu Force button is pressed |
|
451 |
""" |
|
452 |
# Open dialog for forcing item variable value |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
453 |
self.ForceValue(self.ContextualButtonsItem) |
1209 | 454 |
# Close contextual menu |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
455 |
self.DismissContextualButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
456 |
|
1209 | 457 |
def OnReleaseItemButton(self): |
458 |
""" |
|
459 |
Function called when contextual menu Release button is pressed |
|
460 |
""" |
|
461 |
# Release item variable value |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
462 |
self.ReleaseValue(self.ContextualButtonsItem) |
1209 | 463 |
# Close contextual menu |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
464 |
self.DismissContextualButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
465 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
466 |
def OnExportItemGraphButton(self): |
1209 | 467 |
""" |
468 |
Function called when contextual menu Export button is pressed |
|
469 |
""" |
|
470 |
# Export data of item variable |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
471 |
self.ExportGraph(self.ContextualButtonsItem) |
1209 | 472 |
# Close contextual menu |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
473 |
self.DismissContextualButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
474 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
475 |
def OnRemoveItemButton(self): |
1209 | 476 |
""" |
477 |
Function called when contextual menu Remove button is pressed |
|
478 |
""" |
|
479 |
# Remove item from Viewer |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
480 |
wx.CallAfter(self.ParentWindow.DeleteValue, self, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
481 |
self.ContextualButtonsItem) |
1209 | 482 |
# Close contextual menu |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
483 |
self.DismissContextualButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
484 |
|
1209 | 485 |
def HandleCursorMove(self, event): |
1212 | 486 |
""" |
487 |
Update Cursor position according to mouse position and graph type |
|
488 |
@param event: Mouse event |
|
489 |
""" |
|
1209 | 490 |
start_tick, end_tick = self.ParentWindow.GetRange() |
491 |
cursor_tick = None |
|
492 |
items = self.ItemsDict.values() |
|
1212 | 493 |
|
494 |
# Graph is orthogonal |
|
1209 | 495 |
if self.GraphType == GRAPH_ORTHOGONAL: |
1212 | 496 |
# Extract items data displayed in canvas figure |
497 |
min_start_tick = max(start_tick, self.GetItemsMinCommonTick()) |
|
498 |
start_tick = max(start_tick, min_start_tick) |
|
499 |
end_tick = max(end_tick, min_start_tick) |
|
1209 | 500 |
x_data = items[0].GetData(start_tick, end_tick) |
501 |
y_data = items[1].GetData(start_tick, end_tick) |
|
1212 | 502 |
|
503 |
# Search for the nearest point from mouse position |
|
1209 | 504 |
if len(x_data) > 0 and len(y_data) > 0: |
1212 | 505 |
length = min(len(x_data), len(y_data)) |
506 |
d = numpy.sqrt((x_data[:length,1]-event.xdata) ** 2 + \ |
|
507 |
(y_data[:length,1]-event.ydata) ** 2) |
|
508 |
||
509 |
# Set cursor tick to the tick of this point |
|
1209 | 510 |
cursor_tick = x_data[numpy.argmin(d), 0] |
1212 | 511 |
|
512 |
# Graph is parallel |
|
1209 | 513 |
else: |
1212 | 514 |
# Extract items tick |
1209 | 515 |
data = items[0].GetData(start_tick, end_tick) |
1212 | 516 |
|
517 |
# Search for point that tick is the nearest from mouse X position |
|
518 |
# and set cursor tick to the tick of this point |
|
1209 | 519 |
if len(data) > 0: |
1212 | 520 |
cursor_tick = data[numpy.argmin( |
521 |
numpy.abs(data[:,0] - event.xdata)), 0] |
|
522 |
||
523 |
# Update cursor tick |
|
1209 | 524 |
if cursor_tick is not None: |
525 |
self.ParentWindow.SetCursorTick(cursor_tick) |
|
526 |
||
527 |
def OnCanvasButtonPressed(self, event): |
|
528 |
""" |
|
529 |
Function called when a button of mouse is pressed |
|
530 |
@param event: Mouse event |
|
531 |
""" |
|
1212 | 532 |
# Get mouse position, graph Y coordinate is inverted in matplotlib |
533 |
# comparing to wx |
|
1209 | 534 |
width, height = self.GetSize() |
535 |
x, y = event.x, height - event.y |
|
536 |
||
537 |
# Return immediately if mouse is over a button |
|
538 |
if self.IsOverButton(x, y): |
|
539 |
return |
|
540 |
||
541 |
# Mouse was clicked inside graph figure |
|
542 |
if event.inaxes == self.Axes: |
|
543 |
||
544 |
# Find if it was on an item label |
|
545 |
item_idx = None |
|
546 |
# Check every label paired with corresponding item |
|
547 |
for i, t in ([pair for pair in enumerate(self.AxesLabels)] + |
|
548 |
[pair for pair in enumerate(self.Labels)]): |
|
549 |
# Get label bounding box |
|
550 |
(x0, y0), (x1, y1) = t.get_window_extent().get_points() |
|
551 |
rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0) |
|
552 |
# Check if mouse was over label |
|
553 |
if rect.InsideXY(x, y): |
|
554 |
item_idx = i |
|
555 |
break |
|
556 |
||
557 |
# If an item label have been clicked |
|
558 |
if item_idx is not None: |
|
559 |
# Hide buttons and contextual buttons |
|
560 |
self.ShowButtons(False) |
|
561 |
self.DismissContextualButtons() |
|
562 |
||
563 |
# Start a drag'n drop from mouse position in wx coordinate of |
|
564 |
# parent |
|
565 |
xw, yw = self.GetPosition() |
|
566 |
self.ParentWindow.StartDragNDrop(self, |
|
567 |
self.ItemsDict.values()[item_idx], |
|
568 |
x + xw, y + yw, # Current mouse position |
|
569 |
x + xw, y + yw) # Mouse position when button was clicked |
|
570 |
||
571 |
# Don't handle mouse button if canvas is 3D and let matplotlib do |
|
572 |
# the default behavior (rotate 3D axes) |
|
573 |
elif not self.Is3DCanvas(): |
|
574 |
# Save mouse position when clicked |
|
575 |
self.MouseStartPos = wx.Point(x, y) |
|
576 |
||
577 |
# Mouse button was left button, start moving cursor |
|
578 |
if event.button == 1: |
|
579 |
# Save current tick in case a drag'n drop is initiate to |
|
580 |
# restore it |
|
581 |
self.StartCursorTick = self.CursorTick |
|
582 |
||
583 |
self.HandleCursorMove(event) |
|
584 |
||
585 |
# Mouse button is middle button and graph is parallel, start |
|
586 |
# moving graph along X coordinate (tick) |
|
587 |
elif event.button == 2 and self.GraphType == GRAPH_PARALLEL: |
|
588 |
self.StartCursorTick = self.ParentWindow.GetRange()[0] |
|
589 |
||
590 |
# Mouse was clicked outside graph figure and over resize highlight with |
|
591 |
# left button, start resizing Viewer |
|
592 |
elif event.button == 1 and event.y <= 5: |
|
593 |
self.MouseStartPos = wx.Point(x, y) |
|
594 |
self.CanvasStartSize = height |
|
595 |
||
596 |
def OnCanvasButtonReleased(self, event): |
|
597 |
""" |
|
598 |
Function called when a button of mouse is released |
|
599 |
@param event: Mouse event |
|
600 |
""" |
|
601 |
# If a drag'n drop is in progress, stop it |
|
602 |
if self.ParentWindow.IsDragging(): |
|
603 |
width, height = self.GetSize() |
|
604 |
xw, yw = self.GetPosition() |
|
605 |
item = self.ParentWindow.DraggingAxesPanel.ItemsDict.values()[0] |
|
606 |
# Give mouse position in wx coordinate of parent |
|
607 |
self.ParentWindow.StopDragNDrop(item.GetVariable(), |
|
608 |
xw + event.x, yw + height - event.y) |
|
609 |
||
610 |
else: |
|
611 |
# Reset any move in progress |
|
612 |
self.MouseStartPos = None |
|
613 |
self.CanvasStartSize = None |
|
614 |
||
615 |
# Handle button under mouse if it exist |
|
616 |
width, height = self.GetSize() |
|
617 |
self.HandleButton(event.x, height - event.y) |
|
618 |
||
619 |
def OnCanvasMotion(self, event): |
|
620 |
""" |
|
621 |
Function called when a button of mouse is moved over Viewer |
|
622 |
@param event: Mouse event |
|
623 |
""" |
|
624 |
width, height = self.GetSize() |
|
625 |
||
626 |
# If a drag'n drop is in progress, move canvas dragged |
|
627 |
if self.ParentWindow.IsDragging(): |
|
628 |
xw, yw = self.GetPosition() |
|
629 |
# Give mouse position in wx coordinate of parent |
|
630 |
self.ParentWindow.MoveDragNDrop( |
|
631 |
xw + event.x, |
|
632 |
yw + height - event.y) |
|
633 |
||
634 |
# If a Viewer resize is in progress, change Viewer size |
|
635 |
elif event.button == 1 and self.CanvasStartSize is not None: |
|
636 |
width, height = self.GetSize() |
|
637 |
self.SetCanvasSize(width, |
|
638 |
self.CanvasStartSize + height - event.y - self.MouseStartPos.y) |
|
639 |
||
640 |
# If no button is pressed, show or hide contextual buttons or resize |
|
641 |
# highlight |
|
642 |
elif event.button is None: |
|
643 |
# Compute direction for items label according graph type |
|
644 |
if self.GraphType == GRAPH_PARALLEL: # Graph is parallel |
|
645 |
directions = [wx.RIGHT] * len(self.AxesLabels) + \ |
|
646 |
[wx.LEFT] * len(self.Labels) |
|
647 |
elif len(self.AxesLabels) > 0: # Graph is orthogonal in 2D |
|
648 |
directions = [wx.RIGHT, wx.TOP, # Directions for AxesLabels |
|
649 |
wx.LEFT, wx.BOTTOM] # Directions for Labels |
|
650 |
else: # Graph is orthogonal in 3D |
|
651 |
directions = [wx.LEFT] * len(self.Labels) |
|
652 |
||
653 |
# Find if mouse is over an item label |
|
654 |
item_idx = None |
|
655 |
menu_direction = None |
|
656 |
for (i, t), dir in zip( |
|
657 |
[pair for pair in enumerate(self.AxesLabels)] + |
|
658 |
[pair for pair in enumerate(self.Labels)], |
|
659 |
directions): |
|
660 |
# Check every label paired with corresponding item |
|
661 |
(x0, y0), (x1, y1) = t.get_window_extent().get_points() |
|
662 |
rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0) |
|
663 |
# Check if mouse was over label |
|
664 |
if rect.InsideXY(event.x, height - event.y): |
|
665 |
item_idx = i |
|
666 |
menu_direction = dir |
|
667 |
break |
|
668 |
||
669 |
# If mouse is over an item label, |
|
670 |
if item_idx is not None: |
|
671 |
self.PopupContextualButtons( |
|
672 |
self.ItemsDict.values()[item_idx], |
|
673 |
rect, menu_direction) |
|
674 |
return |
|
675 |
||
676 |
# If mouse isn't over a contextual menu, hide the current shown one |
|
677 |
# if it exists |
|
678 |
if self.IsOverContextualButton(event.x, height - event.y) is None: |
|
679 |
self.DismissContextualButtons() |
|
680 |
||
681 |
# Update resize highlight |
|
682 |
if event.y <= 5: |
|
683 |
if self.SetHighlight(HIGHLIGHT_RESIZE): |
|
684 |
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
|
685 |
self.ParentWindow.ForceRefresh() |
|
686 |
else: |
|
687 |
if self.SetHighlight(HIGHLIGHT_NONE): |
|
688 |
self.SetCursor(wx.NullCursor) |
|
689 |
self.ParentWindow.ForceRefresh() |
|
690 |
||
691 |
# Handle buttons if canvas is not 3D |
|
692 |
elif not self.Is3DCanvas(): |
|
693 |
||
694 |
# If left button is pressed |
|
695 |
if event.button == 1: |
|
696 |
||
697 |
# Mouse is inside graph figure |
|
698 |
if event.inaxes == self.Axes: |
|
699 |
||
700 |
# If a cursor move is in progress, update cursor position |
|
701 |
if self.MouseStartPos is not None: |
|
702 |
self.HandleCursorMove(event) |
|
703 |
||
704 |
# Mouse is outside graph figure, cursor move is in progress and |
|
705 |
# there is only one item in Viewer, start a drag'n drop |
|
706 |
elif self.MouseStartPos is not None and len(self.Items) == 1: |
|
707 |
xw, yw = self.GetPosition() |
|
708 |
self.ParentWindow.SetCursorTick(self.StartCursorTick) |
|
709 |
self.ParentWindow.StartDragNDrop(self, |
|
710 |
self.ItemsDict.values()[0], |
|
711 |
# Current mouse position |
|
712 |
event.x + xw, height - event.y + yw, |
|
713 |
# Mouse position when button was clicked |
|
714 |
self.MouseStartPos.x + xw, |
|
715 |
self.MouseStartPos.y + yw) |
|
716 |
||
717 |
# If middle button is pressed and moving graph along X coordinate |
|
718 |
# is in progress |
|
719 |
elif event.button == 2 and self.GraphType == GRAPH_PARALLEL and \ |
|
720 |
self.MouseStartPos is not None: |
|
721 |
start_tick, end_tick = self.ParentWindow.GetRange() |
|
722 |
rect = self.GetAxesBoundingBox() |
|
723 |
||
724 |
# Move graph along X coordinate |
|
725 |
self.ParentWindow.SetCanvasPosition( |
|
726 |
self.StartCursorTick + |
|
727 |
(self.MouseStartPos.x - event.x) * |
|
728 |
(end_tick - start_tick) / rect.width) |
|
729 |
||
730 |
def OnCanvasScroll(self, event): |
|
731 |
""" |
|
732 |
Function called when a wheel mouse is use in Viewer |
|
733 |
@param event: Mouse event |
|
734 |
""" |
|
735 |
# Change X range of graphs if mouse is in canvas figure and ctrl is |
|
736 |
# pressed |
|
737 |
if event.inaxes is not None and event.guiEvent.ControlDown(): |
|
738 |
||
739 |
# Calculate position of fixed tick point according to graph type |
|
740 |
# and mouse position |
|
741 |
if self.GraphType == GRAPH_ORTHOGONAL: |
|
742 |
start_tick, end_tick = self.ParentWindow.GetRange() |
|
743 |
tick = (start_tick + end_tick) / 2. |
|
744 |
else: |
|
745 |
tick = event.xdata |
|
746 |
self.ParentWindow.ChangeRange(int(-event.step) / 3, tick) |
|
747 |
||
748 |
# Vetoing event to prevent parent panel to be scrolled |
|
749 |
self.ParentWindow.VetoScrollEvent = True |
|
750 |
||
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
751 |
def OnLeftDClick(self, event): |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
752 |
""" |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
753 |
Function called when a left mouse button is double clicked |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
754 |
@param event: Mouse event |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
755 |
""" |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
756 |
# Check that double click was done inside figure |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
757 |
pos = event.GetPosition() |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
758 |
rect = self.GetAxesBoundingBox() |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
759 |
if rect.InsideXY(pos.x, pos.y): |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
760 |
# Reset Cursor tick to value before starting clicking |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
761 |
self.ParentWindow.SetCursorTick(self.StartCursorTick) |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
762 |
# Toggle to text Viewer(s) |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
763 |
self.ParentWindow.ToggleViewerType(self) |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
764 |
|
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
765 |
else: |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
766 |
event.Skip() |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
767 |
|
1209 | 768 |
# Cursor tick move for each arrow key |
769 |
KEY_CURSOR_INCREMENT = { |
|
770 |
wx.WXK_LEFT: -1, |
|
771 |
wx.WXK_RIGHT: 1, |
|
772 |
wx.WXK_UP: -10, |
|
773 |
wx.WXK_DOWN: 10} |
|
774 |
||
775 |
def OnKeyDown(self, event): |
|
776 |
""" |
|
777 |
Function called when key is pressed |
|
778 |
@param event: wx.KeyEvent |
|
779 |
""" |
|
780 |
# If cursor is shown and arrow key is pressed, move cursor tick |
|
781 |
if self.CursorTick is not None: |
|
782 |
move = self.KEY_CURSOR_INCREMENT.get(event.GetKeyCode(), None) |
|
783 |
if move is not None: |
|
784 |
self.ParentWindow.MoveCursorTick(move) |
|
785 |
event.Skip() |
|
786 |
||
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
787 |
def OnLeave(self, event): |
1209 | 788 |
""" |
789 |
Function called when mouse leave Viewer |
|
790 |
@param event: wx.MouseEvent |
|
791 |
""" |
|
792 |
# If Viewer is not resizing, reset resize highlight |
|
793 |
if self.CanvasStartSize is None: |
|
794 |
self.SetHighlight(HIGHLIGHT_NONE) |
|
795 |
self.SetCursor(wx.NullCursor) |
|
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
796 |
DebugVariableViewer.OnLeave(self, event) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
797 |
else: |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
798 |
event.Skip() |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
799 |
|
1212 | 800 |
def GetCanvasMinSize(self): |
801 |
""" |
|
802 |
Return the minimum size of Viewer so that all items label can be |
|
803 |
displayed |
|
804 |
@return: wx.Size containing Viewer minimum size |
|
805 |
""" |
|
806 |
# The minimum height take in account the height of all items, padding |
|
807 |
# inside figure and border around figure |
|
808 |
return wx.Size(200, |
|
809 |
CANVAS_BORDER[0] + CANVAS_BORDER[1] + |
|
810 |
2 * CANVAS_PADDING + VALUE_LABEL_HEIGHT * len(self.Items)) |
|
811 |
||
812 |
def SetCanvasSize(self, width, height): |
|
813 |
""" |
|
814 |
Set Viewer size checking that it respects Viewer minimum size |
|
815 |
@param width: Viewer width |
|
816 |
@param height: Viewer height |
|
817 |
""" |
|
818 |
height = max(height, self.GetCanvasMinSize()[1]) |
|
819 |
self.SetMinSize(wx.Size(width, height)) |
|
820 |
self.RefreshLabelsPosition(height) |
|
821 |
self.ParentWindow.RefreshGraphicsSizer() |
|
822 |
||
823 |
def GetAxesBoundingBox(self, parent_coordinate=False): |
|
824 |
""" |
|
825 |
Return figure bounding box in wx coordinate |
|
826 |
@param parent_coordinate: True if use parent coordinate (default False) |
|
827 |
""" |
|
828 |
# Calculate figure bounding box. Y coordinate is inverted in matplotlib |
|
829 |
# figure comparing to wx panel |
|
830 |
width, height = self.GetSize() |
|
831 |
ax, ay, aw, ah = self.figure.gca().get_position().bounds |
|
832 |
bbox = wx.Rect(ax * width, height - (ay + ah) * height - 1, |
|
833 |
aw * width + 2, ah * height + 1) |
|
834 |
||
835 |
# If parent_coordinate, add Viewer position in parent |
|
836 |
if parent_coordinate: |
|
837 |
xw, yw = self.GetPosition() |
|
838 |
bbox.x += xw |
|
839 |
bbox.y += yw |
|
840 |
||
841 |
return bbox |
|
842 |
||
843 |
def RefreshHighlight(self, x, y): |
|
844 |
""" |
|
845 |
Refresh Viewer highlight according to mouse position |
|
846 |
@param x: X coordinate of mouse pointer |
|
847 |
@param y: Y coordinate of mouse pointer |
|
848 |
""" |
|
849 |
width, height = self.GetSize() |
|
850 |
||
851 |
# Mouse is over Viewer figure and graph is not 3D |
|
852 |
bbox = self.GetAxesBoundingBox() |
|
853 |
if bbox.InsideXY(x, y) and not self.Is3DCanvas(): |
|
854 |
rect = wx.Rect(bbox.x, bbox.y, bbox.width / 2, bbox.height) |
|
855 |
# Mouse is over Viewer left part of figure |
|
856 |
if rect.InsideXY(x, y): |
|
857 |
self.SetHighlight(HIGHLIGHT_LEFT) |
|
858 |
||
859 |
# Mouse is over Viewer right part of figure |
|
860 |
else: |
|
861 |
self.SetHighlight(HIGHLIGHT_RIGHT) |
|
862 |
||
863 |
# Mouse is over upper part of Viewer |
|
864 |
elif y < height / 2: |
|
865 |
# Viewer is upper one in Debug Variable Panel, show highlight |
|
866 |
if self.ParentWindow.IsViewerFirst(self): |
|
867 |
self.SetHighlight(HIGHLIGHT_BEFORE) |
|
868 |
||
869 |
# Viewer is not the upper one, show highlight in previous one |
|
870 |
# It prevents highlight to move when mouse leave one Viewer to |
|
871 |
# another |
|
872 |
else: |
|
873 |
self.SetHighlight(HIGHLIGHT_NONE) |
|
874 |
self.ParentWindow.HighlightPreviousViewer(self) |
|
875 |
||
876 |
# Mouse is over lower part of Viewer |
|
877 |
else: |
|
878 |
self.SetHighlight(HIGHLIGHT_AFTER) |
|
879 |
||
880 |
def OnAxesMotion(self, event): |
|
881 |
""" |
|
882 |
Function overriding default function called when mouse is dragged for |
|
883 |
rotating graph preventing refresh to be called too quickly |
|
884 |
@param event: Mouse event |
|
885 |
""" |
|
886 |
if self.Is3DCanvas(): |
|
887 |
# Call default function at most 10 times per second |
|
888 |
current_time = gettime() |
|
889 |
if current_time - self.LastMotionTime > REFRESH_PERIOD: |
|
890 |
self.LastMotionTime = current_time |
|
891 |
Axes3D._on_move(self.Axes, event) |
|
892 |
||
893 |
def GetAddTextFunction(self): |
|
894 |
""" |
|
895 |
Return function for adding text in figure according to graph type |
|
896 |
@return: Function adding text to figure |
|
897 |
""" |
|
898 |
text_func = (self.Axes.text2D if self.Is3DCanvas() else self.Axes.text) |
|
899 |
def AddText(*args, **kwargs): |
|
900 |
args = [0, 0, ""] |
|
901 |
kwargs["transform"] = self.Axes.transAxes |
|
902 |
return text_func(*args, **kwargs) |
|
903 |
return AddText |
|
904 |
||
905 |
def ResetGraphics(self): |
|
906 |
""" |
|
907 |
Reset figure and graphical elements displayed in it |
|
908 |
Called any time list of items or graph type change |
|
909 |
""" |
|
910 |
# Clear figure from any axes defined |
|
911 |
self.Figure.clear() |
|
912 |
||
913 |
# Add 3D projection if graph is in 3D |
|
914 |
if self.Is3DCanvas(): |
|
915 |
self.Axes = self.Figure.gca(projection='3d') |
|
916 |
self.Axes.set_color_cycle(['b']) |
|
917 |
||
918 |
# Override function to prevent too much refresh when graph is |
|
919 |
# rotated |
|
920 |
self.LastMotionTime = gettime() |
|
921 |
setattr(self.Axes, "_on_move", self.OnAxesMotion) |
|
922 |
||
923 |
# Init graph mouse event so that graph can be rotated |
|
924 |
self.Axes.mouse_init() |
|
925 |
||
926 |
# Set size of Z axis labels |
|
927 |
self.Axes.tick_params(axis='z', labelsize='small') |
|
928 |
||
929 |
else: |
|
930 |
self.Axes = self.Figure.gca() |
|
931 |
self.Axes.set_color_cycle(COLOR_CYCLE) |
|
932 |
||
933 |
# Set size of X and Y axis labels |
|
934 |
self.Axes.tick_params(axis='x', labelsize='small') |
|
935 |
self.Axes.tick_params(axis='y', labelsize='small') |
|
936 |
||
937 |
# Init variables storing graphical elements added to figure |
|
938 |
self.Plots = [] # List of curves |
|
939 |
self.VLine = None # Vertical line for cursor |
|
940 |
self.HLine = None # Horizontal line for cursor (only orthogonal 2D) |
|
941 |
self.AxesLabels = [] # List of items variable path text label |
|
942 |
self.Labels = [] # List of items text label |
|
943 |
||
944 |
# Get function to add a text in figure according to graph type |
|
945 |
add_text_func = self.GetAddTextFunction() |
|
946 |
||
947 |
# Graph type is parallel or orthogonal in 3D |
|
948 |
if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas(): |
|
949 |
num_item = len(self.Items) |
|
950 |
for idx in xrange(num_item): |
|
951 |
||
952 |
# Get color from color cycle (black if only one item) |
|
953 |
color = ('k' if num_item == 1 |
|
954 |
else COLOR_CYCLE[idx % len(COLOR_CYCLE)]) |
|
955 |
||
956 |
# In 3D graph items variable label are not displayed as text |
|
957 |
# in figure, but as axis title |
|
958 |
if not self.Is3DCanvas(): |
|
959 |
# Items variable labels are in figure upper left corner |
|
960 |
self.AxesLabels.append( |
|
961 |
add_text_func(size='small', color=color, |
|
962 |
verticalalignment='top')) |
|
963 |
||
964 |
# Items variable labels are in figure lower right corner |
|
965 |
self.Labels.append( |
|
966 |
add_text_func(size='large', color=color, |
|
967 |
horizontalalignment='right')) |
|
968 |
||
969 |
# Graph type is orthogonal in 2D |
|
970 |
else: |
|
971 |
# X coordinate labels are in figure lower side |
|
972 |
self.AxesLabels.append(add_text_func(size='small')) |
|
973 |
self.Labels.append( |
|
974 |
add_text_func(size='large', |
|
975 |
horizontalalignment='right')) |
|
976 |
||
977 |
# Y coordinate labels are vertical and in figure left side |
|
978 |
self.AxesLabels.append( |
|
979 |
add_text_func(size='small', rotation='vertical')) |
|
980 |
self.Labels.append( |
|
981 |
add_text_func(size='large', rotation='vertical', |
|
982 |
verticalalignment='top')) |
|
983 |
||
984 |
# Refresh position of labels according to Viewer size |
|
985 |
width, height = self.GetSize() |
|
986 |
self.RefreshLabelsPosition(height) |
|
987 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
988 |
def RefreshLabelsPosition(self, height): |
1212 | 989 |
""" |
990 |
Function called when mouse leave Viewer |
|
991 |
@param event: wx.MouseEvent |
|
992 |
""" |
|
993 |
# Figure position like text position in figure are expressed is ratio |
|
994 |
# canvas size and figure size. As we want that border around figure and |
|
995 |
# text position in figure don't change when canvas size change, we |
|
996 |
# expressed border and text position in pixel on screen and apply the |
|
997 |
# ratio calculated hereafter to get border and text position in |
|
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1212
diff
changeset
|
998 |
# matplotlib coordinate |
1212 | 999 |
canvas_ratio = 1. / height # Divide by canvas height in pixel |
1000 |
graph_ratio = 1. / ( |
|
1001 |
(1.0 - (CANVAS_BORDER[0] + CANVAS_BORDER[1]) * canvas_ratio) |
|
1002 |
* height) # Divide by figure height in pixel |
|
1003 |
||
1004 |
# Update position of figure (keeping up and bottom border the same |
|
1005 |
# size) |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1006 |
self.Figure.subplotpars.update( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1007 |
top= 1.0 - CANVAS_BORDER[1] * canvas_ratio, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1008 |
bottom= CANVAS_BORDER[0] * canvas_ratio) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1009 |
|
1212 | 1010 |
# Update position of items labels |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1011 |
if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas(): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1012 |
num_item = len(self.Items) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1013 |
for idx in xrange(num_item): |
1212 | 1014 |
|
1015 |
# In 3D graph items variable label are not displayed |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1016 |
if not self.Is3DCanvas(): |
1212 | 1017 |
# Items variable labels are in figure upper left corner |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1018 |
self.AxesLabels[idx].set_position( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1019 |
(0.05, |
1212 | 1020 |
1.0 - (CANVAS_PADDING + |
1021 |
AXES_LABEL_HEIGHT * idx) * graph_ratio)) |
|
1022 |
||
1023 |
# Items variable labels are in figure lower right corner |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1024 |
self.Labels[idx].set_position( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1025 |
(0.95, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1026 |
CANVAS_PADDING * graph_ratio + |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1027 |
(num_item - idx - 1) * VALUE_LABEL_HEIGHT * graph_ratio)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1028 |
else: |
1212 | 1029 |
# X coordinate labels are in figure lower side |
1030 |
self.AxesLabels[0].set_position( |
|
1031 |
(0.1, CANVAS_PADDING * graph_ratio)) |
|
1032 |
self.Labels[0].set_position( |
|
1033 |
(0.95, CANVAS_PADDING * graph_ratio)) |
|
1034 |
||
1035 |
# Y coordinate labels are vertical and in figure left side |
|
1036 |
self.AxesLabels[1].set_position( |
|
1037 |
(0.05, 2 * CANVAS_PADDING * graph_ratio)) |
|
1038 |
self.Labels[1].set_position( |
|
1039 |
(0.05, 1.0 - CANVAS_PADDING * graph_ratio)) |
|
1040 |
||
1041 |
# Update subplots |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1042 |
self.Figure.subplots_adjust() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1043 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1044 |
def RefreshViewer(self, refresh_graphics=True): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1045 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1046 |
if refresh_graphics: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1047 |
start_tick, end_tick = self.ParentWindow.GetRange() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1048 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1049 |
if self.GraphType == GRAPH_PARALLEL: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1050 |
min_value = max_value = None |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1051 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1052 |
for idx, item in enumerate(self.Items): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1053 |
data = item.GetData(start_tick, end_tick) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1054 |
if data is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1055 |
item_min_value, item_max_value = item.GetValueRange() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1056 |
if min_value is None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1057 |
min_value = item_min_value |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1058 |
elif item_min_value is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1059 |
min_value = min(min_value, item_min_value) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1060 |
if max_value is None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1061 |
max_value = item_max_value |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1062 |
elif item_max_value is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1063 |
max_value = max(max_value, item_max_value) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1064 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1065 |
if len(self.Plots) <= idx: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1066 |
self.Plots.append( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1067 |
self.Axes.plot(data[:, 0], data[:, 1])[0]) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1068 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1069 |
self.Plots[idx].set_data(data[:, 0], data[:, 1]) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1070 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1071 |
if min_value is not None and max_value is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1072 |
y_center = (min_value + max_value) / 2. |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1073 |
y_range = max(1.0, max_value - min_value) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1074 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1075 |
y_center = 0.5 |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1076 |
y_range = 1.0 |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1077 |
x_min, x_max = start_tick, end_tick |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1078 |
y_min, y_max = y_center - y_range * 0.55, y_center + y_range * 0.55 |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1079 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1080 |
if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1081 |
if self.VLine is None: |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1082 |
self.VLine = self.Axes.axvline(self.CursorTick, color=CURSOR_COLOR) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1083 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1084 |
self.VLine.set_xdata((self.CursorTick, self.CursorTick)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1085 |
self.VLine.set_visible(True) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1086 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1087 |
if self.VLine is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1088 |
self.VLine.set_visible(False) |
929
c562031146e4
Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents:
928
diff
changeset
|
1089 |
else: |
1212 | 1090 |
min_start_tick = max(start_tick, self.GetItemsMinCommonTick()) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1091 |
start_tick = max(start_tick, min_start_tick) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1092 |
end_tick = max(end_tick, min_start_tick) |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1093 |
items = self.ItemsDict.values() |
1215 | 1094 |
x_data, x_min, x_max = items[0].OrthogonalDataAndRange(start_tick, end_tick) |
1095 |
y_data, y_min, y_max = items[1].OrthogonalDataAndRange(start_tick, end_tick) |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1096 |
if self.CursorTick is not None: |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1097 |
x_cursor, x_forced = items[0].GetValue(self.CursorTick, raw=True) |
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1098 |
y_cursor, y_forced = items[1].GetValue(self.CursorTick, raw=True) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1099 |
length = 0 |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1100 |
if x_data is not None and y_data is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1101 |
length = min(len(x_data), len(y_data)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1102 |
if len(self.Items) < 3: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1103 |
if x_data is not None and y_data is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1104 |
if len(self.Plots) == 0: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1105 |
self.Plots.append( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1106 |
self.Axes.plot(x_data[:, 1][:length], |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1107 |
y_data[:, 1][:length])[0]) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1108 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1109 |
self.Plots[0].set_data( |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1110 |
x_data[:, 1][:length], |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1111 |
y_data[:, 1][:length]) |
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
1112 |
|
928
a94e7fea7051
Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents:
927
diff
changeset
|
1113 |
if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick: |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1114 |
if self.VLine is None: |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1115 |
self.VLine = self.Axes.axvline(x_cursor, color=CURSOR_COLOR) |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1116 |
else: |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1117 |
self.VLine.set_xdata((x_cursor, x_cursor)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1118 |
if self.HLine is None: |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1119 |
self.HLine = self.Axes.axhline(y_cursor, color=CURSOR_COLOR) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1120 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1121 |
self.HLine.set_ydata((y_cursor, y_cursor)) |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1122 |
self.VLine.set_visible(True) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1123 |
self.HLine.set_visible(True) |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1124 |
else: |
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1125 |
if self.VLine is not None: |
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1126 |
self.VLine.set_visible(False) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1127 |
if self.HLine is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1128 |
self.HLine.set_visible(False) |
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
1129 |
else: |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1130 |
while len(self.Axes.lines) > 0: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1131 |
self.Axes.lines.pop() |
1215 | 1132 |
z_data, z_min, z_max = items[2].OrthogonalDataAndRange(start_tick, end_tick) |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
1133 |
if self.CursorTick is not None: |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1134 |
z_cursor, z_forced = items[2].GetValue(self.CursorTick, raw=True) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1135 |
if x_data is not None and y_data is not None and z_data is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1136 |
length = min(length, len(z_data)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1137 |
self.Axes.plot(x_data[:, 1][:length], |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1138 |
y_data[:, 1][:length], |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1139 |
zs = z_data[:, 1][:length]) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1140 |
self.Axes.set_zlim(z_min, z_max) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1141 |
if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1142 |
for kwargs in [{"xs": numpy.array([x_min, x_max])}, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1143 |
{"ys": numpy.array([y_min, y_max])}, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1144 |
{"zs": numpy.array([z_min, z_max])}]: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1145 |
for param, value in [("xs", numpy.array([x_cursor, x_cursor])), |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1146 |
("ys", numpy.array([y_cursor, y_cursor])), |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1147 |
("zs", numpy.array([z_cursor, z_cursor]))]: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1148 |
kwargs.setdefault(param, value) |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1149 |
kwargs["color"] = CURSOR_COLOR |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1150 |
self.Axes.plot(**kwargs) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1151 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1152 |
self.Axes.set_xlim(x_min, x_max) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1153 |
self.Axes.set_ylim(y_min, y_max) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1154 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1155 |
variable_name_mask = self.ParentWindow.GetVariableNameMask() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1156 |
if self.CursorTick is not None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1157 |
values, forced = apply(zip, [item.GetValue(self.CursorTick) for item in self.Items]) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1158 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1159 |
values, forced = apply(zip, [(item.GetValue(), item.IsForced()) for item in self.Items]) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1160 |
labels = [item.GetVariable(variable_name_mask) for item in self.Items] |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1161 |
styles = map(lambda x: {True: 'italic', False: 'normal'}[x], forced) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1162 |
if self.Is3DCanvas(): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1163 |
for idx, label_func in enumerate([self.Axes.set_xlabel, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1164 |
self.Axes.set_ylabel, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1165 |
self.Axes.set_zlabel]): |
1200
501cb0bb4c05
Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents:
1199
diff
changeset
|
1166 |
label_func(labels[idx], fontdict={'size': 'small','color': COLOR_CYCLE[idx]}) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1167 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1168 |
for label, text in zip(self.AxesLabels, labels): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1169 |
label.set_text(text) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1170 |
for label, value, style in zip(self.Labels, values, styles): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1171 |
label.set_text(value) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1172 |
label.set_style(style) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1173 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1174 |
self.draw() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
1175 |
|
1209 | 1176 |
def draw(self, drawDC=None): |
1177 |
""" |
|
1178 |
Render the figure. |
|
1179 |
""" |
|
1180 |
# Render figure using agg |
|
1181 |
FigureCanvasAgg.draw(self) |
|
1182 |
||
1183 |
# Get bitmap of figure rendered |
|
1184 |
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None) |
|
1185 |
self.bitmap.UseAlpha() |
|
1186 |
||
1187 |
# Create DC for rendering graphics in bitmap |
|
1188 |
destDC = wx.MemoryDC() |
|
1189 |
destDC.SelectObject(self.bitmap) |
|
1190 |
||
1191 |
# Get Graphics Context for DC, for anti-aliased and transparent |
|
1192 |
# rendering |
|
1193 |
destGC = wx.GCDC(destDC) |
|
1194 |
||
1195 |
destGC.BeginDrawing() |
|
1196 |
||
1197 |
# Get canvas size and figure bounding box in canvas |
|
1198 |
width, height = self.GetSize() |
|
1199 |
bbox = self.GetAxesBoundingBox() |
|
1200 |
||
1201 |
# If highlight to display is resize, draw thick grey line at bottom |
|
1202 |
# side of canvas |
|
1203 |
if self.Highlight == HIGHLIGHT_RESIZE: |
|
1204 |
destGC.SetPen(HIGHLIGHT_RESIZE_PEN) |
|
1205 |
destGC.SetBrush(HIGHLIGHT_RESIZE_BRUSH) |
|
1206 |
destGC.DrawRectangle(0, height - 5, width, 5) |
|
1207 |
||
1208 |
# If highlight to display is merging graph, draw 50% transparent blue |
|
1209 |
# rectangle on left or right part of figure depending on highlight type |
|
1210 |
elif self.Highlight in [HIGHLIGHT_LEFT, HIGHLIGHT_RIGHT]: |
|
1211 |
destGC.SetPen(HIGHLIGHT_DROP_PEN) |
|
1212 |
destGC.SetBrush(HIGHLIGHT_DROP_BRUSH) |
|
1213 |
||
1214 |
x_offset = (bbox.width / 2 |
|
1215 |
if self.Highlight == HIGHLIGHT_RIGHT |
|
1216 |
else 0) |
|
1217 |
destGC.DrawRectangle(bbox.x + x_offset, bbox.y, |
|
1218 |
bbox.width / 2, bbox.height) |
|
1219 |
||
1220 |
# Draw other Viewer common elements |
|
1221 |
self.DrawCommonElements(destGC, self.GetButtons()) |
|
1222 |
||
1223 |
destGC.EndDrawing() |
|
1224 |
||
1225 |
self._isDrawn = True |
|
1226 |
self.gui_repaint(drawDC=drawDC) |
|
1227 |
||
1228 |