controls/DebugVariablePanel.py
author Laurent Bessard
Wed, 18 Jul 2012 01:02:08 +0200
changeset 728 ce36d704184b
parent 715 6a3792a6bf7b
child 756 7eb469275611
permissions -rw-r--r--
Fix bug with 'projects' entry in configuration file
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     3
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     6
#
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     8
#
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    10
#
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    15
#
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    20
#
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    24
715
6a3792a6bf7b Fix bugs on Debug Variable Panel after splitting it from PLCOpenEditor.py
Laurent Bessard
parents: 714
diff changeset
    25
from types import TupleType
6a3792a6bf7b Fix bugs on Debug Variable Panel after splitting it from PLCOpenEditor.py
Laurent Bessard
parents: 714
diff changeset
    26
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    27
import wx
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
    28
import wx.lib.buttons
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    29
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    30
from graphics import DebugDataConsumer, DebugViewer
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    31
from controls import CustomGrid, CustomTable
715
6a3792a6bf7b Fix bugs on Debug Variable Panel after splitting it from PLCOpenEditor.py
Laurent Bessard
parents: 714
diff changeset
    32
from dialogs import ForceVariableDialog
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
    33
from utils.BitmapLibrary import GetBitmap
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    34
715
6a3792a6bf7b Fix bugs on Debug Variable Panel after splitting it from PLCOpenEditor.py
Laurent Bessard
parents: 714
diff changeset
    35
def AppendMenu(parent, help, id, kind, text):
6a3792a6bf7b Fix bugs on Debug Variable Panel after splitting it from PLCOpenEditor.py
Laurent Bessard
parents: 714
diff changeset
    36
    parent.Append(help=help, id=id, kind=kind, text=text)
