controls/DebugVariablePanel/DebugVariableGraphicViewer.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 20 Aug 2024 00:35:00 +0200
changeset 3972 5d46adf7bbba
parent 3871 5d23a47937c4
permissions -rw-r--r--
IDE: Workaround some reported WxPython/MacOS problems.

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