controls/PouInstanceVariablesPanel.py
author Edouard Tisserant
Fri, 02 Aug 2013 08:55:45 +0900
changeset 1281 47131e3388f4
parent 1277 358db9d64aa1
child 1343 a76a020b8822
permissions -rw-r--r--
Various cleanup and optimization
- Deleted shameful dead code here and here...
- Accelerated creation of GenBitmap*Button adding some caching for bitmap grayOut
- Replaced lists inside type use dictionary by sets
- Prevented useless type usage checking when unnecessary
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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import wx
1281
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    26
import wx.lib.agw.customtreectrl as CT
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    27
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    28
import wx.lib.imageutils
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
import wx.lib.buttons
1281
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    30
GrayedBitmapCache = {}
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    31
def SetBitmapLabel(self, bitmap, createOthers=True):
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    32
    """
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    33
    Set the bitmap to display normally.
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    34
    This is the only one that is required. If
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    35
    createOthers is True, then the other bitmaps
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    36
    will be generated on the fly.  Currently,
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    37
    only the disabled bitmap is generated.
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    38
    """
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    39
    self.bmpLabel = bitmap
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    40
    if bitmap is not None and createOthers:
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    41
        GrayBitmap=GrayedBitmapCache.get(bitmap,None)
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    42
        if GrayBitmap is None:
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    43
            image = wx.ImageFromBitmap(bitmap)
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    44
            wx.lib.imageutils.grayOut(image)
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    45
            GrayBitmap = wx.BitmapFromImage(image)
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    46
            GrayedBitmapCache[bitmap] = GrayBitmap
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    47
        self.SetBitmapDisabled(GrayBitmap)
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    48
wx.lib.buttons.GenBitmapButton.SetBitmapLabel = SetBitmapLabel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    50
try:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    51
    import matplotlib
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    52
    matplotlib.use('WX')
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    53
    USE_MPL = True
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    54
except:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    55
    USE_MPL = False
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    56
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
    57
