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