controls/PouInstanceVariablesPanel.py
author Laurent Bessard
Fri, 13 Jul 2012 12:42:38 +0200
changeset 725 7c44fc339889
parent 714 131ea7f237b9
permissions -rw-r--r--
Fix bug with FBDBlockDialog on Beremiz
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
f10449b18dbe refactoring
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
f10449b18dbe refactoring
laurent
parents:
diff changeset
     3
f10449b18dbe refactoring
laurent
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
f10449b18dbe refactoring
laurent
parents:
diff changeset
     5
#based on the plcopen standard. 
f10449b18dbe refactoring
laurent
parents:
diff changeset
     6
#
f10449b18dbe refactoring
laurent
parents:
diff changeset
     7
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
f10449b18dbe refactoring
laurent
parents:
diff changeset
     8
#
f10449b18dbe refactoring
laurent
parents:
diff changeset
     9
#See COPYING file for copyrights details.
f10449b18dbe refactoring
laurent
parents:
diff changeset
    10
#
f10449b18dbe refactoring
laurent
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
f10449b18dbe refactoring
laurent
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
f10449b18dbe refactoring
laurent
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
f10449b18dbe refactoring
laurent
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
f10449b18dbe refactoring
laurent
parents:
diff changeset
    15
#
f10449b18dbe refactoring
laurent
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
f10449b18dbe refactoring
laurent
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
f10449b18dbe refactoring
laurent
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f10449b18dbe refactoring
laurent
parents:
diff changeset
    19
#General Public License for more details.
f10449b18dbe refactoring
laurent
parents:
diff changeset
    20
#
f10449b18dbe refactoring
laurent
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
f10449b18dbe refactoring
laurent
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
f10449b18dbe refactoring
laurent
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
f10449b18dbe refactoring
laurent
parents:
diff changeset
    24
f10449b18dbe refactoring
laurent
parents:
diff changeset
    25
import wx
f10449b18dbe refactoring
laurent
parents:
diff changeset
    26
import wx.lib.buttons
f10449b18dbe refactoring
laurent
parents:
diff changeset
    27
import wx.lib.agw.customtreectrl as CT
f10449b18dbe refactoring
laurent
parents:
diff changeset
    28
f10449b18dbe refactoring
laurent
parents:
diff changeset
    29
from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    30
from utils.BitmapLibrary import GetBitmap
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    31
f10449b18dbe refactoring
laurent
parents:
diff changeset
    32
class PouInstanceVariablesPanel(wx.Panel):
f10449b18dbe refactoring
laurent
parents:
diff changeset
    33
    
f10449b18dbe refactoring
laurent
parents:
diff changeset
    34
    def __init__(self, parent, window, controller, debug):
f10449b18dbe refactoring
laurent
parents:
diff changeset
    35
        wx.Panel.__init__(self, name='PouInstanceTreePanel', 
f10449b18dbe refactoring
laurent
parents:
diff changeset
    36
                parent=parent, pos=wx.Point(0, 0), 
f10449b18dbe refactoring
laurent
parents:
diff changeset
    37
                size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
f10449b18dbe refactoring
laurent
parents:
diff changeset
    38
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    39
        self.ParentButton = wx.lib.buttons.GenBitmapButton(self,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    40
              bitmap=GetBitmap("top"), size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    41
        self.ParentButton.SetToolTipString(_("Parent instance"))
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    42
        self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick, 
f10449b18dbe refactoring
laurent
parents:
diff changeset
    43
                self.ParentButton)
f10449b18dbe refactoring
laurent
parents:
diff changeset
    44
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    45
        self.InstanceChoice = wx.ComboBox(self, style=wx.CB_READONLY)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    46
        self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
f10449b18dbe refactoring
laurent
parents:
diff changeset
    47
                self.InstanceChoice)
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
    48
        self.InstanceChoice.Bind(wx.EVT_LEFT_DOWN, self.OnInstanceChoiceLeftDown)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    49
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    50
        self.DebugButton = wx.lib.buttons.GenBitmapButton(self, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    51
              bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    52
        self.ParentButton.SetToolTipString(_("Debug instance"))
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    53
        self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
f10449b18dbe refactoring
laurent
parents:
diff changeset
    54
                self.DebugButton)
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
    55
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    56
        self.VariablesList = CT.CustomTreeCtrl(self,
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    57
              style=wx.SUNKEN_BORDER,
f10449b18dbe refactoring
laurent
parents:
diff changeset
    58
              agwStyle=CT.TR_NO_BUTTONS|
f10449b18dbe refactoring
laurent
parents:
diff changeset
    59
                       CT.TR_SINGLE|
f10449b18dbe refactoring
laurent
parents:
diff changeset
    60
                       CT.TR_HAS_VARIABLE_ROW_HEIGHT|
f10449b18dbe refactoring
laurent
parents:
diff changeset
    61
                       CT.TR_HIDE_ROOT|
686
3216bf5f711d Fixed instances treecontrol display
Edouard Tisserant
parents: 684
diff changeset
    62
                       CT.TR_NO_LINES|
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
    63
                       getattr(CT, "TR_ALIGN_WINDOWS_RIGHT", CT.TR_ALIGN_WINDOWS))