6a3792a6bf7b Fix bugs on Debug Variable Panel after splitting it from PLCOpenEditor.py
Laurent Bessard
parents: 714
diff changeset
    37
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    38
def GetDebugVariablesTableColnames():
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    39
    _ = lambda x : x
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    40
    return [_("Variable"), _("Value")]
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    41
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    42
class VariableTableItem(DebugDataConsumer):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    43
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    44
    def __init__(self, parent, variable, value):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    45
        DebugDataConsumer.__init__(self)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    46
        self.Parent = parent
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    47
        self.Variable = variable
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    48
        self.Value = value
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    49
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    50
    def __del__(self):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    51
        self.Parent = None
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    52
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    53
    def SetVariable(self, variable):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    54
        if self.Parent and self.Variable != variable:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    55
            self.Variable = variable
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    56
            self.Parent.RefreshGrid()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    57
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    58
    def GetVariable(self):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    59
        return self.Variable
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    60
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    61
    def SetForced(self, forced):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    62
        if self.Forced != forced:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    63
            self.Forced = forced
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    64
            self.Parent.HasNewData = True
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    65
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    66
    def SetValue(self, value):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    67
        if self.Value != value:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    68
            self.Value = value
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    69
            self.Parent.HasNewData = True
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    70
            
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    71
    def GetValue(self):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    72
        return self.Value
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    73
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    74
class DebugVariableTable(CustomTable):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    75
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    76
    def GetValue(self, row, col):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    77
        if row < self.GetNumberRows():
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    78
            return self.GetValueByName(row, self.GetColLabelValue(col, False))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    79
        return ""
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    80
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    81
    def SetValue(self, row, col, value):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    82
        if col < len(self.colnames):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    83
            self.SetValueByName(row, self.GetColLabelValue(col, False), value)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    84
            
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    85
    def GetValueByName(self, row, colname):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    86
        if row < self.GetNumberRows():
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    87
            if colname == "Variable":
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    88
                return self.data[row].GetVariable()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    89
            elif colname == "Value":
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    90
                return self.data[row].GetValue()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    91
        return ""
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    92
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    93
    def SetValueByName(self, row, colname, value):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    94
        if row < self.GetNumberRows():
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    95
            if colname == "Variable":
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    96
                self.data[row].SetVariable(value)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    97
            elif colname == "Value":
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    98
                self.data[row].SetValue(value)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
    99
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   100
    def IsForced(self, row):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   101
        if row < self.GetNumberRows():
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   102
            return self.data[row].IsForced()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   103
        return False
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   104
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   105
    def _updateColAttrs(self, grid):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   106
        """
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   107
        wx.grid.Grid -> update the column attributes to add the
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   108
        appropriate renderer given the column name.
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   109
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   110
        Otherwise default to the default renderer.
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   111
        """
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   112
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   113
        for row in range(self.GetNumberRows()):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   114
            for col in range(self.GetNumberCols()):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   115
                if self.GetColLabelValue(col, False) == "Value":
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   116
                    if self.IsForced(row):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   117
                        grid.SetCellTextColour(row, col, wx.BLUE)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   118
                    else:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   119
                        grid.SetCellTextColour(row, col, wx.BLACK)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   120
                grid.SetReadOnly(row, col, True)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   121
            self.ResizeRow(grid, row)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   122
                
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   123
    def AppendItem(self, data):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   124
        self.data.append(data)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   125
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   126
    def InsertItem(self, idx, data):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   127
        self.data.insert(idx, data)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   128
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   129
    def RemoveItem(self, idx):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   130
        self.data.pop(idx)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   131
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   132
    def MoveItem(self, idx, new_idx):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   133
        self.data.insert(new_idx, self.data.pop(idx))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   134
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   135
    def GetItem(self, idx):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   136
        return self.data[idx]
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   137
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   138
class DebugVariableDropTarget(wx.TextDropTarget):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   139
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   140
    def __init__(self, parent):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   141
        wx.TextDropTarget.__init__(self)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   142
        self.ParentWindow = parent
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   143
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   144
    def OnDropText(self, x, y, data):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   145
        x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   146
        row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   147
        if row == wx.NOT_FOUND:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   148
            row = self.ParentWindow.Table.GetNumberRows()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   149
        message = None
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   150
        try:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   151
            values = eval(data)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   152
        except:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   153
            message = _("Invalid value \"%s\" for debug variable")%data
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   154
            values = None
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   155
        if not isinstance(values, TupleType):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   156
            message = _("Invalid value \"%s\" for debug variable")%data
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   157
            values = None
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   158
        if values is not None and values[1] == "debug":
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   159
            self.ParentWindow.InsertValue(values[0], row)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   160
        if message is not None:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   161
            wx.CallAfter(self.ShowMessage, message)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   162
            
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   163
    def ShowMessage(self, message):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   164
        dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   165
        dialog.ShowModal()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   166
        dialog.Destroy()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   167
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   168
class DebugVariablePanel(wx.Panel, DebugViewer):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   169
    
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   170
    def __init__(self, parent, producer):
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   171
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   172
        DebugViewer.__init__(self, producer, True)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   173
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   174
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   175
        main_sizer.AddGrowableCol(0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   176
        main_sizer.AddGrowableRow(1)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   177
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   178
        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   179
        main_sizer.AddSizer(button_sizer, border=5, 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   180
              flag=wx.ALIGN_RIGHT|wx.ALL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   181
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   182
        for name, bitmap, help in [
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   183
                ("DeleteButton", "remove_element", _("Remove debug variable")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   184
                ("UpButton", "up", _("Move debug variable up")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   185
                ("DownButton", "down", _("Move debug variable down"))]:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   186
            button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   187
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   188
            button.SetToolTipString(help)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   189
            setattr(self, name, button)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   190
            button_sizer.AddWindow(button, border=5, flag=wx.LEFT)
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   191
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   192
        self.VariablesGrid = CustomGrid(self, size=wx.Size(0, 150), style=wx.VSCROLL)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   193
        self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   194
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, 
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   195
              self.OnVariablesGridCellRightClick)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   196
        main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   197
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   198
        self.SetSizer(main_sizer)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   199
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   200
        self.HasNewData = False
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   201
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   202
        self.Table = DebugVariableTable(self, [], GetDebugVariablesTableColnames())
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   203
        self.VariablesGrid.SetTable(self.Table)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   204
        self.VariablesGrid.SetButtons({"Delete": self.DeleteButton,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   205
                                       "Up": self.UpButton,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 711
diff changeset
   206
                                       "Down": self.DownButton})
711
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   207
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   208
        def _AddVariable(new_row):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   209
            return self.VariablesGrid.GetGridCursorRow()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   210
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   211
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   212
        def _DeleteVariable(row):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   213
            item = self.Table.GetItem(row)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   214
            self.RemoveDataConsumer(item)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   215
            self.Table.RemoveItem(row)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   216
            self.RefreshGrid()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   217
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   218
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   219
        def _MoveVariable(row, move):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   220
            new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   221
            if new_row != row:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   222
                self.Table.MoveItem(row, new_row)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   223
                self.RefreshGrid()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   224
            return new_row
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   225
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   226
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   227
        self.VariablesGrid.SetRowLabelSize(0)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   228
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   229
        for col in range(self.Table.GetNumberCols()):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   230
            attr = wx.grid.GridCellAttr()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   231
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   232
            self.VariablesGrid.SetColAttr(col, attr)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   233
            self.VariablesGrid.SetColSize(col, 100)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   234
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   235
        self.Table.ResetView(self.VariablesGrid)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   236
        self.VariablesGrid.RefreshButtons()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   237
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   238
    def RefreshNewData(self):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   239
        if self.HasNewData:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   240
            self.HasNewData = False
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   241
            self.RefreshGrid()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   242
        DebugViewer.RefreshNewData(self)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   243
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   244
    def RefreshGrid(self):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   245
        self.Freeze()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   246
        self.Table.ResetView(self.VariablesGrid)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   247
        self.VariablesGrid.RefreshButtons()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   248
        self.Thaw()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   249
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   250
    def UnregisterObsoleteData(self):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   251
        items = [(idx, item) for idx, item in enumerate(self.Table.GetData())]
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   252
        items.reverse()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   253
        for idx, item in items:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   254
            iec_path = item.GetVariable().upper()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   255
            if self.GetDataType(iec_path) is None:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   256
                self.RemoveDataConsumer(item)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   257
                self.Table.RemoveItem(idx)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   258
            else:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   259
                self.AddDataConsumer(iec_path, item)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   260
        self.Freeze()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   261
        self.Table.ResetView(self.VariablesGrid)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   262
        self.VariablesGrid.RefreshButtons()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   263
        self.Thaw()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   264
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   265
    def ResetGrid(self):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   266
        self.DeleteDataConsumers()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   267
        self.Table.Empty()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   268
        self.Freeze()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   269
        self.Table.ResetView(self.VariablesGrid)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   270
        self.VariablesGrid.RefreshButtons()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   271
        self.Thaw()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   272
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   273
    def GetForceVariableMenuFunction(self, iec_path, item):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   274
        iec_type = self.GetDataType(iec_path)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   275
        def ForceVariableFunction(event):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   276
            if iec_type is not None:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   277
                dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   278
                if dialog.ShowModal() == wx.ID_OK:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   279
                    self.ForceDataValue(iec_path, dialog.GetValue())
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   280
        return ForceVariableFunction
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   281
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   282
    def GetReleaseVariableMenuFunction(self, iec_path):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   283
        def ReleaseVariableFunction(event):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   284
            self.ReleaseDataValue(iec_path)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   285
        return ReleaseVariableFunction
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   286
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   287
    def OnVariablesGridCellRightClick(self, event):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   288
        row, col = event.GetRow(), event.GetCol()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   289
        if self.Table.GetColLabelValue(col, False) == "Value":
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   290
            iec_path = self.Table.GetValueByName(row, "Variable").upper()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   291
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   292
            menu = wx.Menu(title='')
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   293
            
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   294
            new_id = wx.NewId()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   295
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   296
            self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.Table.GetItem(row)), id=new_id)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   297
            
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   298
            new_id = wx.NewId()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   299
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   300
            self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   301
            
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   302
            if self.Table.IsForced(row):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   303
                menu.Enable(new_id, True)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   304
            else:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   305
                menu.Enable(new_id, False)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   306
            
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   307
            self.PopupMenu(menu)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   308
            
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   309
            menu.Destroy()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   310
        event.Skip()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   311
    
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   312
    def InsertValue(self, iec_path, idx = None, force=False):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   313
        if idx is None:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   314
            idx = self.Table.GetNumberRows()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   315
        for item in self.Table.GetData():
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   316
            if iec_path == item.GetVariable():
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   317
                return
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   318
        item = VariableTableItem(self, iec_path, "")
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   319
        result = self.AddDataConsumer(iec_path.upper(), item)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   320
        if result is not None or force:
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   321
            self.Table.InsertItem(idx, item)
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   322
            self.RefreshGrid()
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   323
        
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   324
    def GetDebugVariables(self):
5f6a743dcde5 Adding support for exporting graph value to csv formatted string to clipboard
Laurent Bessard
parents:
diff changeset
   325
        return [item.GetVariable() for item in self.Table.GetData()]