controls/DebugVariablePanel/DebugVariableTablePanel.py
author Laurent Bessard
Fri, 30 Aug 2013 18:10:30 +0200
changeset 1299 9ffc49bfdf9d
parent 1214 2ef048b5383c
permissions -rw-r--r--
Fixed copy/paste with xmlclass refactoring
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
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    25
from types import TupleType
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
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
    29
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    30
from editors.DebugViewer import DebugViewer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
from controls import CustomGrid, CustomTable
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
from dialogs.ForceVariableDialog import ForceVariableDialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    35
from DebugVariableItem import DebugVariableItem
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    36
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
def GetDebugVariablesTableColnames():
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    38
    """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    39
    Function returning table column header labels
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    40
    @return: List of labels [col_label,...]
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    41
    """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
    _ = lambda x : x
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    43
    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
    44
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    45
#-------------------------------------------------------------------------------
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    46
#                        Debug Variable Table Panel
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    47
#-------------------------------------------------------------------------------
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    48
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    49
"""
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    50
Class that implements a custom table storing value to display in Debug Variable
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    51
Table Panel grid
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    52
"""
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
    53
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
class DebugVariableTable(CustomTable):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
    def GetValue(self, row, col):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
            return self.GetValueByName(row, self.GetColLabelValue(col, False))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        return ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
    def SetValue(self, row, col, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
        if col < len(self.colnames):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
            self.SetValueByName(row, self.GetColLabelValue(col, False), value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
    def GetValueByName(self, row, colname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
            if colname == "Variable":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
                return self.data[row].GetVariable()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
            elif colname == "Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
                return self.data[row].GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        return ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
    def SetValueByName(self, row, colname, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
            if colname == "Variable":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
                self.data[row].SetVariable(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
            elif colname == "Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
                self.data[row].SetValue(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
    def IsForced(self, row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
            return self.data[row].IsForced()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
    def _updateColAttrs(self, grid):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        wx.grid.Grid -> update the column attributes to add the
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        appropriate renderer given the column name.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        Otherwise default to the default renderer.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        for row in range(self.GetNumberRows()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
            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
    95
                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
    96
                if colname == "Value":
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    97
                    if self.IsForced(row):
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
    98
                        grid.SetCellTextColour(row, col, wx.BLUE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
                    else:
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   100
                        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
   101
                grid.SetReadOnly(row, col, True)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
            self.ResizeRow(grid, row)
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   103
    
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   104
    def RefreshValues(self, grid):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   105
        for col in xrange(self.GetNumberCols()):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   106
            colname = self.GetColLabelValue(col, False)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   107
            if colname == "Value":
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   108
                for row in xrange(self.GetNumberRows()):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   109
                    grid.SetCellValue(row, col, str(self.data[row].GetValue()))
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   110
                    if self.IsForced(row):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   111
                        grid.SetCellTextColour(row, col, wx.BLUE)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   112
                    else:
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   113
                        grid.SetCellTextColour(row, col, wx.BLACK)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   114
      
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   115
    def AppendItem(self, item):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   116
        self.data.append(item)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   117
    
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   118
    def InsertItem(self, idx, item):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   119
        self.data.insert(idx, item)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   120
    
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   121
    def RemoveItem(self, item):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   122
        self.data.remove(item)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
    def MoveItem(self, idx, new_idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        self.data.insert(new_idx, self.data.pop(idx))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
    def GetItem(self, idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        return self.data[idx]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   130
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   131
#-------------------------------------------------------------------------------
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   132
#                  Debug Variable Table Panel Drop Target
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   133
#-------------------------------------------------------------------------------
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   134
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   135
"""
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   136
Class that implements a custom drop target class for Debug Variable Table Panel
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   137
"""
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   138
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   139
class DebugVariableTableDropTarget(wx.TextDropTarget):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   140
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   141
    def __init__(self, parent):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   142
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   143
        Constructor
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   144
        @param window: Reference to the Debug Variable Panel
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   145
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
        wx.TextDropTarget.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
        self.ParentWindow = parent
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   148
        
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
   149
    def __del__(self):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   150
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   151
        Destructor
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   152
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   153
        # Remove reference to Debug Variable 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
   154
        self.ParentWindow = None
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   155
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
    def OnDropText(self, x, y, data):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   157
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   158
        Function called when mouse is dragged over Drop Target
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   159
        @param x: X coordinate of mouse pointer
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   160
        @param y: Y coordinate of mouse pointer
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   161
        @param data: Text associated to drag'n drop
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   162
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
        message = None
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   164
        
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   165
        # Check that data is valid regarding DebugVariablePanel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
            values = eval(data)
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   168
            if not isinstance(values, TupleType):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   169
                raise ValueError
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
        except:
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   171
            message = _("Invalid value \"%s\" for debug variable") % data
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
            values = None
909
852af7c6f0ef Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents: 907
diff changeset
   173
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   174
        # Display message if data is invalid
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
            wx.CallAfter(self.ShowMessage, message)
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   177
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   178
        # Data contain a reference to a variable to debug
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   179
        elif values[1] == "debug":
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   180
            grid = self.ParentWindow.VariablesGrid
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   181
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   182
            # Get row where variable was dropped
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   183
            x, y = grid.CalcUnscrolledPosition(x, y)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   184
            row = grid.YToRow(y - grid.GetColLabelSize())
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   185
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   186
            # If no row found add variable at table end
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   187
            if row == wx.NOT_FOUND:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   188
                row = self.ParentWindow.Table.GetNumberRows()
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   189
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   190
            # Add variable to table
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   191
            self.ParentWindow.InsertValue(values[0], row, force=True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   192
            
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
    def ShowMessage(self, message):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   194
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   195
        Show error message in Error Dialog
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   196
        @param message: Error message to display
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   197
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   198
        dialog = wx.MessageDialog(self.ParentWindow, 
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   199
                                  message, 
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   200
                                  _("Error"), 
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   201
                                  wx.OK|wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
        dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
        dialog.Destroy()
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   204
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   205
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   206
#-------------------------------------------------------------------------------
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   207
#                       Debug Variable Table Panel
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   208
#-------------------------------------------------------------------------------
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   209
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   210
"""
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   211
Class that implements a panel displaying debug variable values in a table
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   212
"""
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   213
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   214
class DebugVariableTablePanel(wx.Panel, DebugViewer):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   216
    def __init__(self, parent, producer, window):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   217
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   218
        Constructor
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   219
        @param parent: Reference to the parent wx.Window
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   220
        @param producer: Object receiving debug value and dispatching them to
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   221
        consumers
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   222
        @param window: Reference to Beremiz frame
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   223
        """
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
   224
        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
   225
        
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   226
        # Save Reference to Beremiz frame
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   227
        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
   228
        
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   229
        # Variable storing flag indicating that variable displayed in table
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   230
        # received new value and then table need to be refreshed
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
        self.HasNewData = False
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   232
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   233
        DebugViewer.__init__(self, producer, True)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   234
        
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   235
        # Construction of window layout by creating controls and sizers
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   236
        
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   237
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   238
        main_sizer.AddGrowableCol(0)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   239
        main_sizer.AddGrowableRow(1)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   240
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   241
        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   242
        main_sizer.AddSizer(button_sizer, border=5, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   243
              flag=wx.ALIGN_RIGHT|wx.ALL)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   244
        
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   245
        # Creation of buttons for navigating in table
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   246
        
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   247
        for name, bitmap, help in [
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   248
                ("DeleteButton", "remove_element", _("Remove debug variable")),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   249
                ("UpButton", "up", _("Move debug variable up")),
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   250
                ("DownButton", "down", _("Move debug variable down"))]:
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   251
            button = wx.lib.buttons.GenBitmapButton(self, 
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   252
                  bitmap=GetBitmap(bitmap), 
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   253
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   254
            button.SetToolTipString(help)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   255
            setattr(self, name, button)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   256
            button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   257
        
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   258
        # Creation of grid and associated table
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   259
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   260
        self.VariablesGrid = CustomGrid(self, 
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   261
                size=wx.Size(-1, 150), style=wx.VSCROLL)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   262
        # Define grid drop target
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   263
        self.VariablesGrid.SetDropTarget(DebugVariableTableDropTarget(self))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   264
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   265
              self.OnVariablesGridCellRightClick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   266
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, 
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   267
              self.OnVariablesGridCellLeftClick)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   268
        main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   269
    
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   270
        self.Table = DebugVariableTable(self, [], 
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   271
                GetDebugVariablesTableColnames())
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   272
        self.VariablesGrid.SetTable(self.Table)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   273
        self.VariablesGrid.SetButtons({"Delete": self.DeleteButton,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   274
                                       "Up": self.UpButton,
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   275
                                       "Down": self.DownButton})
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   276
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   277
        # Definition of function associated to navigation buttons
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   278
        
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   279
        def _AddVariable(new_row):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   280
            return self.VariablesGrid.GetGridCursorRow()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   281
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   282
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   283
        def _DeleteVariable(row):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   284
            item = self.Table.GetItem(row)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   285
            self.RemoveDataConsumer(item)
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   286
            self.Table.RemoveItem(item)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   287
            self.RefreshView()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   288
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   289
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   290
        def _MoveVariable(row, move):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   291
            new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   292
            if new_row != row:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   293
                self.Table.MoveItem(row, new_row)
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
   294
                self.RefreshView()
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   295
            return new_row
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   296
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   297
        
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   298
        # Initialization of grid layout
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   299
        
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   300
        self.VariablesGrid.SetRowLabelSize(0)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   301
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   302
        self.GridColSizes = [200, 100]
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   303
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   304
        for col in range(self.Table.GetNumberCols()):
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   305
            attr = wx.grid.GridCellAttr()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   306
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   307
            self.VariablesGrid.SetColAttr(col, attr)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   308
            self.VariablesGrid.SetColSize(col, self.GridColSizes[col])
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   309
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   310
        self.Table.ResetView(self.VariablesGrid)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   311
        self.VariablesGrid.RefreshButtons()
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
   312
        
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
   313
        self.SetSizer(main_sizer)
1192
d8783c0c7d80 Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents: 1191
diff changeset
   314
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 898
diff changeset
   315
    def RefreshNewData(self, *args, **kwargs):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   316
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   317
        Called to refresh Table according to values received by variables
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   318
        Can receive any parameters (not used here)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   319
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   320
        # Refresh 'Value' column of table if new data have been received since
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   321
        # last refresh
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   322
        if self.HasNewData:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
            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
   324
            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
   325
        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
   326
    
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   327
    def RefreshView(self, only_values=False):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   328
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   329
        Function refreshing table layout and values
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   330
        @param only_values: True if only 'Value' column need to be updated
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   331
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   332
        # Block refresh until table layout and values are completely updated
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   333
        self.Freeze()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   334
        
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   335
        # Update only 'value' column from table 
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   336
        if only_values:
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   337
            self.Table.RefreshValues(self.VariablesGrid)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   338
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   339
        # Update complete table layout refreshing table navigation buttons
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   340
        # state according to 
929
c562031146e4 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 928
diff changeset
   341
        else:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   342
            self.Table.ResetView(self.VariablesGrid)
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   343
            self.VariablesGrid.RefreshButtons()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   344
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   345
        self.Thaw()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   346
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   347
    def ResetView(self):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   348
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   349
        Function removing all variables denugged from table
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   350
        @param only_values: True if only 'Value' column need to be updated
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   351
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   352
        # Unsubscribe all variables debugged
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   353
        self.UnsubscribeAllDataConsumers()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   354
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   355
        # Clear table content
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   356
        self.Table.Empty()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   357
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   358
        # Update table layout
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   359
        self.Freeze()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   360
        self.Table.ResetView(self.VariablesGrid)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   361
        self.VariablesGrid.RefreshButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   362
        self.Thaw()
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   363
    
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   364
    def SubscribeAllDataConsumers(self):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   365
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   366
        Function refreshing table layout and values
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   367
        @param only_values: True if only 'Value' column need to be updated
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   368
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   369
        DebugViewer.SubscribeAllDataConsumers(self)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   370
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   371
        # Navigate through variable displayed in table, removing those that
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   372
        # doesn't exist anymore in PLC
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   373
        for item in self.Table.GetData()[:]:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   374
            iec_path = item.GetVariable()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   375
            if self.GetDataType(iec_path) is None:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   376
                self.RemoveDataConsumer(item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   377
                self.Table.RemoveItem(idx)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   378
            else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   379
                self.AddDataConsumer(iec_path.upper(), item)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   380
                item.RefreshVariableType()
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   381
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   382
        # Update table layout
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   383
        self.Freeze()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   384
        self.Table.ResetView(self.VariablesGrid)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   385
        self.VariablesGrid.RefreshButtons()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   386
        self.Thaw()
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
    
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   388
    def GetForceVariableMenuFunction(self, item):
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   389
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   390
        Function returning callback function for contextual menu 'Force' item
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   391
        @param item: Debug Variable item where contextual menu was opened 
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   392
        @return: Callback function
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   393
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
        def ForceVariableFunction(event):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   395
            # Get variable path and data type
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   396
            iec_path = item.GetVariable()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   397
            iec_type = self.GetDataType(iec_path)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   398
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   399
            # Return immediately if not data type found
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   400
            if iec_type is None:
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   401
                return
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   402
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   403
            # Open dialog for entering value to force variable
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   404
            dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   405
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   406
            # If valid value entered, force variable
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   407
            if dialog.ShowModal() == wx.ID_OK:
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   408
                self.ForceDataValue(iec_path.upper(), dialog.GetValue())
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   409
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
        return ForceVariableFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   412
    def GetReleaseVariableMenuFunction(self, iec_path):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   413
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   414
        Function returning callback function for contextual menu 'Release' item
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   415
        @param iec_path: Debug Variable path where contextual menu was opened
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   416
        @return: Callback function
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   417
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
        def ReleaseVariableFunction(event):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   419
            # Release variable
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
            self.ReleaseDataValue(iec_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
        return ReleaseVariableFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
    
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   423
    def OnVariablesGridCellLeftClick(self, event):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   424
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   425
        Called when left mouse button is pressed on a table cell
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   426
        @param event: wx.grid.GridEvent
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   427
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   428
        # Initiate a drag and drop if the cell clicked was in 'Variable' column
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   429
        if self.Table.GetColLabelValue(event.GetCol(), False) == "Variable":
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   430
            item = self.Table.GetItem(event.GetRow())
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   431
            data = wx.TextDataObject(str((item.GetVariable(), "debug")))
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   432
            dragSource = wx.DropSource(self.VariablesGrid)
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   433
            dragSource.SetData(data)
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   434
            dragSource.DoDragDrop()
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   435
        
892
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   436
        event.Skip()
771581a6b0be Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents: 888
diff changeset
   437
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
    def OnVariablesGridCellRightClick(self, event):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   439
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   440
        Called when right mouse button is pressed on a table cell
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   441
        @param event: wx.grid.GridEvent
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   442
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   443
        # Open a contextual menu if the cell clicked was in 'Value' column
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   444
        if self.Table.GetColLabelValue(event.GetCol(), False) == "Value":
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   445
            row = event.GetRow()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   446
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   447
            # Get variable path
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   448
            item = self.Table.GetItem(row)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   449
            iec_path = item.GetVariable().upper()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   450
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   451
            # Create contextual menu
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
            menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
            
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   454
            # Add menu items
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   455
            for text, enable, callback in [
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   456
                (_("Force value"), True,
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   457
                 self.GetForceVariableMenuFunction(item)),
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   458
                # Release menu item is enabled only if variable is forced 
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   459
                (_("Release value"), self.Table.IsForced(row),
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   460
                 self.GetReleaseVariableMenuFunction(iec_path))]:
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   461
                
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   462
                new_id = wx.NewId()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   463
                menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   464
                menu.Enable(new_id, enable)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   465
                self.Bind(wx.EVT_MENU, callback, id=new_id)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   466
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   467
            # Popup contextual menu
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   468
            self.PopupMenu(menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   469
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
            menu.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   472
    
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   473
    def InsertValue(self, iec_path, index=None, force=False, graph=False):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   474
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   475
        Insert a new variable to debug in table
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   476
        @param iec_path: Variable path to debug
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   477
        @param index: Row where insert the variable in table (default None,
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   478
        insert at last position)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   479
        @param force: Force insertion of variable even if not defined in
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   480
        producer side
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   481
        @param graph: Values must be displayed in graph canvas (Do nothing,
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   482
        here for compatibility with Debug Variable Graphic Panel)
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   483
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   484
        # Return immediately if variable is already debugged
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   485
        for item in self.Table.GetData():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   486
            if iec_path == item.GetVariable():
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   487
                return
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   488
            
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   489
        # Insert at last position if index not defined
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   490
        if index is None:
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   491
            index = self.Table.GetNumberRows()
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   492
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   493
        # Subscribe variable to producer
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   494
        item = DebugVariableItem(self, iec_path)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
        result = self.AddDataConsumer(iec_path.upper(), item)
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   496
        
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   497
        # Insert variable in table if subscription done or insertion forced
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   498
        if result is not None or force:
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   499
            self.Table.InsertItem(index, item)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   500
            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
   501
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 878
diff changeset
   502
    def ResetGraphicsValues(self):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   503
        """
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   504
        Called to reset graphics values when PLC is started
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   505
        (Nothing to do because no graphic values here. Defined for
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   506
        compatibility with Debug Variable Graphic Panel)
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
   507
        """
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 980
diff changeset
   508
        pass
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   509