controls/DebugVariablePanel.py
author Laurent Bessard
Wed, 29 May 2013 12:51:31 +0200
changeset 1192 d8783c0c7d80
parent 1191 5237f87e035f
permissions -rw-r--r--
Fixed bugs in DebugVariablePanel with ticktime modifications
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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
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
    25
from types import TupleType, ListType, FloatType
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
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    27
import math
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    28
import numpy
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    29
import binascii
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
import wx.lib.buttons
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    33
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    34
try:
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    35
    import matplotlib
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    36
    matplotlib.use('WX')
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    37
    import matplotlib.pyplot
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
    38
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
    39
    from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
    40
    from matplotlib.backends.backend_agg import FigureCanvasAgg
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    41
    from mpl_toolkits.mplot3d import Axes3D
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
    42
    color_cycle = ['r', 'b', 'g', 'm', 'y', 'k']
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
    43
    cursor_color = '#800080'
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    44
    USE_MPL = True
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    45
except:
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
    46
    USE_MPL = False
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    47
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1174
diff changeset
    48
from graphics.DebugDataConsumer import DebugDataConsumer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1174
diff changeset
    49
from editors.DebugViewer import DebugViewer, REFRESH_PERIOD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
from controls import CustomGrid, CustomTable
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
from dialogs.ForceVariableDialog import ForceVariableDialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
def AppendMenu(parent, help, id, kind, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
    parent.Append(help=help, id=id, kind=kind, text=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
def GetDebugVariablesTableColnames():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
    _ = lambda x : x
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    59
    return [_("Variable"), _("Value")]
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    60
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    61
CRC_SIZE = 8
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    62
CRC_MASK = 2 ** CRC_SIZE - 1
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    63
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
class VariableTableItem(DebugDataConsumer):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    66
    def __init__(self, parent, variable):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        DebugDataConsumer.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
        self.Parent = parent
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        self.Variable = variable
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    70
        self.RefreshVariableType()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    71
        self.Value = ""
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    72
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        self.Parent = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
    def SetVariable(self, variable):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        if self.Parent and self.Variable != variable:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
            self.Variable = variable
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    79
            self.RefreshVariableType()
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
    80
            self.Parent.RefreshView()
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
    81
    
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    82
    def GetVariable(self, mask=None):
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
    83
        variable = self.Variable
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    84
        if mask is not None:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    85
            parts = variable.split('.')
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    86
            mask = mask + ['*'] * max(0, len(parts) - len(mask))
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    87
            last = None
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    88
            variable = ""
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    89
            for m, v in zip(mask, parts):
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    90
                if m == '*':
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    91
                    if last == '*':
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    92
                        variable += '.'
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    93
                    variable += v
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    94
                elif last is None or last == '*':
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    95
                    variable += '..'
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
    96
                last = m
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
    97
        return variable
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
    99
    def RefreshVariableType(self):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   100
        self.VariableType = self.Parent.GetDataType(self.Variable)
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
   101
        if USE_MPL:
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
   102
            self.ResetData()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   103
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   104
    def GetVariableType(self):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   105
        return self.VariableType
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   106
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   107
    def GetData(self, start_tick=None, end_tick=None):
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
   108
        if USE_MPL and self.IsNumVariable():
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   109
            if len(self.Data) == 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   110
                return self.Data
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   111
            
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   112
            start_idx = end_idx = None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   113
            if start_tick is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   114
                start_idx = self.GetNearestData(start_tick, -1)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   115
            if end_tick is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   116
                end_idx = self.GetNearestData(end_tick, 1)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   117
            if start_idx is None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   118
                start_idx = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   119
            if end_idx is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   120
                return self.Data[start_idx:end_idx + 1]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   121
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   122
                return self.Data[start_idx:]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   123
            
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   124
        return None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   125
    
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   126
    def GetRawValue(self, idx):
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   127
        if self.VariableType in ["STRING", "WSTRING"] and idx < len(self.RawData):
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   128
            return self.RawData[idx][0]
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   129
        return ""
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   130
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   131
    def GetRange(self):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   132
        return self.MinValue, self.MaxValue
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   133
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   134
    def ResetData(self):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   135
        if self.IsNumVariable():
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   136
            self.Data = numpy.array([]).reshape(0, 3)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   137
            if self.VariableType in ["STRING", "WSTRING"]:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   138
                self.RawData = []
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   139
            self.MinValue = None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   140
            self.MaxValue = None
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   141
        else:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   142
            self.Data = None
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
   143
        self.Value = ""
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   144
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   145
    def IsNumVariable(self):
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   146
        return (self.Parent.IsNumType(self.VariableType) or 
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   147
                self.VariableType in ["STRING", "WSTRING"])
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   148
    
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   149
    def NewValue(self, tick, value, forced=False):
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
   150
        if USE_MPL and self.IsNumVariable():
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   151
            if self.VariableType in ["STRING", "WSTRING"]:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   152
                num_value = binascii.crc32(value) & CRC_MASK
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   153
            else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   154
                num_value = float(value)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   155
            if self.MinValue is None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   156
                self.MinValue = num_value
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   157
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   158
                self.MinValue = min(self.MinValue, num_value)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   159
            if self.MaxValue is None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   160
                self.MaxValue = num_value
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   161
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   162
                self.MaxValue = max(self.MaxValue, num_value)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   163
            forced_value = float(forced)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   164
            if self.VariableType in ["STRING", "WSTRING"]:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   165
                raw_data = (value, forced_value)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   166
                if len(self.RawData) == 0 or self.RawData[-1] != raw_data:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   167
                    extra_value = len(self.RawData)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   168
                    self.RawData.append(raw_data)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   169
                else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   170
                    extra_value = len(self.RawData) - 1
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   171
            else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   172
                extra_value = forced_value
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   173
            self.Data = numpy.append(self.Data, [[float(tick), num_value, extra_value]], axis=0)
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   174
            self.Parent.HasNewData = True
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   175
        DebugDataConsumer.NewValue(self, tick, value, forced)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   176
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
    def SetForced(self, forced):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
        if self.Forced != forced:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
            self.Forced = forced
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
            self.Parent.HasNewData = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
    def SetValue(self, value):
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   183
        if (self.VariableType == "STRING" and value.startswith("'") and value.endswith("'") or
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   184
            self.VariableType == "WSTRING" and value.startswith('"') and value.endswith('"')):
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   185
            value = value[1:-1]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
        if self.Value != value:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
            self.Value = value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
            self.Parent.HasNewData = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
            
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   190
    def GetValue(self, tick=None, raw=False):
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   191
        if tick is not None and self.IsNumVariable():
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   192
            if len(self.Data) > 0:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   193
                idx = numpy.argmin(abs(self.Data[:, 0] - tick))
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   194
                if self.VariableType in ["STRING", "WSTRING"]:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   195
                    value, forced = self.RawData[int(self.Data[idx, 2])]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   196
                    if not raw:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   197
                        if self.VariableType == "STRING":
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   198
                            value = "'%s'" % value
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   199
                        else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   200
                            value = '"%s"' % value
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   201
                    return value, forced
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   202
                else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   203
                    value = self.Data[idx, 1]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   204
                    if not raw and isinstance(value, FloatType):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   205
                        value = "%.6g" % value
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   206
                    return value, self.Data[idx, 2]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   207
            return self.Value, self.IsForced()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   208
        elif not raw:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   209
            if self.VariableType == "STRING":
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   210
                return "'%s'" % self.Value
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   211
            elif self.VariableType == "WSTRING":
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   212
                return '"%s"' % self.Value
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   213
            elif isinstance(self.Value, FloatType):
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   214
                return "%.6g" % self.Value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
        return self.Value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   217
    def GetNearestData(self, tick, adjust):
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
   218
        if USE_MPL and self.IsNumVariable():
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   219
            ticks = self.Data[:, 0]
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   220
            new_cursor = numpy.argmin(abs(ticks - tick))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   221
            if adjust == -1 and ticks[new_cursor] > tick and new_cursor > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   222
                new_cursor -= 1
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   223
            elif adjust == 1 and ticks[new_cursor] < tick and new_cursor < len(ticks):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   224
                new_cursor += 1
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   225
            return new_cursor
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   226
        return None
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   227
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
class DebugVariableTable(CustomTable):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
    def GetValue(self, row, col):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
            return self.GetValueByName(row, self.GetColLabelValue(col, False))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
        return ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
    def SetValue(self, row, col, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
        if col < len(self.colnames):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
            self.SetValueByName(row, self.GetColLabelValue(col, False), value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
    def GetValueByName(self, row, colname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
            if colname == "Variable":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
                return self.data[row].GetVariable()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
            elif colname == "Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
                return self.data[row].GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
        return ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
    def SetValueByName(self, row, colname, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
            if colname == "Variable":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
                self.data[row].SetVariable(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
            elif colname == "Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
                self.data[row].SetValue(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
    def IsForced(self, row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
            return self.data[row].IsForced()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
        return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   259
    def IsNumVariable(self, row):
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   260
        if row < self.GetNumberRows():
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   261
            return self.data[row].IsNumVariable()
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   262
        return False
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   263
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
    def _updateColAttrs(self, grid):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
        wx.grid.Grid -> update the column attributes to add the
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
        appropriate renderer given the column name.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
        Otherwise default to the default renderer.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   270
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   272
        for row in range(self.GetNumberRows()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   273
            for col in range(self.GetNumberCols()):
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   274
                colname = self.GetColLabelValue(col, False)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   275
                if colname == "Value":
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   276
                    if self.IsForced(row):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   277
                        grid.SetCellTextColour(row, col, wx.BLUE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
                    else:
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   279
                        grid.SetCellTextColour(row, col, wx.BLACK)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   280
                grid.SetReadOnly(row, col, True)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
            self.ResizeRow(grid, row)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
    def AppendItem(self, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
        self.data.append(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
    def InsertItem(self, idx, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
        self.data.insert(idx, data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
    def RemoveItem(self, idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
        self.data.pop(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
    def MoveItem(self, idx, new_idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
        self.data.insert(new_idx, self.data.pop(idx))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
    def GetItem(self, idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
        return self.data[idx]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
class DebugVariableDropTarget(wx.TextDropTarget):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
    
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
   300
    def __init__(self, parent, control=None):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
        wx.TextDropTarget.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
        self.ParentWindow = parent
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   303
        self.ParentControl = control
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
    
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
   305
    def __del__(self):
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
   306
        self.ParentWindow = None
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
   307
        self.ParentControl = None
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
   308
    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   309
    def OnDragOver(self, x, y, d):
1008
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
   310
        if not isinstance(self.ParentControl, CustomGrid):
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
   311
            if self.ParentControl is not None:
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
   312
                self.ParentControl.OnMouseDragging(x, y)
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
   313
            else:
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
   314
                self.ParentWindow.RefreshHighlight(x, y)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   315
        return wx.TextDropTarget.OnDragOver(self, x, y, d)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   316
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
    def OnDropText(self, x, y, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
            values = eval(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
        except:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
            message = _("Invalid value \"%s\" for debug variable")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
            values = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
        if not isinstance(values, TupleType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
            message = _("Invalid value \"%s\" for debug variable")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
            values = None
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   327
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
            wx.CallAfter(self.ShowMessage, message)
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   330
        elif values is not None and values[1] == "debug":
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
   331
            if isinstance(self.ParentControl, CustomGrid):
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
   332
                x, y = self.ParentControl.CalcUnscrolledPosition(x, y)
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
   333
                row = self.ParentControl.YToRow(y - self.ParentControl.GetColLabelSize())
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   334
                if row == wx.NOT_FOUND:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   335
                    row = self.ParentWindow.Table.GetNumberRows()
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   336
                self.ParentWindow.InsertValue(values[0], row, force=True)
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
   337
            elif self.ParentControl is not None:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   338
                width, height = self.ParentControl.GetSize()
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
   339
                target_idx = self.ParentControl.GetIndex()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   340
                merge_type = GRAPH_PARALLEL
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   341
                if isinstance(self.ParentControl, DebugVariableGraphic):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   342
                    if self.ParentControl.Is3DCanvas():
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   343
                        if y > height / 2:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   344
                            target_idx += 1
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   345
                        if len(values) > 1 and values[2] == "move":
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   346
                            self.ParentWindow.MoveValue(values[0], target_idx)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   347
                        else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   348
                            self.ParentWindow.InsertValue(values[0], target_idx, force=True)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   349
                        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   350
                    else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   351
                        rect = self.ParentControl.GetAxesBoundingBox()
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   352
                        if rect.InsideXY(x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   353
                            merge_rect = wx.Rect(rect.x, rect.y, rect.width / 2., rect.height)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   354
                            if merge_rect.InsideXY(x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   355
                                merge_type = GRAPH_ORTHOGONAL
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   356
                            wx.CallAfter(self.ParentWindow.MergeGraphs, values[0], target_idx, merge_type, force=True)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   357
                        else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   358
                            if y > height / 2:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   359
                                target_idx += 1
952
c1f901403a34 Fixed bug when drag'n dropping variables from left panel
Laurent Bessard
parents: 946
diff changeset
   360
                            if len(values) > 2 and values[2] == "move":
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   361
                                self.ParentWindow.MoveValue(values[0], target_idx)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   362
                            else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   363
                                self.ParentWindow.InsertValue(values[0], target_idx, force=True)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   364
                else:
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
   365
                    if y > height / 2:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
   366
                        target_idx += 1
952
c1f901403a34 Fixed bug when drag'n dropping variables from left panel
Laurent Bessard
parents: 946
diff changeset
   367
                    if len(values) > 2 and values[2] == "move":
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   368
                        self.ParentWindow.MoveValue(values[0], target_idx)
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
   369
                    else:
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   370
                        self.ParentWindow.InsertValue(values[0], target_idx, force=True)
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   371
                    
952
c1f901403a34 Fixed bug when drag'n dropping variables from left panel
Laurent Bessard
parents: 946
diff changeset
   372
            elif len(values) > 2 and values[2] == "move":
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   373
                self.ParentWindow.MoveValue(values[0])
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   374
            else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   375
                self.ParentWindow.InsertValue(values[0], force=True)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   376
    
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   377
    def OnLeave(self):
1008
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
   378
        if not isinstance(self.ParentControl, CustomGrid):
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
   379
            self.ParentWindow.ResetHighlight()
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   380
        return wx.TextDropTarget.OnLeave(self)
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
   381
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
    def ShowMessage(self, message):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
        dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
        dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
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
   387
if USE_MPL:
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   388
    MILLISECOND = 1000000
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   389
    SECOND = 1000 * MILLISECOND
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
   390
    MINUTE = 60 * SECOND
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
   391
    HOUR = 60 * MINUTE
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   392
    DAY = 24 * HOUR
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
   393
    
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
   394
    ZOOM_VALUES = map(lambda x:("x %.1f" % x, x), [math.sqrt(2) ** i for i in xrange(8)])
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
   395
    RANGE_VALUES = \
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
   396
        [("%dms" % i, i * MILLISECOND) for i in (10, 20, 50, 100, 200, 500)] + \
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
   397
        [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
   398
        [("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
   399
        [("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
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
   400
    
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
   401
    GRAPH_PARALLEL, GRAPH_ORTHOGONAL = range(2)
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
   402
    
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
   403
    SCROLLBAR_UNIT = 10
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
   404
    
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   405
    #CANVAS_HIGHLIGHT_TYPES
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   406
    [HIGHLIGHT_NONE,
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   407
     HIGHLIGHT_BEFORE,
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   408
     HIGHLIGHT_AFTER,
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   409
     HIGHLIGHT_LEFT,
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   410
     HIGHLIGHT_RIGHT,
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   411
     HIGHLIGHT_RESIZE] = range(6)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   412
    
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   413
    HIGHLIGHT_DROP_PEN = wx.Pen(wx.Colour(0, 128, 255))
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   414
    HIGHLIGHT_DROP_BRUSH = wx.Brush(wx.Colour(0, 128, 255, 128))
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   415
    HIGHLIGHT_RESIZE_PEN = wx.Pen(wx.Colour(200, 200, 200))
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   416
    HIGHLIGHT_RESIZE_BRUSH = wx.Brush(wx.Colour(200, 200, 200))
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   417
    
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   418
    #CANVAS_SIZE_TYPES
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   419
    [SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = [0, 100, 200]
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   420
    
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   421
    DEFAULT_CANVAS_HEIGHT = 200.
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   422
    CANVAS_BORDER = (20., 10.)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   423
    CANVAS_PADDING = 8.5
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   424
    VALUE_LABEL_HEIGHT = 17.
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   425
    AXES_LABEL_HEIGHT = 12.75
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   426
    
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   427
    def compute_mask(x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   428
        mask = []
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   429
        for xp, yp in zip(x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   430
            if xp == yp:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   431
                mask.append(xp)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   432
            else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   433
                mask.append("*")
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   434
        return mask
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   435
    
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
   436
    def NextTick(variables):
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
   437
        next_tick = None
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
   438
        for item, data in variables:
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
   439
            if len(data) > 0:
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
   440
                if next_tick is None:
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
   441
                    next_tick = data[0][0]
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
   442
                else:
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
   443
                    next_tick = min(next_tick, data[0][0])
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
   444
        return next_tick
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
   445
    
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
   446
    def OrthogonalData(item, start_tick, end_tick):
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
   447
        data = item.GetData(start_tick, end_tick)
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
   448
        min_value, max_value = item.GetRange()
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
   449
        if min_value is not None and max_value is not None:
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
   450
            center = (min_value + max_value) / 2.
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
   451
            range = max(1.0, max_value - min_value)
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
   452
        else:
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
   453
            center = 0.5
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
   454
            range = 1.0
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
   455
        return data, center - range * 0.55, center + range * 0.55
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
   456
    
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   457
    class GraphButton():
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   458
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   459
        def __init__(self, x, y, bitmap, callback):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   460
            self.Position = wx.Point(x, y)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   461
            self.Bitmap = bitmap
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   462
            self.Shown = True
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   463
            self.Enabled = True
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   464
            self.Callback = callback
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   465
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   466
        def __del__(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   467
            self.callback = None
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   468
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   469
        def GetSize(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   470
            return self.Bitmap.GetSize()
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   471
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   472
        def SetPosition(self, x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   473
            self.Position = wx.Point(x, y)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   474
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   475
        def Show(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   476
            self.Shown = True
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   477
            
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   478
        def Hide(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   479
            self.Shown = False
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   480
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   481
        def IsShown(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   482
            return self.Shown
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   483
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   484
        def Enable(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   485
            self.Enabled = True
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   486
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   487
        def Disable(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   488
            self.Enabled = False
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   489
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   490
        def IsEnabled(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   491
            return self.Enabled
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   492
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   493
        def HitTest(self, x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   494
            if self.Shown and self.Enabled:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   495
                w, h = self.Bitmap.GetSize()
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   496
                rect = wx.Rect(self.Position.x, self.Position.y, w, h)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   497
                if rect.InsideXY(x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   498
                    return True
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   499
            return False
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   500
        
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   501
        def ProcessCallback(self):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   502
            if self.Callback is not None:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   503
                wx.CallAfter(self.Callback)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   504
                
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   505
        def Draw(self, dc):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   506
            if self.Shown and self.Enabled:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   507
                dc.DrawBitmap(self.Bitmap, self.Position.x, self.Position.y, True)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   508
    
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   509
    class DebugVariableViewer:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   510
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   511
        def __init__(self, window, items=[]):
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
   512
            self.ParentWindow = window
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
   513
            self.Items = items
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
   514
            
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   515
            self.Highlight = HIGHLIGHT_NONE
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   516
            self.Buttons = []
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   517
        
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
   518
        def __del__(self):
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
   519
            self.ParentWindow = None
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   520
        
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
   521
        def GetIndex(self):
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
   522
            return self.ParentWindow.GetViewerIndex(self)
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
   523
        
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
   524
        def GetItem(self, variable):
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
   525
            for item in self.Items:
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
   526
                if item.GetVariable() == variable:
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
   527
                    return item
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
   528
            return None
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
   529
        
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
   530
        def GetItems(self):
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
   531
            return self.Items
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
   532
        
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
   533
        def GetVariables(self):
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
   534
            if len(self.Items) > 1:
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
   535
                variables = [item.GetVariable() for item in self.Items]
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
   536
                if self.GraphType == GRAPH_ORTHOGONAL:
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
   537
                    return tuple(variables)
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
   538
                return variables
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
   539
            return self.Items[0].GetVariable()
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
   540
        
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
   541
        def AddItem(self, item):
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
   542
            self.Items.append(item)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   543
            
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
   544
        def RemoveItem(self, item):
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
   545
            if item in self.Items:
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
   546
                self.Items.remove(item)
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
   547
            
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
   548
        def Clear(self):
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
   549
            for item in self.Items:
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
   550
                self.ParentWindow.RemoveDataConsumer(item)
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
   551
            self.Items = []
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   552
            
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
   553
        def IsEmpty(self):
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
   554
            return len(self.Items) == 0
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
   555
        
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
   556
        def UnregisterObsoleteData(self):
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
   557
            for item in self.Items[:]:
1102
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
   558
                iec_path = item.GetVariable()
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
   559
                if self.ParentWindow.GetDataType(iec_path) is None:
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
   560
                    self.ParentWindow.RemoveDataConsumer(item)
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
   561
                    self.RemoveItem(item)
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
   562
                else:
1102
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
   563
                    self.ParentWindow.AddDataConsumer(iec_path.upper(), item)
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
   564
                    item.RefreshVariableType()
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   565
            
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
   566
        def ResetData(self):
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
   567
            for item in self.Items:
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
   568
                item.ResetData()
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
   569
        
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   570
        def RefreshViewer(self):
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
   571
            pass
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   572
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   573
        def SetHighlight(self, highlight):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   574
            if self.Highlight != highlight:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   575
                self.Highlight = highlight
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   576
                return True
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   577
            return False
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   578
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   579
        def GetButtons(self):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   580
            return self.Buttons
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   581
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   582
        def HandleButtons(self, x, y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   583
            for button in self.GetButtons():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   584
                if button.HitTest(x, y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   585
                    button.ProcessCallback()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   586
                    return True
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   587
            return False
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   588
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   589
        def IsOverButton(self, x, y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   590
            for button in self.GetButtons():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   591
                if button.HitTest(x, y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   592
                    return True
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   593
            return False
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   594
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   595
        def ShowButtons(self, show):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   596
            for button in self.Buttons:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   597
                if show:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   598
                    button.Show()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   599
                else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   600
                    button.Hide()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   601
            self.RefreshButtonsState()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   602
            self.ParentWindow.ForceRefresh()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   603
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   604
        def RefreshButtonsState(self, refresh_positions=False):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   605
            if self:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   606
                width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   607
                if refresh_positions:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   608
                    offset = 0
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   609
                    buttons = self.Buttons[:]
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   610
                    buttons.reverse()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   611
                    for button in buttons:
1044
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
   612
                        w, h = button.GetSize()
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
   613
                        button.SetPosition(width - 5 - w - offset, 5)
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
   614
                        offset += w + 2
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   615
                    self.ParentWindow.ForceRefresh()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   616
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   617
        def DrawCommonElements(self, dc, buttons=None):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   618
            width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   619
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   620
            dc.SetPen(HIGHLIGHT_DROP_PEN)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   621
            dc.SetBrush(HIGHLIGHT_DROP_BRUSH)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   622
            if self.Highlight in [HIGHLIGHT_BEFORE]:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   623
                dc.DrawLine(0, 1, width - 1, 1)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   624
            elif self.Highlight in [HIGHLIGHT_AFTER]:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   625
                dc.DrawLine(0, height - 1, width - 1, height - 1)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   626
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   627
            if buttons is None:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   628
                buttons = self.Buttons
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   629
            for button in buttons:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   630
                button.Draw(dc)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   631
                
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   632
            if self.ParentWindow.IsDragging():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   633
                destBBox = self.ParentWindow.GetDraggingAxesClippingRegion(self)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   634
                srcPos = self.ParentWindow.GetDraggingAxesPosition(self)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   635
                if destBBox.width > 0 and destBBox.height > 0:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   636
                    srcPanel = self.ParentWindow.DraggingAxesPanel
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   637
                    srcBBox = srcPanel.GetAxesBoundingBox()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   638
                    
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   639
                    if destBBox.x == 0:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   640
                        srcX = srcBBox.x - srcPos.x
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   641
                    else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   642
                        srcX = srcBBox.x
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   643
                    if destBBox.y == 0:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   644
                        srcY = srcBBox.y - srcPos.y
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   645
                    else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   646
                        srcY = srcBBox.y
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   647
                    
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   648
                    srcBmp = _convert_agg_to_wx_bitmap(srcPanel.get_renderer(), None)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   649
                    srcDC = wx.MemoryDC()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   650
                    srcDC.SelectObject(srcBmp)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   651
                    
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   652
                    dc.Blit(destBBox.x, destBBox.y, 
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   653
                            int(destBBox.width), int(destBBox.height), 
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   654
                            srcDC, srcX, srcY)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   655
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   656
        def OnEnter(self, event):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   657
            self.ShowButtons(True)
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
   658
            event.Skip()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   659
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   660
        def OnLeave(self, event):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   661
            if self.Highlight != HIGHLIGHT_RESIZE or self.CanvasStartSize is None:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   662
                x, y = event.GetPosition()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   663
                width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   664
                if (x <= 0 or x >= width - 1 or
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   665
                    y <= 0 or y >= height - 1):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   666
                    self.ShowButtons(False)
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
   667
            event.Skip()
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
   668
        
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   669
        def OnCloseButton(self):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   670
            wx.CallAfter(self.ParentWindow.DeleteValue, self)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   671
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   672
        def OnForceButton(self):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   673
            wx.CallAfter(self.ForceValue, self.Items[0])
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   674
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   675
        def OnReleaseButton(self):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   676
            wx.CallAfter(self.ReleaseValue, self.Items[0])
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   677
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   678
        def OnResizeWindow(self, event):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   679
            wx.CallAfter(self.RefreshButtonsState, True)
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
   680
            event.Skip()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   681
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   682
        def OnMouseDragging(self, x, y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   683
            xw, yw = self.GetPosition()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   684
            self.ParentWindow.RefreshHighlight(x + xw, y + yw)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   685
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   686
        def OnDragging(self, x, y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   687
            width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   688
            if y < height / 2:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   689
                if self.ParentWindow.IsViewerFirst(self):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   690
                    self.SetHighlight(HIGHLIGHT_BEFORE)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   691
                else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   692
                    self.SetHighlight(HIGHLIGHT_NONE)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   693
                    self.ParentWindow.HighlightPreviousViewer(self)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   694
            else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   695
                self.SetHighlight(HIGHLIGHT_AFTER)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   696
        
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
   697
        def OnEraseBackground(self, event):
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
   698
            pass
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
   699
        
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   700
        def OnResize(self, event):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   701
            wx.CallAfter(self.RefreshButtonsState, True)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   702
            event.Skip()
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
   703
        
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
   704
        def ForceValue(self, item):
1102
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
   705
            iec_path = item.GetVariable()
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
   706
            iec_type = self.ParentWindow.GetDataType(iec_path)
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
   707
            if iec_type is not None:
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
   708
                dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
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
   709
                if dialog.ShowModal() == wx.ID_OK:
1102
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
   710
                    self.ParentWindow.ForceDataValue(iec_path.upper(), dialog.GetValue())
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
   711
        
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
   712
        def ReleaseValue(self, item):
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
   713
            iec_path = item.GetVariable().upper()
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
   714
            self.ParentWindow.ReleaseDataValue(iec_path)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   715
    
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   716
    
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   717
    class DebugVariableText(DebugVariableViewer, wx.Panel):
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
   718
        
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   719
        def __init__(self, parent, window, items=[]):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   720
            DebugVariableViewer.__init__(self, window, items)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   721
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   722
            wx.Panel.__init__(self, parent)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   723
            self.SetBackgroundColour(wx.WHITE)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   724
            self.SetDropTarget(DebugVariableDropTarget(window, self))
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   725
            self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   726
            self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   727
            self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   728
            self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   729
            self.Bind(wx.EVT_SIZE, self.OnResize)
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
   730
            self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   731
            self.Bind(wx.EVT_PAINT, self.OnPaint)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   732
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   733
            self.SetMinSize(wx.Size(0, 25))
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   734
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   735
            self.Buttons.append(
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   736
                GraphButton(0, 0, GetBitmap("force"), self.OnForceButton))
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   737
            self.Buttons.append(
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   738
                GraphButton(0, 0, GetBitmap("release"), self.OnReleaseButton))
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   739
            self.Buttons.append(
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   740
                GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton))
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   741
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   742
            self.ShowButtons(False)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   743
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   744
        def RefreshViewer(self):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   745
            width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   746
            bitmap = wx.EmptyBitmap(width, height)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   747
            
946
9343740603f5 Fix bug on Windows with wxPaintDC
Laurent Bessard
parents: 945
diff changeset
   748
            dc = wx.BufferedDC(wx.ClientDC(self), bitmap)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   749
            dc.Clear()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   750
            dc.BeginDrawing()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   751
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   752
            gc = wx.GCDC(dc)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   753
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   754
            item_name = self.Items[0].GetVariable(self.ParentWindow.GetVariableNameMask())
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   755
            w, h = gc.GetTextExtent(item_name)
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   756
            gc.DrawText(item_name, 20, (height - h) / 2)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   757
            
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
   758
            if self.Items[0].IsForced():
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   759
                gc.SetTextForeground(wx.BLUE)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   760
                self.Buttons[0].Disable()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   761
                self.Buttons[1].Enable()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   762
            else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   763
                self.Buttons[1].Disable()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   764
                self.Buttons[0].Enable()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   765
            self.RefreshButtonsState(True)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   766
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   767
            item_value = self.Items[0].GetValue()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   768
            w, h = gc.GetTextExtent(item_value)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   769
            gc.DrawText(item_value, width - 40 - w, (height - h) / 2)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   770
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   771
            self.DrawCommonElements(gc)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   772
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   773
            gc.EndDrawing()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   774
        
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   775
        def OnLeftDown(self, event):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   776
            width, height = self.GetSize()
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   777
            item_name = self.Items[0].GetVariable(self.ParentWindow.GetVariableNameMask())
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   778
            w, h = self.GetTextExtent(item_name)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   779
            x, y = event.GetPosition()
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   780
            rect = wx.Rect(20, (height - h) / 2, w, h)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   781
            if rect.InsideXY(x, y):
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   782
                data = wx.TextDataObject(str((self.Items[0].GetVariable(), "debug", "move")))
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   783
                dragSource = wx.DropSource(self)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   784
                dragSource.SetData(data)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   785
                dragSource.DoDragDrop()
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   786
            else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   787
                event.Skip()
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   788
        
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   789
        def OnLeftUp(self, event):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   790
            x, y = event.GetPosition()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   791
            wx.CallAfter(self.HandleButtons, x, y)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   792
            event.Skip()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   793
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   794
        def OnPaint(self, event):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   795
            self.RefreshViewer()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   796
            event.Skip()
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
   797
    
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   798
    class DebugVariableGraphic(DebugVariableViewer, FigureCanvas):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   799
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   800
        def __init__(self, parent, window, items, graph_type):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   801
            DebugVariableViewer.__init__(self, window, items)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   802
            
1044
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
   803
            self.CanvasSize = SIZE_MINI
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   804
            self.GraphType = graph_type
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   805
            self.CursorTick = None
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   806
            self.MouseStartPos = None
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   807
            self.StartCursorTick = None
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   808
            self.CanvasStartSize = None
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   809
            self.ContextualButtons = []
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   810
            self.ContextualButtonsItem = None
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   811
            
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   812
            self.Figure = matplotlib.figure.Figure(facecolor='w')
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   813
            self.Figure.subplotpars.update(top=0.95, left=0.1, bottom=0.1, right=0.95)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   814
            
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   815
            FigureCanvas.__init__(self, parent, -1, self.Figure)
1190
410b519abd66 Fixed bug keyboard events not catch by graphs when trying to move cursor on Windows
Laurent Bessard
parents: 1176
diff changeset
   816
            self.SetWindowStyle(wx.WANTS_CHARS)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   817
            self.SetBackgroundColour(wx.WHITE)
1174
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
   818
            self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   819
            self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   820
            self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
   821
            self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   822
            self.Bind(wx.EVT_SIZE, self.OnResize)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   823
            
1043
b46e45e0afc7 Fixed bug in graph panel default size in DebugVariablePanel
Laurent Bessard
parents: 1041
diff changeset
   824
            canvas_size = self.GetCanvasMinSize()
b46e45e0afc7 Fixed bug in graph panel default size in DebugVariablePanel
Laurent Bessard
parents: 1041
diff changeset
   825
            self.SetMinSize(canvas_size)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   826
            self.SetDropTarget(DebugVariableDropTarget(self.ParentWindow, self))
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   827
            self.mpl_connect('button_press_event', self.OnCanvasButtonPressed)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   828
            self.mpl_connect('motion_notify_event', self.OnCanvasMotion)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   829
            self.mpl_connect('button_release_event', self.OnCanvasButtonReleased)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   830
            self.mpl_connect('scroll_event', self.OnCanvasScroll)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   831
            
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   832
            for size, bitmap in zip([SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI],
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   833
                                    ["minimize_graph", "middle_graph", "maximize_graph"]):
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   834
                self.Buttons.append(GraphButton(0, 0, GetBitmap(bitmap), self.GetOnChangeSizeButton(size)))
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   835
            self.Buttons.append(
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   836
                GraphButton(0, 0, GetBitmap("export_graph_mini"), self.OnExportGraphButton))
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   837
            self.Buttons.append(
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   838
                GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton))
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   839
            
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   840
            self.ResetGraphics()
1043
b46e45e0afc7 Fixed bug in graph panel default size in DebugVariablePanel
Laurent Bessard
parents: 1041
diff changeset
   841
            self.RefreshLabelsPosition(canvas_size.height)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   842
            self.ShowButtons(False)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   843
        
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
   844
        def draw(self, drawDC=None):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
   845
            FigureCanvasAgg.draw(self)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
   846
    
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
   847
            self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   848
            self.bitmap.UseAlpha() 
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   849
            width, height = self.GetSize()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   850
            bbox = self.GetAxesBoundingBox()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   851
            
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   852
            destDC = wx.MemoryDC()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   853
            destDC.SelectObject(self.bitmap)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   854
            
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   855
            destGC = wx.GCDC(destDC)
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   856
            
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   857
            destGC.BeginDrawing()
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   858
            if self.Highlight == HIGHLIGHT_RESIZE:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   859
                destGC.SetPen(HIGHLIGHT_RESIZE_PEN)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   860
                destGC.SetBrush(HIGHLIGHT_RESIZE_BRUSH)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   861
                destGC.DrawRectangle(0, height - 5, width, 5)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   862
            else:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   863
                destGC.SetPen(HIGHLIGHT_DROP_PEN)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   864
                destGC.SetBrush(HIGHLIGHT_DROP_BRUSH)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   865
                if self.Highlight == HIGHLIGHT_LEFT:
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   866
                    destGC.DrawRectangle(bbox.x, bbox.y, 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   867
                                         bbox.width / 2, bbox.height)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   868
                elif self.Highlight == HIGHLIGHT_RIGHT:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   869
                    destGC.DrawRectangle(bbox.x + bbox.width / 2, bbox.y, 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   870
                                         bbox.width / 2, bbox.height)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   871
            
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   872
            self.DrawCommonElements(destGC, self.Buttons + self.ContextualButtons)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   873
            
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   874
            destGC.EndDrawing()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   875
            
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
   876
            self._isDrawn = True
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
   877
            self.gui_repaint(drawDC=drawDC)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   878
        
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   879
        def GetButtons(self):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   880
            return self.Buttons + self.ContextualButtons
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   881
        
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   882
        def PopupContextualButtons(self, item, rect, style=wx.RIGHT):
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   883
            if self.ContextualButtonsItem is not None and item != self.ContextualButtonsItem:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   884
                self.DismissContextualButtons()
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   885
            
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   886
            if self.ContextualButtonsItem is None:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   887
                self.ContextualButtonsItem = item
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   888
                
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   889
                if self.ContextualButtonsItem.IsForced():
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   890
                    self.ContextualButtons.append(
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   891
                        GraphButton(0, 0, GetBitmap("release"), self.OnReleaseButton))
1044
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
   892
                self.ContextualButtons.append(
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
   893
                    GraphButton(0, 0, GetBitmap("force"), self.OnForceButton))
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   894
                self.ContextualButtons.append(
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   895
                    GraphButton(0, 0, GetBitmap("export_graph_mini"), self.OnExportItemGraphButton))
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   896
                self.ContextualButtons.append(
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   897
                    GraphButton(0, 0, GetBitmap("delete_graph"), self.OnRemoveItemButton))
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   898
                
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   899
                offset = 0
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   900
                buttons = self.ContextualButtons[:]
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   901
                if style in [wx.TOP, wx.LEFT]:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   902
                     buttons.reverse()
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   903
                for button in buttons:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   904
                    w, h = button.GetSize()
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   905
                    if style in [wx.LEFT, wx.RIGHT]:
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   906
                        if style == wx.LEFT:
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   907
                            x = rect.x - w - offset
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   908
                        else:
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   909
                            x = rect.x + rect.width + offset
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   910
                        y = rect.y + (rect.height - h) / 2
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   911
                        offset += w
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   912
                    else:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   913
                        x = rect.x + (rect.width - w ) / 2
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   914
                        if style == wx.TOP:
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   915
                            y = rect.y - h - offset
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   916
                        else:
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
   917
                            y = rect.y + rect.height + offset
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   918
                        offset += h
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   919
                    button.SetPosition(x, y)
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
   920
                self.ParentWindow.ForceRefresh()
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   921
        
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   922
        def DismissContextualButtons(self):
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   923
            if self.ContextualButtonsItem is not None:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   924
                self.ContextualButtonsItem = None
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   925
                self.ContextualButtons = []
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
   926
                self.ParentWindow.ForceRefresh()
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   927
        
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   928
        def IsOverContextualButton(self, x, y):
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   929
            for button in self.ContextualButtons:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   930
                if button.HitTest(x, y):
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   931
                    return True
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   932
            return False
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   933
        
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   934
        def SetMinSize(self, size):
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   935
            wx.Window.SetMinSize(self, size)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   936
            wx.CallAfter(self.RefreshButtonsState)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   937
        
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   938
        def GetOnChangeSizeButton(self, size):
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   939
            def OnChangeSizeButton():
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   940
                self.CanvasSize = size
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   941
                self.SetCanvasSize(200, self.CanvasSize)
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   942
            return OnChangeSizeButton
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   943
        
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   944
        def OnExportGraphButton(self):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   945
            self.ExportGraph()
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   946
        
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   947
        def OnForceButton(self):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   948
            wx.CallAfter(self.ForceValue, 
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   949
                         self.ContextualButtonsItem)
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   950
            self.DismissContextualButtons()
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   951
            
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   952
        def OnReleaseButton(self):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   953
            wx.CallAfter(self.ReleaseValue, 
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   954
                         self.ContextualButtonsItem)
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   955
            self.DismissContextualButtons()
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   956
        
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   957
        def OnExportItemGraphButton(self):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   958
            wx.CallAfter(self.ExportGraph, 
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   959
                         self.ContextualButtonsItem)
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   960
            self.DismissContextualButtons()
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   961
            
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   962
        def OnRemoveItemButton(self):            
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
   963
            wx.CallAfter(self.ParentWindow.DeleteValue, self, 
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   964
                         self.ContextualButtonsItem)
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   965
            self.DismissContextualButtons()
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
   966
        
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   967
        def RefreshLabelsPosition(self, height):
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   968
            canvas_ratio = 1. / height
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   969
            graph_ratio = 1. / ((1.0 - (CANVAS_BORDER[0] + CANVAS_BORDER[1]) * canvas_ratio) * height)
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   970
            
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   971
            self.Figure.subplotpars.update(
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   972
                top= 1.0 - CANVAS_BORDER[1] * canvas_ratio, 
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   973
                bottom= CANVAS_BORDER[0] * canvas_ratio)
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   974
            
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   975
            if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas():
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   976
                num_item = len(self.Items)
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   977
                for idx in xrange(num_item):
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   978
                    if not self.Is3DCanvas():
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   979
                        self.AxesLabels[idx].set_position(
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   980
                            (0.05, 
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   981
                             1.0 - (CANVAS_PADDING + AXES_LABEL_HEIGHT * idx) * graph_ratio))
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   982
                    self.Labels[idx].set_position(
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   983
                        (0.95, 
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   984
                         CANVAS_PADDING * graph_ratio + 
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   985
                         (num_item - idx - 1) * VALUE_LABEL_HEIGHT * graph_ratio))
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   986
            else:
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   987
                self.AxesLabels[0].set_position((0.1, CANVAS_PADDING * graph_ratio))
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   988
                self.Labels[0].set_position((0.95, CANVAS_PADDING * graph_ratio))
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   989
                self.AxesLabels[1].set_position((0.05, 2 * CANVAS_PADDING * graph_ratio))
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   990
                self.Labels[1].set_position((0.05, 1.0 - CANVAS_PADDING * graph_ratio))
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   991
        
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
   992
            self.Figure.subplots_adjust()
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   993
        
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   994
        def GetCanvasMinSize(self):
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   995
            return wx.Size(200, 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   996
                           CANVAS_BORDER[0] + CANVAS_BORDER[1] + 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   997
                           2 * CANVAS_PADDING + VALUE_LABEL_HEIGHT * len(self.Items))
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
   998
        
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
   999
        def SetCanvasSize(self, width, height):
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1000
            height = max(height, self.GetCanvasMinSize()[1])
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1001
            self.SetMinSize(wx.Size(width, height))
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
  1002
            self.RefreshLabelsPosition(height)
1044
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
  1003
            self.RefreshButtonsState()
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1004
            self.ParentWindow.RefreshGraphicsSizer()
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1005
            
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1006
        def GetAxesBoundingBox(self, absolute=False):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1007
            width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1008
            ax, ay, aw, ah = self.figure.gca().get_position().bounds
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1009
            bbox = wx.Rect(ax * width, height - (ay + ah) * height - 1,
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1010
                           aw * width + 2, ah * height + 1)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1011
            if absolute:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1012
                xw, yw = self.GetPosition()
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1013
                bbox.x += xw
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1014
                bbox.y += yw
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1015
            return bbox
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1016
        
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1017
        def OnCanvasButtonPressed(self, event):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1018
            width, height = self.GetSize()
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1019
            x, y = event.x, height - event.y
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1020
            if not self.IsOverButton(x, y):
938
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1021
                if event.inaxes == self.Axes:
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1022
                    item_idx = None
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1023
                    for i, t in ([pair for pair in enumerate(self.AxesLabels)] + 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1024
                                 [pair for pair in enumerate(self.Labels)]):
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1025
                        (x0, y0), (x1, y1) = t.get_window_extent().get_points()
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1026
                        rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1027
                        if rect.InsideXY(x, y):
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1028
                            item_idx = i
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1029
                            break
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1030
                    if item_idx is not None:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1031
                        self.ShowButtons(False)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1032
                        self.DismissContextualButtons()
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1033
                        xw, yw = self.GetPosition()
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1034
                        self.ParentWindow.StartDragNDrop(self, 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1035
                            self.Items[item_idx], x + xw, y + yw, x + xw, y + yw)
938
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1036
                    elif not self.Is3DCanvas():
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1037
                        self.MouseStartPos = wx.Point(x, y)
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1038
                        if event.button == 1 and event.inaxes == self.Axes:
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1039
                            self.StartCursorTick = self.CursorTick
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1040
                            self.HandleCursorMove(event)
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1041
                        elif event.button == 2 and self.GraphType == GRAPH_PARALLEL:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1042
                            width, height = self.GetSize()
938
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1043
                            start_tick, end_tick = self.ParentWindow.GetRange()
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1044
                            self.StartCursorTick = start_tick
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1045
                
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1046
                elif event.button == 1 and event.y <= 5:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1047
                    self.MouseStartPos = wx.Point(x, y)
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1048
                    self.CanvasStartSize = self.GetSize()
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1049
        
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1050
        def OnCanvasButtonReleased(self, event):
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1051
            if self.ParentWindow.IsDragging():
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1052
                width, height = self.GetSize()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1053
                xw, yw = self.GetPosition()
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1054
                self.ParentWindow.StopDragNDrop(
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1055
                    self.ParentWindow.DraggingAxesPanel.Items[0].GetVariable(),
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1056
                    xw + event.x, 
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1057
                    yw + height - event.y)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1058
            else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1059
                self.MouseStartPos = None
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1060
                self.StartCursorTick = None
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1061
                self.CanvasStartSize = None
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1062
                width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1063
                self.HandleButtons(event.x, height - event.y)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1064
                if event.y > 5 and self.SetHighlight(HIGHLIGHT_NONE):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1065
                    self.SetCursor(wx.NullCursor)
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1066
                    self.ParentWindow.ForceRefresh()
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
  1067
        
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1068
        def OnCanvasMotion(self, event):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1069
            width, height = self.GetSize()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1070
            if self.ParentWindow.IsDragging():
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1071
                xw, yw = self.GetPosition()
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1072
                self.ParentWindow.MoveDragNDrop(
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1073
                    xw + event.x, 
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1074
                    yw + height - event.y)
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1075
            else:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1076
                if not self.Is3DCanvas():
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1077
                    if event.button == 1 and self.CanvasStartSize is None:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1078
                        if event.inaxes == self.Axes:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1079
                            if self.MouseStartPos is not None:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1080
                                self.HandleCursorMove(event)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1081
                        elif self.MouseStartPos is not None and len(self.Items) == 1:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1082
                            xw, yw = self.GetPosition()
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1083
                            self.ParentWindow.SetCursorTick(self.StartCursorTick)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1084
                            self.ParentWindow.StartDragNDrop(self, 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1085
                                self.Items[0],
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1086
                                event.x + xw, height - event.y + yw, 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1087
                                self.MouseStartPos.x + xw, self.MouseStartPos.y + yw)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1088
                    elif event.button == 2 and self.GraphType == GRAPH_PARALLEL:
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1089
                        start_tick, end_tick = self.ParentWindow.GetRange()
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1090
                        rect = self.GetAxesBoundingBox()
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1091
                        self.ParentWindow.SetCanvasPosition(
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1092
                            self.StartCursorTick + (self.MouseStartPos.x - event.x) *
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1093
                            (end_tick - start_tick) / rect.width)    
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1094
                
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1095
                if event.button == 1 and self.CanvasStartSize is not None:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1096
                    width, height = self.GetSize()
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1097
                    self.SetCanvasSize(width, 
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1098
                        self.CanvasStartSize.height + height - event.y - self.MouseStartPos.y)
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1099
                    
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1100
                elif event.button in [None, "up", "down"]:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1101
                    if self.GraphType == GRAPH_PARALLEL:
938
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1102
                        orientation = [wx.RIGHT] * len(self.AxesLabels) + [wx.LEFT] * len(self.Labels)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1103
                    elif len(self.AxesLabels) > 0:
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1104
                        orientation = [wx.RIGHT, wx.TOP, wx.LEFT, wx.BOTTOM]
938
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1105
                    else:
ef1bfe848bf9 Fixed bug with 3D graphs in debug variable panel
Laurent Bessard
parents: 937
diff changeset
  1106
                        orientation = [wx.LEFT] * len(self.Labels)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1107
                    item_idx = None
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1108
                    item_style = None
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1109
                    for (i, t), style in zip([pair for pair in enumerate(self.AxesLabels)] + 
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1110
                                             [pair for pair in enumerate(self.Labels)], 
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1111
                                             orientation):
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1112
                        (x0, y0), (x1, y1) = t.get_window_extent().get_points()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1113
                        rect = wx.Rect(x0, height - y1, x1 - x0, y1 - y0)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1114
                        if rect.InsideXY(event.x, height - event.y):
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1115
                            item_idx = i
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1116
                            item_style = style
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1117
                            break
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1118
                    if item_idx is not None:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1119
                        self.PopupContextualButtons(self.Items[item_idx], rect, item_style)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1120
                        return 
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1121
                    if not self.IsOverContextualButton(event.x, height - event.y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1122
                        self.DismissContextualButtons()
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1123
                    
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1124
                    if event.y <= 5:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1125
                        if self.SetHighlight(HIGHLIGHT_RESIZE):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1126
                            self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1127
                            self.ParentWindow.ForceRefresh()
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1128
                    else:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1129
                        if self.SetHighlight(HIGHLIGHT_NONE):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1130
                            self.SetCursor(wx.NullCursor)
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1131
                            self.ParentWindow.ForceRefresh()
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1132
        
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1133
        def OnCanvasScroll(self, event):
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1134
            if event.inaxes is not None and event.guiEvent.ControlDown():
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1135
                if self.GraphType == GRAPH_ORTHOGONAL:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1136
                    start_tick, end_tick = self.ParentWindow.GetRange()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1137
                    tick = (start_tick + end_tick) / 2.
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1138
                else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1139
                    tick = event.xdata
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1140
                self.ParentWindow.ChangeRange(int(-event.step) / 3, tick)
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1141
                self.ParentWindow.VetoScrollEvent = True
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1142
        
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1143
        def OnDragging(self, x, y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1144
            width, height = self.GetSize()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1145
            bbox = self.GetAxesBoundingBox()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1146
            if bbox.InsideXY(x, y) and not self.Is3DCanvas():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1147
                rect = wx.Rect(bbox.x, bbox.y, bbox.width / 2, bbox.height)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1148
                if rect.InsideXY(x, y):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1149
                    self.SetHighlight(HIGHLIGHT_LEFT)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1150
                else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1151
                    self.SetHighlight(HIGHLIGHT_RIGHT)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1152
            elif y < height / 2:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1153
                if self.ParentWindow.IsViewerFirst(self):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1154
                    self.SetHighlight(HIGHLIGHT_BEFORE)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1155
                else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1156
                    self.SetHighlight(HIGHLIGHT_NONE)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1157
                    self.ParentWindow.HighlightPreviousViewer(self)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1158
            else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1159
                self.SetHighlight(HIGHLIGHT_AFTER)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1160
        
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1161
        def OnLeave(self, event):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1162
            if self.CanvasStartSize is None and self.SetHighlight(HIGHLIGHT_NONE):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1163
                self.SetCursor(wx.NullCursor)
937
bd6fdbb61784 Added support for changing graph size using handles like sash window
Laurent Bessard
parents: 936
diff changeset
  1164
                self.ParentWindow.ForceRefresh()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1165
            DebugVariableViewer.OnLeave(self, event)
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1166
        
1174
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1167
        KEY_CURSOR_INCREMENT = {
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1168
            wx.WXK_LEFT: -1,
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1169
            wx.WXK_RIGHT: 1,
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1170
            wx.WXK_UP: -10,
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1171
            wx.WXK_DOWN: 10}
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1172
        def OnKeyDown(self, event):
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1173
            if self.CursorTick is not None:
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1174
                self.ParentWindow.MoveCursorTick(
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1175
                    self.KEY_CURSOR_INCREMENT.get(
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1176
                      event.GetKeyCode(), 0))
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1177
            event.Skip()
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1178
        
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1179
        def HandleCursorMove(self, event):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1180
            start_tick, end_tick = self.ParentWindow.GetRange()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1181
            cursor_tick = None
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1182
            if self.GraphType == GRAPH_ORTHOGONAL:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1183
                x_data = self.Items[0].GetData(start_tick, end_tick)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1184
                y_data = self.Items[1].GetData(start_tick, end_tick)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1185
                if len(x_data) > 0 and len(y_data) > 0:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1186
                    length = min(len(x_data), len(y_data))
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1187
                    d = numpy.sqrt((x_data[:length,1]-event.xdata) ** 2 + (y_data[:length,1]-event.ydata) ** 2)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1188
                    cursor_tick = x_data[numpy.argmin(d), 0]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1189
            else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1190
                data = self.Items[0].GetData(start_tick, end_tick)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1191
                if len(data) > 0:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1192
                    cursor_tick = data[numpy.argmin(numpy.abs(data[:,0] - event.xdata)), 0]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1193
            if cursor_tick is not None:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1194
                self.ParentWindow.SetCursorTick(cursor_tick)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1195
        
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1196
        def OnAxesMotion(self, event):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1197
            if self.Is3DCanvas():
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1198
                current_time = gettime()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1199
                if current_time - self.LastMotionTime > REFRESH_PERIOD:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1200
                    self.LastMotionTime = current_time
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1201
                    Axes3D._on_move(self.Axes, event)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1202
        
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
  1203
        def ResetGraphics(self):
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
  1204
            self.Figure.clear()
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
  1205
            if self.Is3DCanvas():
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
  1206
                self.Axes = self.Figure.gca(projection='3d')
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
  1207
                self.Axes.set_color_cycle(['b'])
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
  1208
                self.LastMotionTime = gettime()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1209
                setattr(self.Axes, "_on_move", self.OnAxesMotion)
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
  1210
                self.Axes.mouse_init()
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1211
                self.Axes.tick_params(axis='z', labelsize='small')
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
  1212
            else:
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
  1213
                self.Axes = self.Figure.gca()
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1214
                self.Axes.set_color_cycle(color_cycle)
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1215
            self.Axes.tick_params(axis='x', labelsize='small')
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1216
            self.Axes.tick_params(axis='y', labelsize='small')
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
  1217
            self.Plots = []
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1218
            self.VLine = None
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1219
            self.HLine = None
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1220
            self.Labels = []
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1221
            self.AxesLabels = []
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1222
            if not self.Is3DCanvas():
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1223
                text_func = self.Axes.text
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1224
            else:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1225
                text_func = self.Axes.text2D
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1226
            if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas():
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1227
                num_item = len(self.Items)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1228
                for idx in xrange(num_item):
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1229
                    if num_item == 1:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1230
                        color = 'k'
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1231
                    else:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1232
                        color = color_cycle[idx % len(color_cycle)]
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1233
                    if not self.Is3DCanvas():
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1234
                        self.AxesLabels.append(
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
  1235
                            text_func(0, 0, "", size='small',
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
  1236
                                      verticalalignment='top', 
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1237
                                      color=color,
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1238
                                      transform=self.Axes.transAxes))
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1239
                    self.Labels.append(
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1240
                        text_func(0, 0, "", size='large', 
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1241
                                  horizontalalignment='right',
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1242
                                  color=color,
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1243
                                  transform=self.Axes.transAxes))
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1244
            else:
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1245
                self.AxesLabels.append(
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1246
                    self.Axes.text(0, 0, "", size='small',
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1247
                                   transform=self.Axes.transAxes))
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1248
                self.Labels.append(
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1249
                    self.Axes.text(0, 0, "", size='large',
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1250
                                   horizontalalignment='right',
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1251
                                   transform=self.Axes.transAxes))
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1252
                self.AxesLabels.append(
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1253
                    self.Axes.text(0, 0, "", size='small',
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1254
                                   rotation='vertical',
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1255
                                   verticalalignment='bottom',
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1256
                                   transform=self.Axes.transAxes))
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1257
                self.Labels.append(
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1258
                    self.Axes.text(0, 0, "", size='large',
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1259
                                   rotation='vertical',
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1260
                                   verticalalignment='top',
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1261
                                   transform=self.Axes.transAxes))
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1262
            width, height = self.GetSize()
935
fc1515f27e1f Added button in graph for changing graph size to minimum
Laurent Bessard
parents: 934
diff changeset
  1263
            self.RefreshLabelsPosition(height)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1264
            
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
  1265
        def AddItem(self, item):
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
  1266
            DebugVariableViewer.AddItem(self, item)
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
  1267
            self.ResetGraphics()
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
  1268
            
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
  1269
        def RemoveItem(self, item):
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
  1270
            DebugVariableViewer.RemoveItem(self, item)
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
  1271
            if not self.IsEmpty():
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1272
                if len(self.Items) == 1:
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1273
                    self.GraphType = GRAPH_PARALLEL
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
  1274
                self.ResetGraphics()
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
  1275
        
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
  1276
        def UnregisterObsoleteData(self):
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
  1277
            DebugVariableViewer.UnregisterObsoleteData(self)
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
  1278
            if not self.IsEmpty():
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
  1279
                self.ResetGraphics()
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
  1280
        
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
  1281
        def Is3DCanvas(self):
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
  1282
            return self.GraphType == GRAPH_ORTHOGONAL and len(self.Items) == 3
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
  1283
        
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1284
        def SetCursorTick(self, cursor_tick):
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1285
            self.CursorTick = cursor_tick
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1286
            
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1287
        def RefreshViewer(self, refresh_graphics=True):
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
  1288
            
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
  1289
            if refresh_graphics:
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
  1290
                start_tick, end_tick = self.ParentWindow.GetRange()
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
  1291
                
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
  1292
                if self.GraphType == GRAPH_PARALLEL:    
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
  1293
                    min_value = max_value = None
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
  1294
                    
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
  1295
                    for idx, item in enumerate(self.Items):
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
  1296
                        data = item.GetData(start_tick, end_tick)
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
  1297
                        if data is not None:
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
  1298
                            item_min_value, item_max_value = item.GetRange()
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
  1299
                            if min_value is None:
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
  1300
                                min_value = item_min_value
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
  1301
                            elif item_min_value is not None:
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
  1302
                                min_value = min(min_value, item_min_value)
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
  1303
                            if max_value is None:
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
  1304
                                max_value = item_max_value
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
  1305
                            elif item_max_value is not None:
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
  1306
                                max_value = max(max_value, item_max_value)
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
  1307
                            
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
  1308
                            if len(self.Plots) <= idx:
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
  1309
                                self.Plots.append(
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
  1310
                                    self.Axes.plot(data[:, 0], data[:, 1])[0])
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
  1311
                            else:
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
  1312
                                self.Plots[idx].set_data(data[:, 0], data[:, 1])
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
  1313
                        
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
  1314
                    if min_value is not None and max_value is not None:
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
  1315
                        y_center = (min_value + max_value) / 2.
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
  1316
                        y_range = max(1.0, max_value - min_value)
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
  1317
                    else:
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
  1318
                        y_center = 0.5
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
  1319
                        y_range = 1.0
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
  1320
                    x_min, x_max = start_tick, end_tick
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
  1321
                    y_min, y_max = y_center - y_range * 0.55, y_center + y_range * 0.55
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
  1322
                    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1323
                    if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick:
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1324
                        if self.VLine is None:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1325
                            self.VLine = self.Axes.axvline(self.CursorTick, color=cursor_color)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1326
                        else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1327
                            self.VLine.set_xdata((self.CursorTick, self.CursorTick))
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1328
                        self.VLine.set_visible(True)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1329
                    else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1330
                        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
  1331
                            self.VLine.set_visible(False)
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
  1332
                else:
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
  1333
                    min_start_tick = reduce(max, [item.GetData()[0, 0] 
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
  1334
                                                  for item in self.Items
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
  1335
                                                  if len(item.GetData()) > 0], 0)
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
  1336
                    start_tick = max(start_tick, min_start_tick)
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
  1337
                    end_tick = max(end_tick, min_start_tick)
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
  1338
                    x_data, x_min, x_max = OrthogonalData(self.Items[0], start_tick, end_tick)
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
  1339
                    y_data, y_min, y_max = OrthogonalData(self.Items[1], start_tick, end_tick)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1340
                    if self.CursorTick is not None:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1341
                        x_cursor, x_forced = self.Items[0].GetValue(self.CursorTick, raw=True)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1342
                        y_cursor, y_forced = self.Items[1].GetValue(self.CursorTick, raw=True)
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
  1343
                    length = 0
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
  1344
                    if x_data is not None and y_data is not None:  
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
  1345
                        length = min(len(x_data), len(y_data))
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
  1346
                    if len(self.Items) < 3:
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
  1347
                        if x_data is not None and y_data is not None:
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
  1348
                            if len(self.Plots) == 0:
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
  1349
                                self.Plots.append(
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
  1350
                                    self.Axes.plot(x_data[:, 1][:length], 
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
  1351
                                                   y_data[:, 1][:length])[0])
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
  1352
                            else:
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
  1353
                                self.Plots[0].set_data(
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
  1354
                                    x_data[:, 1][:length], 
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
  1355
                                    y_data[:, 1][:length])
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1356
                        
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1357
                        if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick:
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1358
                            if self.VLine is None:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1359
                                self.VLine = self.Axes.axvline(x_cursor, color=cursor_color)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1360
                            else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1361
                                self.VLine.set_xdata((x_cursor, x_cursor))
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1362
                            if self.HLine is None:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1363
                                self.HLine = self.Axes.axhline(y_cursor, color=cursor_color)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1364
                            else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1365
                                self.HLine.set_ydata((y_cursor, y_cursor))
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1366
                            self.VLine.set_visible(True)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1367
                            self.HLine.set_visible(True)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1368
                        else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1369
                            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
  1370
                                self.VLine.set_visible(False)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1371
                            if self.HLine is not None:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1372
                                self.HLine.set_visible(False)
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
  1373
                    else:
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
  1374
                        while len(self.Axes.lines) > 0:
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
  1375
                            self.Axes.lines.pop()
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
  1376
                        z_data, z_min, z_max = OrthogonalData(self.Items[2], start_tick, end_tick)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1377
                        if self.CursorTick is not None:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1378
                            z_cursor, z_forced = self.Items[2].GetValue(self.CursorTick, raw=True)
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
  1379
                        if x_data is not None and y_data is not None and z_data is not None:
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
  1380
                            length = min(length, len(z_data))
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
  1381
                            self.Axes.plot(x_data[:, 1][:length],
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
  1382
                                           y_data[:, 1][:length],
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
  1383
                                           zs = z_data[:, 1][:length])
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
  1384
                        self.Axes.set_zlim(z_min, z_max)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1385
                        if self.CursorTick is not None and start_tick <= self.CursorTick <= end_tick:
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1386
                            for kwargs in [{"xs": numpy.array([x_min, x_max])},
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1387
                                           {"ys": numpy.array([y_min, y_max])},
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1388
                                           {"zs": numpy.array([z_min, z_max])}]:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1389
                                for param, value in [("xs", numpy.array([x_cursor, x_cursor])),
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1390
                                                     ("ys", numpy.array([y_cursor, y_cursor])),
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1391
                                                     ("zs", numpy.array([z_cursor, z_cursor]))]:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1392
                                    kwargs.setdefault(param, value)
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1393
                                kwargs["color"] = cursor_color
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1394
                                self.Axes.plot(**kwargs)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1395
                    
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
  1396
                self.Axes.set_xlim(x_min, x_max)
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
  1397
                self.Axes.set_ylim(y_min, y_max)
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
  1398
            
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1399
            variable_name_mask = self.ParentWindow.GetVariableNameMask()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1400
            if self.CursorTick is not None:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1401
                values, forced = apply(zip, [item.GetValue(self.CursorTick) for item in self.Items])
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1402
            else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1403
                values, forced = apply(zip, [(item.GetValue(), item.IsForced()) for item in self.Items])
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1404
            labels = [item.GetVariable(variable_name_mask) for item in self.Items]
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1405
            styles = map(lambda x: {True: 'italic', False: 'normal'}[x], forced)
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1406
            if self.Is3DCanvas():
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1407
                for idx, label_func in enumerate([self.Axes.set_xlabel, 
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1408
                                                  self.Axes.set_ylabel,
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1409
                                                  self.Axes.set_zlabel]):
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1410
                    label_func(labels[idx], fontdict={'size': 'small','color': color_cycle[idx]})
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1411
            else:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1412
                for label, text in zip(self.AxesLabels, labels):
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1413
                    label.set_text(text)
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1414
            for label, value, style in zip(self.Labels, values, styles):
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1415
                label.set_text(value)
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 929
diff changeset
  1416
                label.set_style(style)
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1417
            
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1418
            self.draw()
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
  1419
    
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1420
        def ExportGraph(self, item=None):
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1421
            if item is not None:
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1422
                variables = [(item, [entry for entry in item.GetData()])]
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1423
            else:
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1424
                variables = [(item, [entry for entry in item.GetData()])
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1425
                             for item in self.Items]
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1426
            self.ParentWindow.CopyDataToClipboard(variables)
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  1427
    
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
  1428
class DebugVariablePanel(wx.Panel, DebugViewer):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1429
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1430
    def __init__(self, parent, producer, window):
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
  1431
        wx.Panel.__init__(self, parent, style=wx.SP_3D|wx.TAB_TRAVERSAL)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1432
        
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1433
        self.ParentWindow = window
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1434
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1435
        self.HasNewData = False
1008
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
  1436
        self.Force = False
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  1437
        
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
  1438
        if USE_MPL:
1008
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
  1439
            self.SetBackgroundColour(wx.WHITE)
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
  1440
            
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
  1441
            main_sizer = wx.BoxSizer(wx.VERTICAL)
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
  1442
            
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
  1443
            self.Ticks = numpy.array([])
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
  1444
            self.StartTick = 0
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
  1445
            self.Fixed = False
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1446
            self.CursorTick = None
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1447
            self.DraggingAxesPanel = None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1448
            self.DraggingAxesBoundingBox = None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1449
            self.DraggingAxesMousePos = None
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1450
            self.VetoScrollEvent = False
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1451
            self.VariableNameMask = []
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1452
            
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
  1453
            self.GraphicPanels = []
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
  1454
            
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1455
            graphics_button_sizer = wx.BoxSizer(wx.HORIZONTAL)
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
  1456
            main_sizer.AddSizer(graphics_button_sizer, border=5, flag=wx.GROW|wx.ALL)
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
  1457
            
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
  1458
            range_label = wx.StaticText(self, label=_('Range:'))
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1459
            graphics_button_sizer.AddWindow(range_label, flag=wx.ALIGN_CENTER_VERTICAL)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1460
            
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
  1461
            self.CanvasRange = wx.ComboBox(self, style=wx.CB_READONLY)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1462
            self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, self.CanvasRange)
905
eaa1d3a4b52b Fix DebugVariablePanel time range position
Laurent Bessard
parents: 903
diff changeset
  1463
            graphics_button_sizer.AddWindow(self.CanvasRange, 1, 
eaa1d3a4b52b Fix DebugVariablePanel time range position
Laurent Bessard
parents: 903
diff changeset
  1464
                  border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1465
            
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1466
            self.CanvasRange.Clear()
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1467
            default_range_idx = 0
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1468
            for idx, (text, value) in enumerate(RANGE_VALUES):
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1469
                self.CanvasRange.Append(text)
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1470
                if text == "1s":
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1471
                    default_range_idx = idx
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1472
            self.CanvasRange.SetSelection(default_range_idx)
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1473
            
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1474
            for name, bitmap, help in [
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1475
                ("CurrentButton", "current", _("Go to current value")),
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1476
                ("ExportGraphButton", "export_graph", _("Export graph values to clipboard"))]:
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
  1477
                button = wx.lib.buttons.GenBitmapButton(self, 
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1478
                      bitmap=GetBitmap(bitmap), 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1479
                      size=wx.Size(28, 28), style=wx.NO_BORDER)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1480
                button.SetToolTipString(help)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1481
                setattr(self, name, button)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1482
                self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1483
                graphics_button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1484
            
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
  1485
            self.CanvasPosition = wx.ScrollBar(self, 
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1486
                  size=wx.Size(0, 16), style=wx.SB_HORIZONTAL)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1487
            self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1488
                  self.OnPositionChanging, self.CanvasPosition)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1489
            self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1490
                  self.OnPositionChanging, self.CanvasPosition)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1491
            self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1492
                  self.OnPositionChanging, self.CanvasPosition)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1493
            self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1494
                  self.OnPositionChanging, self.CanvasPosition)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1495
            self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, 
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1496
                  self.OnPositionChanging, self.CanvasPosition)
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
  1497
            main_sizer.AddWindow(self.CanvasPosition, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
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
  1498
            
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1499
            self.TickSizer = wx.BoxSizer(wx.HORIZONTAL)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1500
            main_sizer.AddSizer(self.TickSizer, border=5, flag=wx.ALL|wx.GROW)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1501
            
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1502
            self.TickLabel = wx.StaticText(self)
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1503
            self.TickSizer.AddWindow(self.TickLabel, border=5, flag=wx.RIGHT)
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1504
            
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1505
            self.MaskLabel = wx.TextCtrl(self, style=wx.TE_READONLY|wx.TE_CENTER|wx.NO_BORDER)
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  1506
            self.TickSizer.AddWindow(self.MaskLabel, 1, border=5, flag=wx.RIGHT|wx.GROW)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1507
            
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1508
            self.TickTimeLabel = wx.StaticText(self)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1509
            self.TickSizer.AddWindow(self.TickTimeLabel)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1510
            
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
  1511
            self.GraphicsWindow = wx.ScrolledWindow(self, style=wx.HSCROLL|wx.VSCROLL)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1512
            self.GraphicsWindow.SetBackgroundColour(wx.WHITE)
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
  1513
            self.GraphicsWindow.SetDropTarget(DebugVariableDropTarget(self))
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1514
            self.GraphicsWindow.Bind(wx.EVT_ERASE_BACKGROUND, self.OnGraphicsWindowEraseBackground)
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  1515
            self.GraphicsWindow.Bind(wx.EVT_PAINT, self.OnGraphicsWindowPaint)
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
  1516
            self.GraphicsWindow.Bind(wx.EVT_SIZE, self.OnGraphicsWindowResize)
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1517
            self.GraphicsWindow.Bind(wx.EVT_MOUSEWHEEL, self.OnGraphicsWindowMouseWheel)
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  1518
            
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
  1519
            main_sizer.AddWindow(self.GraphicsWindow, 1, flag=wx.GROW)
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
  1520
            
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
  1521
            self.GraphicsSizer = wx.BoxSizer(wx.VERTICAL)
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
  1522
            self.GraphicsWindow.SetSizer(self.GraphicsSizer)
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
  1523
            
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
  1524
        else:
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
  1525
            main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
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
  1526
            main_sizer.AddGrowableCol(0)
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
  1527
            main_sizer.AddGrowableRow(1)
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
  1528
            
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
  1529
            button_sizer = wx.BoxSizer(wx.HORIZONTAL)
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
  1530
            main_sizer.AddSizer(button_sizer, border=5, 
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
  1531
                  flag=wx.ALIGN_RIGHT|wx.ALL)
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
  1532
            
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
  1533
            for name, bitmap, help in [
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
  1534
                    ("DeleteButton", "remove_element", _("Remove debug variable")),
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
  1535
                    ("UpButton", "up", _("Move debug variable up")),
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
  1536
                    ("DownButton", "down", _("Move debug variable down"))]:
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
  1537
                button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), 
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
  1538
                      size=wx.Size(28, 28), style=wx.NO_BORDER)
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
  1539
                button.SetToolTipString(help)
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
  1540
                setattr(self, name, button)
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
  1541
                button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
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
  1542
            
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
  1543
            self.VariablesGrid = CustomGrid(self, size=wx.Size(-1, 150), style=wx.VSCROLL)
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
  1544
            self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self, self.VariablesGrid))
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
  1545
            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, 
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
  1546
                  self.OnVariablesGridCellRightClick)
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
  1547
            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, 
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
  1548
                  self.OnVariablesGridCellLeftClick)
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
  1549
            main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
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
  1550
        
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
  1551
            self.Table = DebugVariableTable(self, [], GetDebugVariablesTableColnames())
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
  1552
            self.VariablesGrid.SetTable(self.Table)
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
  1553
            self.VariablesGrid.SetButtons({"Delete": self.DeleteButton,
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
  1554
                                           "Up": self.UpButton,
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
  1555
                                           "Down": self.DownButton})
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
  1556
        
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
  1557
            def _AddVariable(new_row):
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
  1558
                return self.VariablesGrid.GetGridCursorRow()
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
  1559
            setattr(self.VariablesGrid, "_AddRow", _AddVariable)
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
  1560
        
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
  1561
            def _DeleteVariable(row):
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
  1562
                item = self.Table.GetItem(row)
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
  1563
                self.RemoveDataConsumer(item)
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
  1564
                self.Table.RemoveItem(row)
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
  1565
                self.RefreshView()
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
  1566
            setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
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
  1567
            
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
  1568
            def _MoveVariable(row, move):
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
  1569
                new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1))
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
  1570
                if new_row != row:
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
  1571
                    self.Table.MoveItem(row, new_row)
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
  1572
                    self.RefreshView()
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
  1573
                return new_row
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
  1574
            setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
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
  1575
            
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
  1576
            self.VariablesGrid.SetRowLabelSize(0)
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
  1577
            
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
  1578
            self.GridColSizes = [200, 100]
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
  1579
            
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
  1580
            for col in range(self.Table.GetNumberCols()):
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
  1581
                attr = wx.grid.GridCellAttr()
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
  1582
                attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
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
  1583
                self.VariablesGrid.SetColAttr(col, attr)
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
  1584
                self.VariablesGrid.SetColSize(col, self.GridColSizes[col])
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
  1585
            
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
  1586
            self.Table.ResetView(self.VariablesGrid)
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
  1587
            self.VariablesGrid.RefreshButtons()
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
  1588
        
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1589
        DebugViewer.__init__(self, producer, True)
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1590
        
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
  1591
        self.SetSizer(main_sizer)
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1592
    
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1593
    def SetTickTime(self, ticktime=0):
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1594
        if USE_MPL:
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1595
            self.Ticktime = ticktime
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1596
            if self.Ticktime == 0:
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1597
                self.Ticktime = MILLISECOND
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1598
            self.CurrentRange = RANGE_VALUES[
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1599
                self.CanvasRange.GetSelection()][1] / self.Ticktime
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1600
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1601
    def SetDataProducer(self, producer):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1602
        DebugViewer.SetDataProducer(self, producer)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1603
        
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
  1604
        if USE_MPL:
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
  1605
            if self.DataProducer is not None:
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1606
                self.SetTickTime(self.DataProducer.GetTicktime())
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1607
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1608
    def RefreshNewData(self, *args, **kwargs):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1609
        if self.HasNewData or self.Force:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1610
            self.HasNewData = False
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
  1611
            self.RefreshView(only_values=True)
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1612
        DebugViewer.RefreshNewData(self, *args, **kwargs)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1613
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1614
    def NewDataAvailable(self, tick, *args, **kwargs):
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
  1615
        if USE_MPL and tick is not None:
927
bd3e5b65e8be Fix bug when resetting graphs values
Laurent Bessard
parents: 925
diff changeset
  1616
            if len(self.Ticks) == 0:
bd3e5b65e8be Fix bug when resetting graphs values
Laurent Bessard
parents: 925
diff changeset
  1617
                self.StartTick = tick 
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1618
            self.Ticks = numpy.append(self.Ticks, [tick])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1619
            if not self.Fixed or tick < self.StartTick + self.CurrentRange:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1620
                self.StartTick = max(self.StartTick, tick - self.CurrentRange)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1621
            if self.Fixed and self.Ticks[-1] - self.Ticks[0] < self.CurrentRange:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1622
                self.Force = True
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1623
        DebugViewer.NewDataAvailable(self, tick, *args, **kwargs)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1624
    
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1625
    def ForceRefresh(self):
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1626
        self.Force = True
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1627
        wx.CallAfter(self.NewDataAvailable, None, True)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1628
    
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
  1629
    def RefreshGraphicsSizer(self):
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
  1630
        self.GraphicsSizer.Clear()
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
  1631
        
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
  1632
        for panel in self.GraphicPanels:
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
  1633
            self.GraphicsSizer.AddWindow(panel, flag=wx.GROW)
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
  1634
            
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
  1635
        self.GraphicsSizer.Layout()
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
  1636
        self.RefreshGraphicsWindowScrollbars()
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
  1637
    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1638
    def SetCanvasPosition(self, tick):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1639
        tick = max(self.Ticks[0], min(tick, self.Ticks[-1] - self.CurrentRange))
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1640
        self.StartTick = self.Ticks[numpy.argmin(numpy.abs(self.Ticks - tick))]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1641
        self.Fixed = True
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1642
        self.RefreshCanvasPosition()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1643
        self.ForceRefresh()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1644
    
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1645
    def SetCursorTick(self, cursor_tick):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1646
        self.CursorTick = cursor_tick
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1647
        self.Fixed = True
1084
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  1648
        self.UpdateCursorTick() 
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1649
    
1174
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1650
    def MoveCursorTick(self, move):
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1651
        if self.CursorTick is not None:
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1652
            cursor_tick = max(self.Ticks[0], 
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1653
                          min(self.CursorTick + move, 
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1654
                              self.Ticks[-1]))
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1655
            cursor_tick_idx = numpy.argmin(numpy.abs(self.Ticks - cursor_tick))
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1656
            if self.Ticks[cursor_tick_idx] == self.CursorTick:
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1657
                cursor_tick_idx = max(0, 
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1658
                                  min(cursor_tick_idx + abs(move) / move, 
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1659
                                      len(self.Ticks) - 1))
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1660
            self.CursorTick = self.Ticks[cursor_tick_idx]
1174
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1661
            self.StartTick = max(self.Ticks[
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1662
                                numpy.argmin(numpy.abs(self.Ticks - 
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1663
                                        self.CursorTick + self.CurrentRange))],
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1664
                             min(self.StartTick, self.CursorTick))
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1665
            self.RefreshCanvasPosition()
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1666
            self.UpdateCursorTick() 
9cc1a3fa9619 Add support for moving cursor in Debug Graphs using arrow keys
Laurent Bessard
parents: 1102
diff changeset
  1667
            
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1668
    def ResetCursorTick(self):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1669
        self.CursorTick = None
1084
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  1670
        self.UpdateCursorTick()
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  1671
    
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  1672
    def UpdateCursorTick(self):
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1673
        for panel in self.GraphicPanels:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1674
            if isinstance(panel, DebugVariableGraphic):
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1675
                panel.SetCursorTick(self.CursorTick)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1676
        self.ForceRefresh()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1677
    
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1678
    def StartDragNDrop(self, panel, item, x_mouse, y_mouse, x_mouse_start, y_mouse_start):
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1679
        if len(panel.GetItems()) > 1:
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1680
            self.DraggingAxesPanel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1681
            self.DraggingAxesPanel.SetCursorTick(self.CursorTick)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1682
            width, height = panel.GetSize()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1683
            self.DraggingAxesPanel.SetSize(wx.Size(width, height))
1044
41bd726aa23c Fixed bugs in DebugVariablePanel
Laurent Bessard
parents: 1043
diff changeset
  1684
            self.DraggingAxesPanel.ResetGraphics()
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1685
            self.DraggingAxesPanel.SetPosition(wx.Point(0, -height))
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1686
        else:
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1687
            self.DraggingAxesPanel = panel
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1688
        self.DraggingAxesBoundingBox = panel.GetAxesBoundingBox(absolute=True)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1689
        self.DraggingAxesMousePos = wx.Point(
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1690
            x_mouse_start - self.DraggingAxesBoundingBox.x, 
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1691
            y_mouse_start - self.DraggingAxesBoundingBox.y)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1692
        self.MoveDragNDrop(x_mouse, y_mouse)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1693
        
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1694
    def MoveDragNDrop(self, x_mouse, y_mouse):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1695
        self.DraggingAxesBoundingBox.x = x_mouse - self.DraggingAxesMousePos.x
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1696
        self.DraggingAxesBoundingBox.y = y_mouse - self.DraggingAxesMousePos.y
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1697
        self.RefreshHighlight(x_mouse, y_mouse)
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1698
    
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1699
    def RefreshHighlight(self, x_mouse, y_mouse):
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1700
        for idx, panel in enumerate(self.GraphicPanels):
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1701
            x, y = panel.GetPosition()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1702
            width, height = panel.GetSize()
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1703
            rect = wx.Rect(x, y, width, height)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1704
            if (rect.InsideXY(x_mouse, y_mouse) or 
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1705
                idx == 0 and y_mouse < 0 or
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1706
                idx == len(self.GraphicPanels) - 1 and y_mouse > panel.GetPosition()[1]):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1707
                panel.OnDragging(x_mouse - x, y_mouse - y)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1708
            else:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1709
                panel.SetHighlight(HIGHLIGHT_NONE)
962
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1710
        if wx.Platform == "__WXMSW__":
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1711
            self.RefreshView()
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1712
        else:
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1713
            self.ForceRefresh()
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1714
    
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1715
    def ResetHighlight(self):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  1716
        for panel in self.GraphicPanels:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1717
            panel.SetHighlight(HIGHLIGHT_NONE)
962
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1718
        if wx.Platform == "__WXMSW__":
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1719
            self.RefreshView()
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1720
        else:
c0dcbbdb0bb1 Fix bug on Windows when drag'n dropping variable to DebugVariablePanel, panel not refreshed
Laurent Bessard
parents: 952
diff changeset
  1721
            self.ForceRefresh()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1722
    
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1723
    def IsDragging(self):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1724
        return self.DraggingAxesPanel is not None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1725
    
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1726
    def GetDraggingAxesClippingRegion(self, panel):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1727
        x, y = panel.GetPosition()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1728
        width, height = panel.GetSize()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1729
        bbox = wx.Rect(x, y, width, height)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1730
        bbox = bbox.Intersect(self.DraggingAxesBoundingBox)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1731
        bbox.x -= x
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1732
        bbox.y -= y
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1733
        return bbox
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1734
    
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1735
    def GetDraggingAxesPosition(self, panel):
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1736
        x, y = panel.GetPosition()
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1737
        return wx.Point(self.DraggingAxesBoundingBox.x - x,
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1738
                        self.DraggingAxesBoundingBox.y - y)
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1739
    
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1740
    def StopDragNDrop(self, variable, x_mouse, y_mouse):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1741
        if self.DraggingAxesPanel not in self.GraphicPanels:
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1742
            self.DraggingAxesPanel.Destroy()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1743
        self.DraggingAxesPanel = None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1744
        self.DraggingAxesBoundingBox = None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1745
        self.DraggingAxesMousePos = None
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1746
        for idx, panel in enumerate(self.GraphicPanels):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1747
            panel.SetHighlight(HIGHLIGHT_NONE)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1748
            xw, yw = panel.GetPosition()
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1749
            width, height = panel.GetSize()
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1750
            bbox = wx.Rect(xw, yw, width, height)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1751
            if bbox.InsideXY(x_mouse, y_mouse):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1752
                panel.ShowButtons(True)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1753
                merge_type = GRAPH_PARALLEL
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1754
                if isinstance(panel, DebugVariableText) or panel.Is3DCanvas():
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1755
                    if y_mouse > yw + height / 2:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1756
                        idx += 1
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1757
                    wx.CallAfter(self.MoveValue, variable, idx)
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1758
                else:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1759
                    rect = panel.GetAxesBoundingBox(True)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1760
                    if rect.InsideXY(x_mouse, y_mouse):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1761
                        merge_rect = wx.Rect(rect.x, rect.y, rect.width / 2., rect.height)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1762
                        if merge_rect.InsideXY(x_mouse, y_mouse):
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1763
                            merge_type = GRAPH_ORTHOGONAL
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1764
                        wx.CallAfter(self.MergeGraphs, variable, idx, merge_type, force=True)
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1765
                    else:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1766
                        if y_mouse > yw + height / 2:
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1767
                            idx += 1
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1768
                        wx.CallAfter(self.MoveValue, variable, idx)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1769
                self.ForceRefresh()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1770
                return 
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1771
        width, height = self.GraphicsWindow.GetVirtualSize()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1772
        rect = wx.Rect(0, 0, width, height)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1773
        if rect.InsideXY(x_mouse, y_mouse):
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  1774
            wx.CallAfter(self.MoveValue, variable, len(self.GraphicPanels))
925
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1775
        self.ForceRefresh()
5f9dd88a605b Added support for drag'n drop variable from one graph to another with visible graph
Laurent Bessard
parents: 924
diff changeset
  1776
    
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
  1777
    def RefreshView(self, only_values=False):
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1778
        if USE_MPL:
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
  1779
            self.RefreshCanvasPosition()
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
  1780
            
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1781
            width, height = self.GraphicsWindow.GetVirtualSize()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1782
            bitmap = wx.EmptyBitmap(width, height)
946
9343740603f5 Fix bug on Windows with wxPaintDC
Laurent Bessard
parents: 945
diff changeset
  1783
            dc = wx.BufferedDC(wx.ClientDC(self.GraphicsWindow), bitmap)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1784
            dc.Clear()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1785
            dc.BeginDrawing()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1786
            if self.DraggingAxesPanel is not None:
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1787
                destBBox = self.DraggingAxesBoundingBox
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1788
                srcBBox = self.DraggingAxesPanel.GetAxesBoundingBox()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1789
                
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1790
                srcBmp = _convert_agg_to_wx_bitmap(self.DraggingAxesPanel.get_renderer(), None)
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1791
                srcDC = wx.MemoryDC()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1792
                srcDC.SelectObject(srcBmp)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1793
                    
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1794
                dc.Blit(destBBox.x, destBBox.y, 
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1795
                        int(destBBox.width), int(destBBox.height), 
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1796
                        srcDC, srcBBox.x, srcBBox.y)
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1797
            dc.EndDrawing()
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1798
            
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1799
            if not self.Fixed or self.Force:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  1800
                self.Force = False
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
  1801
                refresh_graphics = True
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
  1802
            else:
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
  1803
                refresh_graphics = False
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
  1804
            
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
  1805
            if self.DraggingAxesPanel is not None and self.DraggingAxesPanel not in self.GraphicPanels:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1806
                self.DraggingAxesPanel.RefreshViewer(refresh_graphics)
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
  1807
            for panel in self.GraphicPanels:
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
  1808
                if isinstance(panel, DebugVariableGraphic):
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1809
                    panel.RefreshViewer(refresh_graphics)
907
591cb3d96980 Fixed performance issue with matplotlib in DebugVariablePanel and hide 3D graphics when not needed
Laurent Bessard
parents: 905
diff changeset
  1810
                else:
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1811
                    panel.RefreshViewer()
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1812
            
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1813
            if self.CursorTick is not None:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1814
                tick = self.CursorTick
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1815
            elif len(self.Ticks) > 0:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1816
                tick = self.Ticks[-1]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1817
            else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1818
                tick = None
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1819
            if tick is not None:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1820
                self.TickLabel.SetLabel("Tick: %d" % tick)
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1821
                tick_duration = int(tick * self.Ticktime)
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1822
                not_null = False
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1823
                duration = ""
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1824
                for value, format in [(tick_duration / DAY, "%dd"),
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1825
                                      ((tick_duration % DAY) / HOUR, "%dh"),
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1826
                                      ((tick_duration % HOUR) / MINUTE, "%dm"),
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1827
                                      ((tick_duration % MINUTE) / SECOND, "%ds")]:
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1828
                    
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1829
                    if value > 0 or not_null:
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1830
                        duration += format % value
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1831
                        not_null = True
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1832
                
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1833
                duration += "%gms" % (float(tick_duration % SECOND) / MILLISECOND) 
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1834
                self.TickTimeLabel.SetLabel("t: %s" % duration)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1835
            else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1836
                self.TickLabel.SetLabel("")
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1837
                self.TickTimeLabel.SetLabel("")
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1838
            self.TickSizer.Layout()
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
  1839
        else:
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
  1840
            self.Freeze()
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
  1841
            
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
  1842
            if only_values:
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
  1843
                for col in xrange(self.Table.GetNumberCols()):
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
  1844
                    if self.Table.GetColLabelValue(col, False) == "Value":
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
  1845
                        for row in xrange(self.Table.GetNumberRows()):
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
  1846
                            self.VariablesGrid.SetCellValue(row, col, str(self.Table.GetValueByName(row, "Value")))
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
  1847
            else:
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
  1848
                self.Table.ResetView(self.VariablesGrid)
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
  1849
            self.VariablesGrid.RefreshButtons()
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
  1850
            
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
  1851
            self.Thaw()
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
  1852
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1853
    def UnregisterObsoleteData(self):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1174
diff changeset
  1854
        self.SubscribeAllDataConsumers()
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
  1855
        if USE_MPL:
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
  1856
            if self.DataProducer is not None:
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1857
                if self.DataProducer is not None:
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
  1858
                    self.SetTickTime(self.DataProducer.GetTicktime())
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
  1859
            
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
  1860
            for panel in self.GraphicPanels:
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
  1861
                panel.UnregisterObsoleteData()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1862
                if panel.IsEmpty():
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1863
                    if panel.HasCapture():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  1864
                        panel.ReleaseMouse()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1865
                    self.GraphicPanels.remove(panel)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1866
                    panel.Destroy()
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1867
            
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1868
            self.ResetVariableNameMask()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1869
            self.RefreshGraphicsSizer()
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1870
            self.ForceRefresh()
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
  1871
            
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
  1872
        else:
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
  1873
            items = [(idx, item) for idx, item in enumerate(self.Table.GetData())]
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
  1874
            items.reverse()
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
  1875
            for idx, item in items:
1102
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
  1876
                iec_path = item.GetVariable()
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
  1877
                if self.GetDataType(iec_path) is None:
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
  1878
                    self.RemoveDataConsumer(item)
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
  1879
                    self.Table.RemoveItem(idx)
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
  1880
                else:
1102
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
  1881
                    self.AddDataConsumer(iec_path.upper(), item)
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
  1882
                    item.RefreshVariableType()
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
  1883
            self.Freeze()
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
  1884
            self.Table.ResetView(self.VariablesGrid)
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
  1885
            self.VariablesGrid.RefreshButtons()
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
  1886
            self.Thaw()
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
  1887
    
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
  1888
    def ResetView(self):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1174
diff changeset
  1889
        self.UnsubscribeAllDataConsumers()
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
  1890
        if USE_MPL:
927
bd3e5b65e8be Fix bug when resetting graphs values
Laurent Bessard
parents: 925
diff changeset
  1891
            self.Fixed = False
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
  1892
            for panel in self.GraphicPanels:
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
  1893
                panel.Destroy()
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
  1894
            self.GraphicPanels = []
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1895
            self.ResetVariableNameMask()
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
  1896
            self.RefreshGraphicsSizer()
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
  1897
        else:
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
  1898
            self.Table.Empty()
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
  1899
            self.Freeze()
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
  1900
            self.Table.ResetView(self.VariablesGrid)
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
  1901
            self.VariablesGrid.RefreshButtons()
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
  1902
            self.Thaw()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1903
    
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
  1904
    def RefreshCanvasPosition(self):
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1905
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1906
            pos = int(self.StartTick - self.Ticks[0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1907
            range = int(self.Ticks[-1] - self.Ticks[0])
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1908
        else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1909
            pos = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1910
            range = 0
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1911
        self.CanvasPosition.SetScrollbar(pos, self.CurrentRange, range, self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1912
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1913
    def GetForceVariableMenuFunction(self, iec_path, item):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1914
        iec_type = self.GetDataType(iec_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1915
        def ForceVariableFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1916
            if iec_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1917
                dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1918
                if dialog.ShowModal() == wx.ID_OK:
1102
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
  1919
                    self.ForceDataValue(iec_path.upper(), dialog.GetValue())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1920
        return ForceVariableFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1921
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1922
    def GetReleaseVariableMenuFunction(self, iec_path):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1923
        def ReleaseVariableFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1924
            self.ReleaseDataValue(iec_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1925
        return ReleaseVariableFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1926
    
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
  1927
    def OnVariablesGridCellLeftClick(self, event):
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
  1928
        if event.GetCol() == 0:
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
  1929
            row = event.GetRow()
898
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 895
diff changeset
  1930
            data = wx.TextDataObject(str((self.Table.GetValueByName(row, "Variable"), "debug")))
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
  1931
            dragSource = wx.DropSource(self.VariablesGrid)
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
  1932
            dragSource.SetData(data)
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
  1933
            dragSource.DoDragDrop()
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
  1934
        event.Skip()
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
  1935
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1936
    def OnVariablesGridCellRightClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1937
        row, col = event.GetRow(), event.GetCol()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1938
        if self.Table.GetColLabelValue(col, False) == "Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1939
            iec_path = self.Table.GetValueByName(row, "Variable").upper()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1940
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1941
            menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1942
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1943
            new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1944
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1945
            self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.Table.GetItem(row)), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1946
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1947
            new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1948
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1949
            self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1950
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1951
            if self.Table.IsForced(row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1952
                menu.Enable(new_id, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1953
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1954
                menu.Enable(new_id, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1955
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1956
            self.PopupMenu(menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1957
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1958
            menu.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1959
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1960
    
932
ebe63100b6d7 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 931
diff changeset
  1961
    def ChangeRange(self, dir, tick=None):
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1962
        current_range = self.CurrentRange
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1963
        current_range_idx = self.CanvasRange.GetSelection()
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1964
        new_range_idx = max(0, min(current_range_idx + dir, len(RANGE_VALUES) - 1))
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1965
        if new_range_idx != current_range_idx:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1966
            self.CanvasRange.SetSelection(new_range_idx)
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1967
            self.CurrentRange = RANGE_VALUES[new_range_idx][1] / self.Ticktime
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1968
            if len(self.Ticks) > 0:
932
ebe63100b6d7 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 931
diff changeset
  1969
                if tick is None:
ebe63100b6d7 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 931
diff changeset
  1970
                    tick = self.StartTick + self.CurrentRange / 2.
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1971
                new_start_tick = tick - (tick - self.StartTick) * self.CurrentRange / current_range 
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1972
                self.StartTick = self.Ticks[numpy.argmin(numpy.abs(self.Ticks - new_start_tick))]
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1973
                self.Fixed = self.StartTick < self.Ticks[-1] - self.CurrentRange
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1974
            self.ForceRefresh()
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1975
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1976
    def RefreshRange(self):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1977
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1978
            if self.Fixed and self.Ticks[-1] - self.Ticks[0] < self.CurrentRange:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1979
                self.Fixed = False
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1980
            if self.Fixed:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1981
                self.StartTick = min(self.StartTick, self.Ticks[-1] - self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1982
            else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1983
                self.StartTick = max(self.Ticks[0], self.Ticks[-1] - self.CurrentRange)
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  1984
        self.ForceRefresh()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1985
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1986
    def OnRangeChanged(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1987
        try:
1191
5237f87e035f Fixed values in DebugVariablePanel range selection ComboBox
Laurent Bessard
parents: 1190
diff changeset
  1988
            self.CurrentRange = RANGE_VALUES[self.CanvasRange.GetSelection()][1] / self.Ticktime
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1989
        except ValueError, e:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1990
            self.CanvasRange.SetValue(str(self.CurrentRange))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1991
        wx.CallAfter(self.RefreshRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1992
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1993
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1994
    def OnCurrentButton(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1995
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1996
            self.StartTick = max(self.Ticks[0], self.Ticks[-1] - self.CurrentRange)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1997
            self.Fixed = False
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  1998
            self.ResetCursorTick()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  1999
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2000
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2001
    def CopyDataToClipboard(self, variables):
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2002
        text = "tick;%s;\n" % ";".join([item.GetVariable() for item, data in variables])
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2003
        next_tick = NextTick(variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2004
        while next_tick is not None:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2005
            values = []
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2006
            for item, data in variables:
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2007
                if len(data) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2008
                    if next_tick == data[0][0]:
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2009
                        var_type = item.GetVariableType()
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2010
                        if var_type in ["STRING", "WSTRING"]:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2011
                            value = item.GetRawValue(int(data.pop(0)[2]))
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2012
                            if var_type == "STRING":
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2013
                                values.append("'%s'" % value)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2014
                            else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2015
                                values.append('"%s"' % value)
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2016
                        else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2017
                            values.append("%.3f" % data.pop(0)[1])
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2018
                    else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2019
                        values.append("")
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2020
                else:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2021
                    values.append("")
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2022
            text += "%d;%s;\n" % (next_tick, ";".join(values))
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2023
            next_tick = NextTick(variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2024
        self.ParentWindow.SetCopyBuffer(text)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2025
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2026
    def OnExportGraphButton(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2027
        variables = []
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2028
        if USE_MPL:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2029
            items = []
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2030
            for panel in self.GraphicPanels:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2031
                items.extend(panel.GetItems())
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2032
        else:
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2033
            items = self.Table.GetData()
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2034
        for item in items:
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2035
            if item.IsNumVariable():
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2036
                variables.append((item, [entry for entry in item.GetData()]))
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2037
        wx.CallAfter(self.CopyDataToClipboard, variables)
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2038
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2039
    
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2040
    def OnPositionChanging(self, event):
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2041
        if len(self.Ticks) > 0:
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2042
            self.StartTick = self.Ticks[0] + event.GetPosition()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2043
            self.Fixed = True
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2044
            self.ForceRefresh()
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2045
        event.Skip()
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
  2046
    
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
  2047
    def GetRange(self):
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
  2048
        return self.StartTick, self.StartTick + self.CurrentRange
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
  2049
    
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
  2050
    def GetViewerIndex(self, viewer):
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
  2051
        if viewer in self.GraphicPanels:
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
  2052
            return self.GraphicPanels.index(viewer)
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
  2053
        return None
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
  2054
    
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2055
    def IsViewerFirst(self, viewer):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2056
        return viewer == self.GraphicPanels[0]
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2057
    
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2058
    def IsViewerLast(self, viewer):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2059
        return viewer == self.GraphicPanels[-1]
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2060
    
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2061
    def HighlightPreviousViewer(self, viewer):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2062
        if self.IsViewerFirst(viewer):
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2063
            return
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2064
        idx = self.GetViewerIndex(viewer)
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2065
        if idx is None:
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2066
            return
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  2067
        self.GraphicPanels[idx-1].SetHighlight(HIGHLIGHT_AFTER)
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
  2068
    
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2069
    def ResetVariableNameMask(self):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2070
        items = []
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2071
        for panel in self.GraphicPanels:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2072
            items.extend(panel.GetItems())
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2073
        if len(items) > 1:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2074
            self.VariableNameMask = reduce(compute_mask,
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2075
                [item.GetVariable().split('.') for item in items])
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2076
        elif len(items) > 0:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2077
            self.VariableNameMask = items[0].GetVariable().split('.')[:-1] + ['*']
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2078
        else:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2079
            self.VariableNameMask = []
931
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  2080
        self.MaskLabel.ChangeValue(".".join(self.VariableNameMask))
da4970f6c46c Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 930
diff changeset
  2081
        self.MaskLabel.SetInsertionPoint(self.MaskLabel.GetLastPosition())
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2082
            
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2083
    def GetVariableNameMask(self):
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2084
        return self.VariableNameMask
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2085
    
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2086
    def InsertValue(self, iec_path, idx = None, force=False):
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
  2087
        if USE_MPL:
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
  2088
            for panel in self.GraphicPanels:
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
  2089
                if panel.GetItem(iec_path) is not None:
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
  2090
                    return
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
  2091
            if idx is None:
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
  2092
                idx = len(self.GraphicPanels)
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
  2093
        else:
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
  2094
            for item in self.Table.GetData():
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
  2095
                if iec_path == item.GetVariable():
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
  2096
                    return
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
  2097
            if idx is None:
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
  2098
                idx = self.Table.GetNumberRows()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  2099
        item = VariableTableItem(self, iec_path)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2100
        result = self.AddDataConsumer(iec_path.upper(), item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2101
        if result is not None or force:
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
  2102
            
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
  2103
            if USE_MPL:
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
  2104
                if item.IsNumVariable():
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
  2105
                    panel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2106
                    if self.CursorTick is not None:
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2107
                        panel.SetCursorTick(self.CursorTick)
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
  2108
                else:
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
  2109
                    panel = DebugVariableText(self.GraphicsWindow, self, [item])
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
  2110
                if idx is not None:
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
  2111
                    self.GraphicPanels.insert(idx, panel)
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
  2112
                else:
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
  2113
                    self.GraphicPanels.append(panel)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2114
                self.ResetVariableNameMask()
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
  2115
                self.RefreshGraphicsSizer()
1008
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
  2116
                self.ForceRefresh()
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
  2117
            else:
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
  2118
                self.Table.InsertItem(idx, item)
1008
1e5d285864f6 Fixed bugs in DebugVariablePanel when matplotlib not installed
Laurent Bessard
parents: 988
diff changeset
  2119
                self.RefreshView()
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
  2120
    
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  2121
    def MoveValue(self, iec_path, idx = None):
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2122
        if idx is None:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2123
            idx = len(self.GraphicPanels)
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2124
        source_panel = None
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2125
        item = None
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2126
        for panel in self.GraphicPanels:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2127
            item = panel.GetItem(iec_path)
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2128
            if item is not None:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2129
                source_panel = panel
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2130
                break
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2131
        if source_panel is not None:
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2132
            source_panel.RemoveItem(item)
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2133
            source_size = source_panel.GetSize()
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2134
            if source_panel.IsEmpty():
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  2135
                if source_panel.HasCapture():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  2136
                    source_panel.ReleaseMouse()
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2137
                self.GraphicPanels.remove(source_panel)
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2138
                source_panel.Destroy()
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2139
            
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  2140
            if item.IsNumVariable():
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  2141
                panel = DebugVariableGraphic(self.GraphicsWindow, self, [item], GRAPH_PARALLEL)
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2142
                panel.SetCanvasSize(source_size.width, source_size.height)
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  2143
                if self.CursorTick is not None:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  2144
                    panel.SetCursorTick(self.CursorTick)
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  2145
            else:
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  2146
                panel = DebugVariableText(self.GraphicsWindow, self, [item])
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2147
            self.GraphicPanels.insert(idx, panel)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2148
            self.ResetVariableNameMask()
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2149
            self.RefreshGraphicsSizer()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2150
            self.ForceRefresh()
919
4a36e38e51d3 Fix bug in DebugVariablePanel when manipulating graph layout and adding drag'n drop graph from parallel graphs and moving graphs order
Laurent Bessard
parents: 916
diff changeset
  2151
    
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
  2152
    def MergeGraphs(self, source, target_idx, merge_type, force=False):
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2153
        source_item = None
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
  2154
        source_panel = None
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
  2155
        for panel in self.GraphicPanels:
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
  2156
            source_item = panel.GetItem(source)
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
  2157
            if source_item is not None:
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
  2158
                source_panel = panel
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
  2159
                break
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2160
        if source_item is None:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2161
            item = VariableTableItem(self, source)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2162
            if item.IsNumVariable():
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2163
                result = self.AddDataConsumer(source.upper(), item)
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2164
                if result is not None or force:
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2165
                    source_item = item
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
  2166
        if source_item is not None and source_item.IsNumVariable():
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2167
            if source_panel is not None:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2168
                source_size = source_panel.GetSize()
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2169
            else:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2170
                source_size = None
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
  2171
            target_panel = self.GraphicPanels[target_idx]
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
  2172
            graph_type = target_panel.GraphType
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
  2173
            if target_panel != source_panel:
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
  2174
                if (merge_type == GRAPH_PARALLEL and graph_type != merge_type or
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2175
                    merge_type == GRAPH_ORTHOGONAL and 
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
  2176
                    (graph_type == GRAPH_PARALLEL and len(target_panel.Items) > 1 or
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
  2177
                     graph_type == GRAPH_ORTHOGONAL and len(target_panel.Items) >= 3)):
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2178
                    return
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2179
                
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
  2180
                if source_panel is not None:
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
  2181
                    source_panel.RemoveItem(source_item)
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
  2182
                    if source_panel.IsEmpty():
943
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  2183
                        if source_panel.HasCapture():
da7f80e04a54 Fixed panels displaying non-numeric variables in DebugVariablePanel
Laurent Bessard
parents: 938
diff changeset
  2184
                            source_panel.ReleaseMouse()
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
  2185
                        self.GraphicPanels.remove(source_panel)
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
  2186
                        source_panel.Destroy()
936
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  2187
            elif (merge_type != graph_type and len(target_panel.Items) == 2):
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  2188
                target_panel.RemoveItem(source_item)
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  2189
            else:
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  2190
                target_panel = None
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  2191
                
364d178df2d3 Added button for exporting individual graph values to clipboard
Laurent Bessard
parents: 935
diff changeset
  2192
            if target_panel is not None:
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
  2193
                target_panel.AddItem(source_item)
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
  2194
                target_panel.GraphType = merge_type
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2195
                size = target_panel.GetSize()
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2196
                if merge_type == GRAPH_ORTHOGONAL:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2197
                    target_panel.SetCanvasSize(size.width, size.width)
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2198
                elif source_size is not None:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2199
                    target_panel.SetCanvasSize(size.width, size.height + source_size.height)
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2200
                else:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2201
                    target_panel.SetCanvasSize(size.width, size.height)
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
  2202
                target_panel.ResetGraphics()
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
  2203
                
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2204
                self.ResetVariableNameMask()
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
  2205
                self.RefreshGraphicsSizer()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2206
                self.ForceRefresh()
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
  2207
    
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
  2208
    def DeleteValue(self, source_panel, item=None):
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
  2209
        source_idx = self.GetViewerIndex(source_panel)
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
  2210
        if source_idx is not None:
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
  2211
            
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
  2212
            if item is None:
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
  2213
                source_panel.Clear()
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
  2214
                source_panel.Destroy()
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
  2215
                self.GraphicPanels.remove(source_panel)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2216
                self.ResetVariableNameMask()
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
  2217
                self.RefreshGraphicsSizer()
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
  2218
            else:
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
  2219
                source_panel.RemoveItem(item)
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
  2220
                if source_panel.IsEmpty():
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
  2221
                    source_panel.Destroy()
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
  2222
                    self.GraphicPanels.remove(source_panel)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
  2223
                    self.ResetVariableNameMask()
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
  2224
                    self.RefreshGraphicsSizer()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2225
            self.ForceRefresh()
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
  2226
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  2227
    def ResetGraphicsValues(self):
888
baf5dbfd28f4 Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents: 887
diff changeset
  2228
        if USE_MPL:
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
  2229
            self.Ticks = numpy.array([])
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
  2230
            self.StartTick = 0
927
bd3e5b65e8be Fix bug when resetting graphs values
Laurent Bessard
parents: 925
diff changeset
  2231
            self.Fixed = False
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
  2232
            for panel in self.GraphicPanels:
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
  2233
                panel.ResetData()
1084
baa09a1c7b15 Fixed bug in DebugVariablePanel, cursor not reset when graphs were reset
Laurent Bessard
parents: 1044
diff changeset
  2234
            self.ResetCursorTick()
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
  2235
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
  2236
    def RefreshGraphicsWindowScrollbars(self):
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
  2237
        xstart, ystart = self.GraphicsWindow.GetViewStart()
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
  2238
        window_size = self.GraphicsWindow.GetClientSize()
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
  2239
        vwidth, vheight = self.GraphicsSizer.GetMinSize()
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  2240
        posx = max(0, min(xstart, (vwidth - window_size[0]) / SCROLLBAR_UNIT))
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  2241
        posy = max(0, min(ystart, (vheight - window_size[1]) / SCROLLBAR_UNIT))
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
  2242
        self.GraphicsWindow.Scroll(posx, posy)
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
  2243
        self.GraphicsWindow.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  2244
                vwidth / SCROLLBAR_UNIT, vheight / SCROLLBAR_UNIT, posx, posy)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
  2245
    
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  2246
    def OnGraphicsWindowEraseBackground(self, event):
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  2247
        pass
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  2248
    
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  2249
    def OnGraphicsWindowPaint(self, event):
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  2250
        self.RefreshView()
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  2251
        event.Skip()
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
  2252
    
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
  2253
    def OnGraphicsWindowResize(self, event):
1041
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2254
        size = self.GetSize()
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2255
        for panel in self.GraphicPanels:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2256
            panel_size = panel.GetSize()
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2257
            if panel.GraphType == GRAPH_ORTHOGONAL and panel_size.width == panel_size.height:
736ec395399a Fixed graph panel size when modifying DebugVariablePanel layout
Laurent Bessard
parents: 1040
diff changeset
  2258
                panel.SetCanvasSize(size.width, size.width)
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
  2259
        self.RefreshGraphicsWindowScrollbars()
924
5f2cc382be8c Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents: 919
diff changeset
  2260
        event.Skip()
1040
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  2261
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  2262
    def OnGraphicsWindowMouseWheel(self, event):
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  2263
        if self.VetoScrollEvent:
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  2264
            self.VetoScrollEvent = False
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  2265
        else:
af8a1aee3584 Fixed MouseWheel behavior in DebugVariablePanel, change graph range only if CTRL is pressed
Laurent Bessard
parents: 1008
diff changeset
  2266
            event.Skip()