from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU, ITEM_TRANSITION, ITEM_ACTION
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
class PouInstanceVariablesPanel(wx.Panel):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
    def __init__(self, parent, window, controller, debug):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        wx.Panel.__init__(self, name='PouInstanceTreePanel', 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
                parent=parent, pos=wx.Point(0, 0), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
                size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        self.ParentButton = wx.lib.buttons.GenBitmapButton(self,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
              bitmap=GetBitmap("top"), size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        self.ParentButton.SetToolTipString(_("Parent instance"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
        self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
                self.ParentButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        
821
3667bb14aeca Fix bug debug instance button not visible in PouInstanceVariablesPanel when instance path is too long
laurent
parents: 814
diff changeset
    73
        self.InstanceChoice = wx.ComboBox(self, size=wx.Size(0, 0), style=wx.CB_READONLY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
                self.InstanceChoice)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        self.DebugButton = wx.lib.buttons.GenBitmapButton(self, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
              bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER)
1082
5a08404d5dda Fixed bug in PouInstanceVariablesPanel buttons tooltips
Laurent Bessard
parents: 1031
diff changeset
    79
        self.DebugButton.SetToolTipString(_("Debug instance"))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
                self.DebugButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        self.VariablesList = CT.CustomTreeCtrl(self,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
              style=wx.SUNKEN_BORDER,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
              agwStyle=CT.TR_NO_BUTTONS|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
                       CT.TR_SINGLE|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
                       CT.TR_HAS_VARIABLE_ROW_HEIGHT|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
                       CT.TR_HIDE_ROOT|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
                       CT.TR_NO_LINES|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
                       getattr(CT, "TR_ALIGN_WINDOWS_RIGHT", CT.TR_ALIGN_WINDOWS))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        self.VariablesList.SetIndent(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        self.VariablesList.SetSpacing(5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        self.VariablesList.DoSelectItem = lambda *x,**y:True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
                self.OnVariablesListItemActivated)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
1031
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
    97
        self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        buttons_sizer.AddWindow(self.ParentButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        buttons_sizer.AddWindow(self.DebugButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        buttons_sizer.AddGrowableCol(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        buttons_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        main_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        main_sizer.AddWindow(self.VariablesList, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        main_sizer.AddGrowableRow(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
        self.ParentWindow = window
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
        self.Controller = controller
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
        self.Debug = debug
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
        if not self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
            self.DebugButton.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
        self.PouTagName = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
        self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
        self.PouInstance = None
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 __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        self.Controller = None
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 SetTreeImageList(self, tree_image_list):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        self.VariablesList.SetImageList(tree_image_list)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
    def SetController(self, controller):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
        self.Controller = controller
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
    def SetPouType(self, tagname, pou_instance=None):
1222
775b48a2be3b Fixed flickering and lag when refreshing PouInstanceVariablesPanel
Laurent Bessard
parents: 1217
diff changeset
   136
        if self.Controller is not None:
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   137
            if tagname == "Project":
915
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   138
                config_name = self.Controller.GetProjectMainConfigurationName()
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   139
                if config_name is not None:
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   140
                    tagname = self.Controller.ComputeConfigurationName(config_name)
915
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   141
            if pou_instance is not None:
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   142
                self.PouInstance = pou_instance
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   143
            
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   144
            if self.PouTagName != tagname:
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   145
                self.PouTagName = tagname
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   146
                self.RefreshView()
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   147
            else:
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   148
                self.RefreshInstanceChoice()
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   149
        else:
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   150
            self.RefreshView()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
    def ResetView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        self.Controller = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
        self.PouTagName = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
        self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
    def RefreshView(self):
1222
775b48a2be3b Fixed flickering and lag when refreshing PouInstanceVariablesPanel
Laurent Bessard
parents: 1217
diff changeset
   162
        self.Freeze()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
        self.VariablesList.DeleteAllItems()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
        if self.Controller is not None and self.PouTagName is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
            self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
            self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
        if self.PouInfos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
            root = self.VariablesList.AddRoot("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
            for var_infos in self.PouInfos["variables"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
                if var_infos.get("type", None) is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
                    text = "%(name)s (%(type)s)" % var_infos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
                    text = var_infos["name"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
                panel = wx.Panel(self.VariablesList)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
                    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
                buttons = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
                if var_infos["class"] in ITEMS_VARIABLE:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
   181
                    if (not USE_MPL and var_infos["debug"] and self.Debug and
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
                        (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
                         self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
                        graph_button = wx.lib.buttons.GenBitmapButton(panel, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
                              bitmap=GetBitmap("instance_graph"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
                              size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
                        self.Bind(wx.EVT_BUTTON, self.GenGraphButtonCallback(var_infos), graph_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
                        buttons.append(graph_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
                elif var_infos["edit"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
                    edit_button = wx.lib.buttons.GenBitmapButton(panel, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
                          bitmap=GetBitmap("edit"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
                          size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
                    self.Bind(wx.EVT_BUTTON, self.GenEditButtonCallback(var_infos), edit_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
                    buttons.append(edit_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
                if var_infos["debug"] and self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
                    debug_button = wx.lib.buttons.GenBitmapButton(panel, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
                          bitmap=GetBitmap("debug_instance"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
                          size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
                    self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button)
1217
b64dcc1a011f Fixed bug when moving TextViewer and replacing right click by double click when adding graph in Debug Variable Panel
Laurent Bessard
parents: 1214
diff changeset
   201
                    debug_button.Bind(wx.EVT_LEFT_DCLICK, self.GenDebugButtonDClickCallback(var_infos))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
                    buttons.append(debug_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
                button_num = len(buttons)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
                if button_num > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
                    panel.SetSize(wx.Size(button_num * 32, 28))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
                    panel.SetBackgroundColour(self.VariablesList.GetBackgroundColour())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
                    panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
                    panel.SetSizer(panel_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
                    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
                    for button in buttons:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
                        panel_sizer.AddWindow(button, 0, border=4, flag=wx.LEFT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
                    panel_sizer.Layout()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
                    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
                    panel.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
                    panel = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
                item = self.VariablesList.AppendItem(root, text, wnd=panel)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
                self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
                self.VariablesList.SetPyData(item, var_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
            
1238
24577755485d Fixed bug with InstanceChoice values in PouInstanceVariablesPanel
Laurent Bessard
parents: 1233
diff changeset
   223
        self.RefreshInstanceChoice()
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   224
        self.RefreshButtons()
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   225
        
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   226
        self.Thaw()
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   227
    
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   228
    def RefreshInstanceChoice(self):
1238
24577755485d Fixed bug with InstanceChoice values in PouInstanceVariablesPanel
Laurent Bessard
parents: 1233
diff changeset
   229
        self.InstanceChoice.Clear()
24577755485d Fixed bug with InstanceChoice values in PouInstanceVariablesPanel
Laurent Bessard
parents: 1233
diff changeset
   230
        self.InstanceChoice.SetValue("")
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   231
        if self.Controller is not None and self.PouInfos is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
            instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
            for instance in instances:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
                self.InstanceChoice.Append(instance)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
            if len(instances) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
                self.PouInstance = instances[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
            if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
                self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
                self.InstanceChoice.SetSelection(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
            elif self.PouInstance in instances:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
                self.InstanceChoice.SetStringSelection(self.PouInstance)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
                self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
                self.InstanceChoice.SetValue(_("Select an instance"))
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   245
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
    def RefreshButtons(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
        enabled = self.InstanceChoice.GetSelection() != -1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
        self.ParentButton.Enable(enabled and self.PouInfos["class"] != ITEM_CONFIGURATION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
        self.DebugButton.Enable(enabled and self.PouInfos["debug"] and self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
        root = self.VariablesList.GetRootItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
        if root is not None and root.IsOk():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
            item, item_cookie = self.VariablesList.GetFirstChild(root)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
            while item is not None and item.IsOk():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
                panel = self.VariablesList.GetItemWindow(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                if panel is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                    for child in panel.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
                        if child.GetName() != "edit":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
                            child.Enable(enabled)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
                item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
    def GenEditButtonCallback(self, infos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
        def EditButtonCallback(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
            var_class = infos["class"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
            if var_class == ITEM_RESOURCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
                tagname = self.Controller.ComputeConfigurationResourceName(
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
                    self.InstanceChoice.GetStringSelection(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
                    infos["name"])
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   269
            elif var_class == ITEM_TRANSITION:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   270
                tagname = self.Controller.ComputePouTransitionName(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   271
                    self.PouTagName.split("::")[1],
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   272
                    infos["name"])
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   273
            elif var_class == ITEM_ACTION:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   274
                tagname = self.Controller.ComputePouActionName(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   275
                    self.PouTagName.split("::")[1],
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   276
                    infos["name"])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
                var_class = ITEM_POU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
                tagname = self.Controller.ComputePouName(infos["type"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
            self.ParentWindow.EditProjectElement(var_class, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
        return EditButtonCallback
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
    def GenDebugButtonCallback(self, infos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
        def DebugButtonCallback(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
            if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
                var_class = infos["class"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
                var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
                                      infos["name"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
                if var_class in ITEMS_VARIABLE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
                    self.ParentWindow.AddDebugVariable(var_path, force=True)
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   292
                elif var_class == ITEM_TRANSITION:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   293
                    self.ParentWindow.OpenDebugViewer(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   294
                        var_class,
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   295
                        var_path,
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   296
                        self.Controller.ComputePouTransitionName(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   297
                            self.PouTagName.split("::")[1],
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   298
                            infos["name"]))
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   299
                elif var_class == ITEM_ACTION:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   300
                    self.ParentWindow.OpenDebugViewer(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   301
                        var_class,
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   302
                        var_path,
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   303
                        self.Controller.ComputePouActionName(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   304
                            self.PouTagName.split("::")[1],
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   305
                            infos["name"]))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
                    self.ParentWindow.OpenDebugViewer(
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   308
                        var_class,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
                        var_path,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
                        self.Controller.ComputePouName(infos["type"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
        return DebugButtonCallback
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
    
1217
b64dcc1a011f Fixed bug when moving TextViewer and replacing right click by double click when adding graph in Debug Variable Panel
Laurent Bessard
parents: 1214
diff changeset
   314
    def GenDebugButtonDClickCallback(self, infos):
b64dcc1a011f Fixed bug when moving TextViewer and replacing right click by double click when adding graph in Debug Variable Panel
Laurent Bessard
parents: 1214
diff changeset
   315
        def DebugButtonDClickCallback(event):
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   316
            if self.InstanceChoice.GetSelection() != -1:
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   317
                if infos["class"] in ITEMS_VARIABLE:
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   318
                    self.ParentWindow.AddDebugVariable(
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   319
                        "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   320
                                   infos["name"]), 
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   321
                        force=True,
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   322
                        graph=True)
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   323
            event.Skip()
1217
b64dcc1a011f Fixed bug when moving TextViewer and replacing right click by double click when adding graph in Debug Variable Panel
Laurent Bessard
parents: 1214
diff changeset
   324
        return DebugButtonDClickCallback
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1189
diff changeset
   325
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
    def GenGraphButtonCallback(self, infos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
        def GraphButtonCallback(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
            if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
                if infos["class"] in ITEMS_VARIABLE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
                    var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
                                          infos["name"])
885
fc91d3718b74 Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents: 826
diff changeset
   332
                    self.ParentWindow.OpenDebugViewer(infos["class"], var_path, infos["type"])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
        return GraphButtonCallback
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
    def ShowInstanceChoicePopup(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
        self.InstanceChoice.SetFocusFromKbd()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
        size = self.InstanceChoice.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
        event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
        event.m_x = size.width / 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
        event.m_y = size.height / 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
        event.SetEventObject(self.InstanceChoice)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
        #event = wx.KeyEvent(wx.EVT_KEY_DOWN._getEvtType())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
        #event.m_keyCode = wx.WXK_SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
        self.InstanceChoice.GetEventHandler().ProcessEvent(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
    def OnParentButtonClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
        if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
            parent_path = self.InstanceChoice.GetStringSelection().rsplit(".", 1)[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
            tagname = self.Controller.GetPouInstanceTagName(parent_path, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
            if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
                wx.CallAfter(self.SetPouType, tagname, parent_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
                wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
    def OnInstanceChoiceChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
        self.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   360
    def OnDebugButtonClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
        if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
            self.ParentWindow.OpenDebugViewer(
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
                self.PouInfos["class"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
                self.InstanceChoice.GetStringSelection(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
                self.PouTagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   366
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
    def OnVariablesListItemActivated(self, event):
1189
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   369
        selected_item = event.GetItem()
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   370
        if selected_item is not None and selected_item.IsOk():
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   371
            item_infos = self.VariablesList.GetPyData(selected_item)
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   372
            if item_infos is not None and item_infos["class"] not in ITEMS_VARIABLE:
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   373
                instance_path = self.InstanceChoice.GetStringSelection()
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   374
                if item_infos["class"] == ITEM_RESOURCE:
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   375
                    if instance_path != "":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
                        tagname = self.Controller.ComputeConfigurationResourceName(
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
                                       instance_path, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
                                       item_infos["name"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
                    else:
1189
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   380
                        tagname = None
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   381
                else:
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   382
                    tagname = self.Controller.ComputePouName(item_infos["type"])
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   383
                if tagname is not None:
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   384
                    if instance_path != "":
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   385
                        item_path = "%s.%s" % (instance_path, item_infos["name"])
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   386
                    else:
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   387
                        item_path = None
1277
358db9d64aa1 Fixed refresh bug when activating element in instance variables list
Laurent Bessard
parents: 1238
diff changeset
   388
                    self.SetPouType(tagname, item_path)
358db9d64aa1 Fixed refresh bug when activating element in instance variables list
Laurent Bessard
parents: 1238
diff changeset
   389
                    self.ParentWindow.SelectProjectTreeItem(tagname)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
    def OnVariablesListLeftDown(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
        if self.InstanceChoice.GetSelection() == -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
            wx.CallAfter(self.ShowInstanceChoicePopup)
898
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   395
        else:
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   396
            instance_path = self.InstanceChoice.GetStringSelection()
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   397
            item, flags = self.VariablesList.HitTest(event.GetPosition())
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   398
            if item is not None and flags & CT.TREE_HITTEST_ONITEMLABEL:
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   399
                item_infos = self.VariablesList.GetPyData(item)
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   400
                if item_infos is not None and item_infos["class"] in ITEMS_VARIABLE:
1107
9303f6b900fe Fixed Drag'n dropping from PouInstanceVariablesPanel ensuring DebugVariablePanel is visible before starting drag'n drop
Laurent Bessard
parents: 1082
diff changeset
   401
                    self.ParentWindow.EnsureTabVisible(
9303f6b900fe Fixed Drag'n dropping from PouInstanceVariablesPanel ensuring DebugVariablePanel is visible before starting drag'n drop
Laurent Bessard
parents: 1082
diff changeset
   402
                        self.ParentWindow.DebugVariablePanel)
898
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   403
                    item_path = "%s.%s" % (instance_path, item_infos["name"])
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   404
                    data = wx.TextDataObject(str((item_path, "debug")))
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   405
                    dragSource = wx.DropSource(self.VariablesList)
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   406
                    dragSource.SetData(data)
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   407
                    dragSource.DoDragDrop()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
        event.Skip()
1031
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   409
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   410
    def OnVariablesListKeyDown(self, event):
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   411
        keycode = event.GetKeyCode()
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   412
        if keycode != wx.WXK_LEFT:
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   413
            event.Skip()
1277
358db9d64aa1 Fixed refresh bug when activating element in instance variables list
Laurent Bessard
parents: 1238
diff changeset
   414