686
3216bf5f711d Fixed instances treecontrol display
Edouard Tisserant
parents: 684
diff changeset
    64
        self.VariablesList.SetIndent(0)
3216bf5f711d Fixed instances treecontrol display
Edouard Tisserant
parents: 684
diff changeset
    65
        self.VariablesList.SetSpacing(5)
3216bf5f711d Fixed instances treecontrol display
Edouard Tisserant
parents: 684
diff changeset
    66
        self.VariablesList.DoSelectItem = lambda *x,**y:True
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    67
        self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
f10449b18dbe refactoring
laurent
parents:
diff changeset
    68
                self.OnVariablesListItemActivated)
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
    69
        self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    70
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
    71
        buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    72
        buttons_sizer.AddWindow(self.ParentButton)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    73
        buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    74
        buttons_sizer.AddWindow(self.DebugButton)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    75
        buttons_sizer.AddGrowableCol(1)
f10449b18dbe refactoring
laurent
parents:
diff changeset
    76
        buttons_sizer.AddGrowableRow(0)
f10449b18dbe refactoring
laurent
parents:
diff changeset
    77
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
    78
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    79
        main_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
    80
        main_sizer.AddWindow(self.VariablesList, flag=wx.GROW)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
    81
        main_sizer.AddGrowableCol(0)
f10449b18dbe refactoring
laurent
parents:
diff changeset
    82
        main_sizer.AddGrowableRow(1)
f10449b18dbe refactoring
laurent
parents:
diff changeset
    83
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
    84
        self.SetSizer(main_sizer)
f10449b18dbe refactoring
laurent
parents:
diff changeset
    85
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
    86
        self.ParentWindow = window
f10449b18dbe refactoring
laurent
parents:
diff changeset
    87
        self.Controller = controller
f10449b18dbe refactoring
laurent
parents:
diff changeset
    88
        self.Debug = debug
f10449b18dbe refactoring
laurent
parents:
diff changeset
    89
        if not self.Debug:
f10449b18dbe refactoring
laurent
parents:
diff changeset
    90
            self.DebugButton.Hide()
f10449b18dbe refactoring
laurent
parents:
diff changeset
    91
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
    92
        self.PouTagName = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
    93
        self.PouInfos = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
    94
        self.PouInstance = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
    95
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
    96
    def __del__(self):
f10449b18dbe refactoring
laurent
parents:
diff changeset
    97
        self.Controller = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
    98
    
f10449b18dbe refactoring
laurent
parents:
diff changeset
    99
    def SetTreeImageList(self, tree_image_list):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   100
        self.VariablesList.SetImageList(tree_image_list)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   101
    
f10449b18dbe refactoring
laurent
parents:
diff changeset
   102
    def SetController(self, controller):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   103
        self.Controller = controller
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   104
    
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   105
        self.RefreshView()
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   106
    
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   107
    def SetPouType(self, tagname, pou_instance=None):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   108
        self.PouTagName = tagname
f10449b18dbe refactoring
laurent
parents:
diff changeset
   109
        if pou_instance is not None:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   110
            self.PouInstance = pou_instance
f10449b18dbe refactoring
laurent
parents:
diff changeset
   111
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
   112
        self.RefreshView()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   113
    
f10449b18dbe refactoring
laurent
parents:
diff changeset
   114
    def ResetView(self):
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   115
        self.Controller = None
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   116
        
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   117
        self.PouTagName = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
   118
        self.PouInfos = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
   119
        self.PouInstance = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
   120
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
   121
        self.RefreshView()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   122
    
f10449b18dbe refactoring
laurent
parents:
diff changeset
   123
    def RefreshView(self):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   124
        self.VariablesList.DeleteAllItems()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   125
        self.InstanceChoice.Clear()
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   126
        self.InstanceChoice.SetValue("")
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   127
        
