controls/PouInstanceVariablesPanel.py
author Edouard Tisserant
Mon, 11 Mar 2013 19:17:56 +0900
changeset 972 659198075ce4
parent 930 4be515ac635e
child 1031 5743398071eb
permissions -rw-r--r--
Redirect PyEval exceptions to logging
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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import wx.lib.buttons
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx.lib.agw.customtreectrl as CT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    29
try:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    30
    import matplotlib
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    31
    matplotlib.use('WX')
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    32
    USE_MPL = True
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    33
except:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    34
    USE_MPL = False
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    35
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
    36
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
    37
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
class PouInstanceVariablesPanel(wx.Panel):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
    def __init__(self, parent, window, controller, debug):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
        wx.Panel.__init__(self, name='PouInstanceTreePanel', 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
                parent=parent, pos=wx.Point(0, 0), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
                size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
        self.ParentButton = wx.lib.buttons.GenBitmapButton(self,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
              bitmap=GetBitmap("top"), size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
        self.ParentButton.SetToolTipString(_("Parent instance"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
                self.ParentButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
        
821
3667bb14aeca Fix bug debug instance button not visible in PouInstanceVariablesPanel when instance path is too long
laurent
parents: 814
diff changeset
    52
        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
    53
        self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
                self.InstanceChoice)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        self.InstanceChoice.Bind(wx.EVT_LEFT_DOWN, self.OnInstanceChoiceLeftDown)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        self.DebugButton = wx.lib.buttons.GenBitmapButton(self, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
              bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        self.ParentButton.SetToolTipString(_("Debug instance"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
                self.DebugButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        self.VariablesList = CT.CustomTreeCtrl(self,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
              style=wx.SUNKEN_BORDER,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
              agwStyle=CT.TR_NO_BUTTONS|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
                       CT.TR_SINGLE|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
                       CT.TR_HAS_VARIABLE_ROW_HEIGHT|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
                       CT.TR_HIDE_ROOT|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
                       CT.TR_NO_LINES|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
                       getattr(CT, "TR_ALIGN_WINDOWS_RIGHT", CT.TR_ALIGN_WINDOWS))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        self.VariablesList.SetIndent(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        self.VariablesList.SetSpacing(5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        self.VariablesList.DoSelectItem = lambda *x,**y:True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
                self.OnVariablesListItemActivated)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
        self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        buttons_sizer.AddWindow(self.ParentButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        buttons_sizer.AddWindow(self.DebugButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        buttons_sizer.AddGrowableCol(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        buttons_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        main_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        main_sizer.AddWindow(self.VariablesList, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        main_sizer.AddGrowableRow(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        self.ParentWindow = window
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        self.Controller = controller
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
        self.Debug = debug
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        if not self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
            self.DebugButton.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        self.PouTagName = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        self.Controller = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
    def SetTreeImageList(self, tree_image_list):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        self.VariablesList.SetImageList(tree_image_list)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
    def SetController(self, controller):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        self.Controller = controller
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.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
    def SetPouType(self, tagname, pou_instance=None):
915
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   115
        if  self.Controller is not None:
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   116
            self.PouTagName = tagname
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   117
            if self.PouTagName == "Project":
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   118
                config_name = self.Controller.GetProjectMainConfigurationName()
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   119
                if config_name is not None:
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   120
                    self.PouTagName = self.Controller.ComputeConfigurationName(config_name)
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   121
            if pou_instance is not None:
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   122
                self.PouInstance = pou_instance
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
    def ResetView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
        self.Controller = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
        self.PouTagName = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
        self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
        self.PouInstance = None
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 RefreshView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
        self.VariablesList.DeleteAllItems()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
        self.InstanceChoice.Clear()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        self.InstanceChoice.SetValue("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
        if self.Controller is not None and self.PouTagName is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
            self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
            self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
        if self.PouInfos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
            root = self.VariablesList.AddRoot("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
            for var_infos in self.PouInfos["variables"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
                if var_infos.get("type", None) is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
                    text = "%(name)s (%(type)s)" % var_infos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
                    text = var_infos["name"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
                panel = wx.Panel(self.VariablesList)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
                    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
                buttons = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
                if var_infos["class"] in ITEMS_VARIABLE:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
   156
                    if (not USE_MPL and var_infos["debug"] and self.Debug and
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
                        (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
                         self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
                        graph_button = wx.lib.buttons.GenBitmapButton(panel, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
                              bitmap=GetBitmap("instance_graph"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
                              size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
                        self.Bind(wx.EVT_BUTTON, self.GenGraphButtonCallback(var_infos), graph_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
                        buttons.append(graph_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
                elif var_infos["edit"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
                    edit_button = wx.lib.buttons.GenBitmapButton(panel, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
                          bitmap=GetBitmap("edit"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
                          size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
                    self.Bind(wx.EVT_BUTTON, self.GenEditButtonCallback(var_infos), edit_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
                    buttons.append(edit_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
                if var_infos["debug"] and self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
                    debug_button = wx.lib.buttons.GenBitmapButton(panel, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
                          bitmap=GetBitmap("debug_instance"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
                          size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
                    self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
                    buttons.append(debug_button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
                button_num = len(buttons)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
                if button_num > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
                    panel.SetSize(wx.Size(button_num * 32, 28))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
                    panel.SetBackgroundColour(self.VariablesList.GetBackgroundColour())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
                    panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
                    panel.SetSizer(panel_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
                    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
                    for button in buttons:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
                        panel_sizer.AddWindow(button, 0, border=4, flag=wx.LEFT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
                    panel_sizer.Layout()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
                    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
                    panel.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
                    panel = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
                item = self.VariablesList.AppendItem(root, text, wnd=panel)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
                self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
                self.VariablesList.SetPyData(item, var_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
            instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
            for instance in instances:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
                self.InstanceChoice.Append(instance)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
            if len(instances) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
                self.PouInstance = instances[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
            if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
                self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
                self.InstanceChoice.SetSelection(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
            elif self.PouInstance in instances:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
                self.InstanceChoice.SetStringSelection(self.PouInstance)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
                self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
                self.InstanceChoice.SetValue(_("Select an instance"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
        self.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
    def RefreshButtons(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
        enabled = self.InstanceChoice.GetSelection() != -1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
        self.ParentButton.Enable(enabled and self.PouInfos["class"] != ITEM_CONFIGURATION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
        self.DebugButton.Enable(enabled and self.PouInfos["debug"] and self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
        root = self.VariablesList.GetRootItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
        if root is not None and root.IsOk():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
            item, item_cookie = self.VariablesList.GetFirstChild(root)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
            while item is not None and item.IsOk():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
                panel = self.VariablesList.GetItemWindow(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
                if panel is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
                    for child in panel.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
                        if child.GetName() != "edit":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
                            child.Enable(enabled)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
                item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
    def GenEditButtonCallback(self, infos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
        def EditButtonCallback(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
            var_class = infos["class"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
            if var_class == ITEM_RESOURCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
                tagname = self.Controller.ComputeConfigurationResourceName(
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
                    self.InstanceChoice.GetStringSelection(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
                    infos["name"])
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   236
            elif var_class == ITEM_TRANSITION:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   237
                tagname = self.Controller.ComputePouTransitionName(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   238
                    self.PouTagName.split("::")[1],
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   239
                    infos["name"])
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   240
            elif var_class == ITEM_ACTION:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   241
                tagname = self.Controller.ComputePouActionName(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   242
                    self.PouTagName.split("::")[1],
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   243
                    infos["name"])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
                var_class = ITEM_POU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
                tagname = self.Controller.ComputePouName(infos["type"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
            self.ParentWindow.EditProjectElement(var_class, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
        return EditButtonCallback
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
    def GenDebugButtonCallback(self, infos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
        def DebugButtonCallback(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
            if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
                var_class = infos["class"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
                var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                                      infos["name"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                if var_class in ITEMS_VARIABLE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
                    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
   259
                elif var_class == ITEM_TRANSITION:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   260
                    self.ParentWindow.OpenDebugViewer(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   261
                        var_class,
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   262
                        var_path,
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   263
                        self.Controller.ComputePouTransitionName(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   264
                            self.PouTagName.split("::")[1],
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   265
                            infos["name"]))
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   266
                elif var_class == ITEM_ACTION:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   267
                    self.ParentWindow.OpenDebugViewer(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   268
                        var_class,
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   269
                        var_path,
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   270
                        self.Controller.ComputePouActionName(
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"]))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   273
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   274
                    self.ParentWindow.OpenDebugViewer(
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   275
                        var_class,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
                        var_path,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
                        self.Controller.ComputePouName(infos["type"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
        return DebugButtonCallback
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
    def GenGraphButtonCallback(self, infos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
        def GraphButtonCallback(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
            if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
                if infos["class"] in ITEMS_VARIABLE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
                    var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
                                          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
   287
                    self.ParentWindow.OpenDebugViewer(infos["class"], var_path, infos["type"])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
        return GraphButtonCallback
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
    def ShowInstanceChoicePopup(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
        self.InstanceChoice.SetFocusFromKbd()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
        size = self.InstanceChoice.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
        event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
        event.m_x = size.width / 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
        event.m_y = size.height / 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
        event.SetEventObject(self.InstanceChoice)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
        #event = wx.KeyEvent(wx.EVT_KEY_DOWN._getEvtType())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
        #event.m_keyCode = wx.WXK_SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
        self.InstanceChoice.GetEventHandler().ProcessEvent(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
    def OnParentButtonClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
        if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
            parent_path = self.InstanceChoice.GetStringSelection().rsplit(".", 1)[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
            tagname = self.Controller.GetPouInstanceTagName(parent_path, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
            if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
                wx.CallAfter(self.SetPouType, tagname, parent_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
                wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
    def OnInstanceChoiceChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
        self.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
    def OnDebugButtonClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
        if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
            self.ParentWindow.OpenDebugViewer(
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
                self.PouInfos["class"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
                self.InstanceChoice.GetStringSelection(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
                self.PouTagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
    def OnVariablesListItemActivated(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
        if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
            instance_path = self.InstanceChoice.GetStringSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
            selected_item = event.GetItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
            if selected_item is not None and selected_item.IsOk():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
                item_infos = self.VariablesList.GetPyData(selected_item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
                if item_infos is not None and item_infos["class"] not in ITEMS_VARIABLE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
                    if item_infos["class"] == ITEM_RESOURCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
                        tagname = self.Controller.ComputeConfigurationResourceName(
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
                                       instance_path, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
                                       item_infos["name"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
                        tagname = self.Controller.ComputePouName(item_infos["type"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
                    item_path = "%s.%s" % (instance_path, item_infos["name"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
                    wx.CallAfter(self.SetPouType, tagname, item_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
                    wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
    def OnVariablesListLeftDown(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
        if self.InstanceChoice.GetSelection() == -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
            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
   344
        else:
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   345
            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
   346
            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
   347
            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
   348
                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
   349
                if item_infos is not None and item_infos["class"] in ITEMS_VARIABLE:
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   350
                    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
   351
                    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
   352
                    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
   353
                    dragSource.SetData(data)
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   354
                    dragSource.DoDragDrop()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
    def OnInstanceChoiceLeftDown(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
        event.Skip()