701
25fbbb005a30 Fix bug in POUinstanceVariablesPanel when no tagname defined
Laurent Bessard
parents: 692
diff changeset
   128
        if self.Controller is not None and self.PouTagName is not None:
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   129
            self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   130
        else:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   131
            self.PouInfos = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
   132
        if self.PouInfos is not None:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   133
            root = self.VariablesList.AddRoot("")
f10449b18dbe refactoring
laurent
parents:
diff changeset
   134
            for var_infos in self.PouInfos["variables"]:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   135
                if var_infos.get("type", None) is not None:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   136
                    text = "%(name)s (%(type)s)" % var_infos
f10449b18dbe refactoring
laurent
parents:
diff changeset
   137
                else:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   138
                    text = var_infos["name"]
f10449b18dbe refactoring
laurent
parents:
diff changeset
   139
                
f10449b18dbe refactoring
laurent
parents:
diff changeset
   140
                panel = wx.Panel(self.VariablesList)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   141
                    
f10449b18dbe refactoring
laurent
parents:
diff changeset
   142
                buttons = []
f10449b18dbe refactoring
laurent
parents:
diff changeset
   143
                if var_infos["class"] in ITEMS_VARIABLE:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   144
                    if (var_infos["debug"] and self.Debug and
f10449b18dbe refactoring
laurent
parents:
diff changeset
   145
                        (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or
f10449b18dbe refactoring
laurent
parents:
diff changeset
   146
                         self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   147
                        graph_button = wx.lib.buttons.GenBitmapButton(panel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   148
                              bitmap=GetBitmap("instance_graph"), 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   149
                              size=wx.Size(28, 28), style=wx.NO_BORDER)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   150
                        self.Bind(wx.EVT_BUTTON, self.GenGraphButtonCallback(var_infos), graph_button)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   151
                        buttons.append(graph_button)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   152
                elif var_infos["edit"]:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   153
                    edit_button = wx.lib.buttons.GenBitmapButton(panel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   154
                          bitmap=GetBitmap("edit"), 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   155
                          size=wx.Size(28, 28), style=wx.NO_BORDER)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   156
                    self.Bind(wx.EVT_BUTTON, self.GenEditButtonCallback(var_infos), edit_button)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   157
                    buttons.append(edit_button)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   158
                
f10449b18dbe refactoring
laurent
parents:
diff changeset
   159
                if var_infos["debug"] and self.Debug:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   160
                    debug_button = wx.lib.buttons.GenBitmapButton(panel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   161
                          bitmap=GetBitmap("debug_instance"), 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 701
diff changeset
   162
                          size=wx.Size(28, 28), style=wx.NO_BORDER)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   163
                    self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   164
                    buttons.append(debug_button)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   165
                
f10449b18dbe refactoring
laurent
parents:
diff changeset
   166
                button_num = len(buttons)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   167
                if button_num > 0:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   168
                    panel.SetSize(wx.Size(button_num * 32, 28))
f10449b18dbe refactoring
laurent
parents:
diff changeset
   169
                    panel.SetBackgroundColour(self.VariablesList.GetBackgroundColour())
f10449b18dbe refactoring
laurent
parents:
diff changeset
   170
                    panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   171
                    panel.SetSizer(panel_sizer)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   172
                    
f10449b18dbe refactoring
laurent
parents:
diff changeset
   173
                    for button in buttons:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   174
                        panel_sizer.AddWindow(button, 0, border=4, flag=wx.LEFT)
692
e00ce7077bfc Fix bugs on PouInstanceVariablesPanel
laurent
parents: 687
diff changeset
   175
                    panel_sizer.Layout()
e00ce7077bfc Fix bugs on PouInstanceVariablesPanel
laurent
parents: 687
diff changeset
   176
                    
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   177
                else:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   178
                    panel.Destroy()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   179
                    panel = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
   180
                
f10449b18dbe refactoring
laurent
parents:
diff changeset
   181
                item = self.VariablesList.AppendItem(root, text, wnd=panel)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   182
                self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"]))
f10449b18dbe refactoring
laurent
parents:
diff changeset
   183
                self.VariablesList.SetPyData(item, var_infos)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   184
            
f10449b18dbe refactoring
laurent
parents:
diff changeset
   185
            instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   186
            for instance in instances:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   187
                self.InstanceChoice.Append(instance)
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   188
            if len(instances) == 1:
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   189
                self.PouInstance = instances[0]
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   190
            if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   191
                self.PouInstance = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
   192
                self.InstanceChoice.SetSelection(0)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   193
            elif self.PouInstance in instances:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   194
                self.InstanceChoice.SetStringSelection(self.PouInstance)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   195
            else:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   196
                self.PouInstance = None
f10449b18dbe refactoring
laurent
parents:
diff changeset
   197
                self.InstanceChoice.SetValue(_("Select an instance"))
f10449b18dbe refactoring
laurent
parents:
diff changeset
   198
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
   199
        self.RefreshButtons()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   200
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
   201
    def RefreshButtons(self):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   202
        enabled = self.InstanceChoice.GetSelection() != -1
f10449b18dbe refactoring
laurent
parents:
diff changeset
   203
        self.ParentButton.Enable(enabled and self.PouInfos["class"] != ITEM_CONFIGURATION)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   204
        self.DebugButton.Enable(enabled and self.PouInfos["debug"] and self.Debug)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   205
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
   206
        root = self.VariablesList.GetRootItem()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   207
        if root is not None and root.IsOk():
f10449b18dbe refactoring
laurent
parents:
diff changeset
   208
            item, item_cookie = self.VariablesList.GetFirstChild(root)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   209
            while item is not None and item.IsOk():
f10449b18dbe refactoring
laurent
parents:
diff changeset
   210
                panel = self.VariablesList.GetItemWindow(item)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   211
                if panel is not None:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   212
                    for child in panel.GetChildren():
f10449b18dbe refactoring
laurent
parents:
diff changeset
   213
                        if child.GetName() != "edit":
f10449b18dbe refactoring
laurent
parents:
diff changeset
   214
                            child.Enable(enabled)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   215
                item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   216
    
f10449b18dbe refactoring
laurent
parents:
diff changeset
   217
    def GenEditButtonCallback(self, infos):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   218
        def EditButtonCallback(event):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   219
            var_class = infos["class"]
f10449b18dbe refactoring
laurent
parents:
diff changeset
   220
            if var_class == ITEM_RESOURCE:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   221
                tagname = self.Controller.ComputeConfigurationResourceName(
f10449b18dbe refactoring
laurent
parents:
diff changeset
   222
                    self.InstanceChoice.GetStringSelection(), 
f10449b18dbe refactoring
laurent
parents:
diff changeset
   223
                    infos["name"])
f10449b18dbe refactoring
laurent
parents:
diff changeset
   224
            else:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   225
                var_class = ITEM_POU
f10449b18dbe refactoring
laurent
parents:
diff changeset
   226
                tagname = self.Controller.ComputePouName(infos["type"])
f10449b18dbe refactoring
laurent
parents:
diff changeset
   227
            self.ParentWindow.EditProjectElement(var_class, tagname)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   228
            event.Skip()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   229
        return EditButtonCallback
f10449b18dbe refactoring
laurent
parents:
diff changeset
   230
    
f10449b18dbe refactoring
laurent
parents:
diff changeset
   231
    def GenDebugButtonCallback(self, infos):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   232
        def DebugButtonCallback(event):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   233
            if self.InstanceChoice.GetSelection() != -1:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   234
                var_class = infos["class"]
f10449b18dbe refactoring
laurent
parents:
diff changeset
   235
                var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
f10449b18dbe refactoring
laurent
parents:
diff changeset
   236
                                      infos["name"])
f10449b18dbe refactoring
laurent
parents:
diff changeset
   237
                if var_class in ITEMS_VARIABLE:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   238
                    self.ParentWindow.AddDebugVariable(var_path, force=True)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   239
                else:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   240
                    self.ParentWindow.OpenDebugViewer(
f10449b18dbe refactoring
laurent
parents:
diff changeset
   241
                        infos["class"],
f10449b18dbe refactoring
laurent
parents:
diff changeset
   242
                        var_path,
f10449b18dbe refactoring
laurent
parents:
diff changeset
   243
                        self.Controller.ComputePouName(infos["type"]))
f10449b18dbe refactoring
laurent
parents:
diff changeset
   244
            event.Skip()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   245
        return DebugButtonCallback
f10449b18dbe refactoring
laurent
parents:
diff changeset
   246
    
f10449b18dbe refactoring
laurent
parents:
diff changeset
   247
    def GenGraphButtonCallback(self, infos):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   248
        def GraphButtonCallback(event):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   249
            if self.InstanceChoice.GetSelection() != -1:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   250
                if infos["class"] in ITEMS_VARIABLE:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   251
                    var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
f10449b18dbe refactoring
laurent
parents:
diff changeset
   252
                                          infos["name"])
f10449b18dbe refactoring
laurent
parents:
diff changeset
   253
                    self.ParentWindow.OpenGraphicViewer(var_path)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   254
            event.Skip()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   255
        return GraphButtonCallback
f10449b18dbe refactoring
laurent
parents:
diff changeset
   256
    
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   257
    def ShowInstanceChoicePopup(self):
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   258
        self.InstanceChoice.SetFocusFromKbd()
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   259
        size = self.InstanceChoice.GetSize()
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   260
        event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   261
        event.m_x = size.width / 2
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   262
        event.m_y = size.height / 2
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   263
        event.SetEventObject(self.InstanceChoice)
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   264
        #event = wx.KeyEvent(wx.EVT_KEY_DOWN._getEvtType())
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   265
        #event.m_keyCode = wx.WXK_SPACE
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   266
        self.InstanceChoice.GetEventHandler().ProcessEvent(event)
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   267
    
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   268
    def OnParentButtonClick(self, event):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   269
        if self.InstanceChoice.GetSelection() != -1:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   270
            parent_path = self.InstanceChoice.GetStringSelection().rsplit(".", 1)[0]
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   271
            tagname = self.Controller.GetPouInstanceTagName(parent_path, self.Debug)
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   272
            if tagname is not None:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   273
                wx.CallAfter(self.SetPouType, tagname, parent_path)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   274
                wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   275
        event.Skip()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   276
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
   277
    def OnInstanceChoiceChanged(self, event):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   278
        self.RefreshButtons()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   279
        event.Skip()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   280
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
   281
    def OnDebugButtonClick(self, event):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   282
        if self.InstanceChoice.GetSelection() != -1:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   283
            self.ParentWindow.OpenDebugViewer(
f10449b18dbe refactoring
laurent
parents:
diff changeset
   284
                self.PouInfos["class"],
f10449b18dbe refactoring
laurent
parents:
diff changeset
   285
                self.InstanceChoice.GetStringSelection(),
f10449b18dbe refactoring
laurent
parents:
diff changeset
   286
                self.PouTagName)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   287
        event.Skip()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   288
        
f10449b18dbe refactoring
laurent
parents:
diff changeset
   289
    def OnVariablesListItemActivated(self, event):
f10449b18dbe refactoring
laurent
parents:
diff changeset
   290
        if self.InstanceChoice.GetSelection() != -1:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   291
            instance_path = self.InstanceChoice.GetStringSelection()
686
3216bf5f711d Fixed instances treecontrol display
Edouard Tisserant
parents: 684
diff changeset
   292
            selected_item = event.GetItem()
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   293
            if selected_item is not None and selected_item.IsOk():
f10449b18dbe refactoring
laurent
parents:
diff changeset
   294
                item_infos = self.VariablesList.GetPyData(selected_item)
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   295
                if item_infos is not None and item_infos["class"] not in ITEMS_VARIABLE:
684
f10449b18dbe refactoring
laurent
parents:
diff changeset
   296
                    if item_infos["class"] == ITEM_RESOURCE:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   297
                        tagname = self.Controller.ComputeConfigurationResourceName(
f10449b18dbe refactoring
laurent
parents:
diff changeset
   298
                                       instance_path, 
f10449b18dbe refactoring
laurent
parents:
diff changeset
   299
                                       item_infos["name"])
f10449b18dbe refactoring
laurent
parents:
diff changeset
   300
                    else:
f10449b18dbe refactoring
laurent
parents:
diff changeset
   301
                        tagname = self.Controller.ComputePouName(item_infos["type"])
f10449b18dbe refactoring
laurent
parents:
diff changeset
   302
                    item_path = "%s.%s" % (instance_path, item_infos["name"])
f10449b18dbe refactoring
laurent
parents:
diff changeset
   303
                    wx.CallAfter(self.SetPouType, tagname, item_path)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   304
                    wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
f10449b18dbe refactoring
laurent
parents:
diff changeset
   305
        event.Skip()
f10449b18dbe refactoring
laurent
parents:
diff changeset
   306
    
687
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   307
    def OnVariablesListLeftDown(self, event):
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   308
        if self.InstanceChoice.GetSelection() == -1:
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   309
            wx.CallAfter(self.ShowInstanceChoicePopup)
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   310
        event.Skip()
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   311
        
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   312
    def OnInstanceChoiceLeftDown(self, event):
629680fb0582 refactoring
laurent
parents: 686
diff changeset
   313
        event.Skip()