controls/PouInstanceVariablesPanel.py
author Laurent Bessard
Thu, 03 Oct 2013 19:01:28 +0200
changeset 1343 a76a020b8822
parent 1281 47131e3388f4
child 1348 aee0a7eb833a
permissions -rw-r--r--
Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
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
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    25
from collections import namedtuple
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    26
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
1281
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1277
diff changeset
    28
import wx.lib.agw.customtreectrl as CT
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
import wx.lib.buttons
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    31
try:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    32
    import matplotlib
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    33
    matplotlib.use('WX')
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    34
    USE_MPL = True
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    35
except:
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    36
    USE_MPL = False
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
    37
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    38
# Customize CustomTreeItem for adding icon on item right
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    39
CT.GenericTreeItem._rightimages = []
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    40
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    41
def SetRightImages(self, images):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    42
    self._rightimages = images
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    43
CT.GenericTreeItem.SetRightImages = SetRightImages
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    44
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    45
def GetRightImages(self):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    46
    return self._rightimages
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    47
CT.GenericTreeItem.GetRightImages = GetRightImages
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    48
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    49
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    50
class CustomTreeCtrlWithRightImage(CT.CustomTreeCtrl):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    51
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    52
    def SetRightImageList(self, imageList):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    53
        self._imageListRight = imageList
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    54
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    55
    def GetLineHeight(self, item):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    56
        height = CT.CustomTreeCtrl.GetLineHeight(self, item)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    57
        rightimages = item.GetRightImages()
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    58
        if len(rightimages) > 0:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    59
            r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    60
            return max(height, r_image_h + 8)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    61
        return height
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    62
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    63
    def GetItemRightImagesBBox(self, item):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    64
        rightimages = item.GetRightImages()
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    65
        if len(rightimages) > 0:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    66
            w, h = self.GetClientSize()
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    67
            total_h = self.GetLineHeight(item)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    68
            r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    69
            
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    70
            bbox_width = (r_image_w + 4) * len(rightimages) + 4
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    71
            bbox_height = r_image_h + 8
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    72
            bbox_x = w - bbox_width
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    73
            bbox_y = item.GetY() + ((total_h > r_image_h) and [(total_h-r_image_h)/2] or [0])[0]
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    74
            
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    75
            return wx.Rect(bbox_x, bbox_y, bbox_width, bbox_height)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    76
        
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    77
        return None
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    78
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    79
    def IsOverItemRightImage(self, item, point):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    80
        rightimages = item.GetRightImages()
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    81
        if len(rightimages) > 0:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    82
            point = self.CalcUnscrolledPosition(point)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    83
            r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    84
            images_bbx = self.GetItemRightImagesBBox(item)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    85
            
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    86
            rect = wx.Rect(images_bbx.x + 4, images_bbx.y + 4,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    87
                           r_image_w, r_image_h)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    88
            for r_image in rightimages:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    89
                if rect.Inside(point):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    90
                    return r_image
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    91
                rect.x += r_image_w + 4
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    92
            
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    93
            return None
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    94
                
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    95
    def PaintItem(self, item, dc, level, align):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    96
        CT.CustomTreeCtrl.PaintItem(self, item, dc, level, align)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    97
        
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    98
        rightimages = item.GetRightImages()
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
    99
        if len(rightimages) > 0:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   100
            images_bbx = self.GetItemRightImagesBBox(item)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   101
            r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   102
            
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   103
            dc.SetBrush(wx.WHITE_BRUSH)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   104
            dc.SetPen(wx.TRANSPARENT_PEN)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   105
            
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   106
            bg_width = (r_image_w + 4) * len(rightimages) + 4
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   107
            bg_height = r_image_h + 8
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   108
            dc.DrawRectangle(images_bbx.x, images_bbx.y, 
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   109
                             images_bbx.width, images_bbx.height)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   110
            x_pos = images_bbx.x + 4
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   111
            for r_image in rightimages:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   112
                self._imageListRight.Draw(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   113
                    r_image, dc, x_pos, images_bbx.y + 4,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   114
                    wx.IMAGELIST_DRAW_TRANSPARENT)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   115
                x_pos += r_image_w + 4
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   116
    
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   117
_ButtonCallbacks = namedtuple("ButtonCallbacks", ["leftdown", "dclick"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   118
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   119
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
   120
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
class PouInstanceVariablesPanel(wx.Panel):
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 __init__(self, parent, window, controller, debug):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        wx.Panel.__init__(self, name='PouInstanceTreePanel', 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
                parent=parent, pos=wx.Point(0, 0), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
                size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
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.ParentButton = wx.lib.buttons.GenBitmapButton(self,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
              bitmap=GetBitmap("top"), size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
        self.ParentButton.SetToolTipString(_("Parent instance"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
        self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
                self.ParentButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
        
821
3667bb14aeca Fix bug debug instance button not visible in PouInstanceVariablesPanel when instance path is too long
laurent
parents: 814
diff changeset
   135
        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
   136
        self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
                self.InstanceChoice)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
        self.DebugButton = wx.lib.buttons.GenBitmapButton(self, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
              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
   141
        self.DebugButton.SetToolTipString(_("Debug instance"))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
                self.DebugButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
        
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   145
        self.VariablesList = CustomTreeCtrlWithRightImage(self,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
              style=wx.SUNKEN_BORDER,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
              agwStyle=CT.TR_NO_BUTTONS|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
                       CT.TR_SINGLE|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
                       CT.TR_HAS_VARIABLE_ROW_HEIGHT|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
                       CT.TR_HIDE_ROOT|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
                       CT.TR_NO_LINES|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
                       getattr(CT, "TR_ALIGN_WINDOWS_RIGHT", CT.TR_ALIGN_WINDOWS))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        self.VariablesList.SetIndent(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
        self.VariablesList.SetSpacing(5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
        self.VariablesList.DoSelectItem = lambda *x,**y:True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
        self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
                self.OnVariablesListItemActivated)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        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
   159
        self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
        
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   161
        self.TreeRightImageList = wx.ImageList(24, 24)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   162
        self.InstanceGraphImage = self.TreeRightImageList.Add(GetBitmap("instance_graph"))
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   163
        self.EditImage = self.TreeRightImageList.Add(GetBitmap("edit"))
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   164
        self.DebugInstanceImage = self.TreeRightImageList.Add(GetBitmap("debug_instance"))
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   165
        self.VariablesList.SetRightImageList(self.TreeRightImageList)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   166
        
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   167
        self.ButtonCallBacks = {
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   168
            self.InstanceGraphImage: _ButtonCallbacks(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   169
                self.GraphButtonCallback, None),
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   170
            self.EditImage: _ButtonCallbacks(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   171
                self.EditButtonCallback, None),
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   172
            self.DebugInstanceImage: _ButtonCallbacks(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   173
                self.DebugButtonCallback, self.DebugButtonDClickCallback)}
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   174
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
        buttons_sizer.AddWindow(self.ParentButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
        buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
        buttons_sizer.AddWindow(self.DebugButton)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
        buttons_sizer.AddGrowableCol(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
        buttons_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
        main_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
        main_sizer.AddWindow(self.VariablesList, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
        main_sizer.AddGrowableRow(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
        self.ParentWindow = window
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
        self.Controller = controller
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
        self.Debug = debug
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
        if not self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
            self.DebugButton.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
        self.PouTagName = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
        self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
        self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
        self.Controller = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
    def SetTreeImageList(self, tree_image_list):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
        self.VariablesList.SetImageList(tree_image_list)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
    def SetController(self, controller):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
        self.Controller = controller
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
    def SetPouType(self, tagname, pou_instance=None):
1222
775b48a2be3b Fixed flickering and lag when refreshing PouInstanceVariablesPanel
Laurent Bessard
parents: 1217
diff changeset
   212
        if self.Controller is not None:
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   213
            if tagname == "Project":
915
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   214
                config_name = self.Controller.GetProjectMainConfigurationName()
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   215
                if config_name is not None:
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   216
                    tagname = self.Controller.ComputeConfigurationName(config_name)
915
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   217
            if pou_instance is not None:
8dc28b21bdac Fix bug when closing project
Laurent Bessard
parents: 900
diff changeset
   218
                self.PouInstance = pou_instance
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   219
            
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   220
            if self.PouTagName != tagname:
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   221
                self.PouTagName = tagname
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   222
                self.RefreshView()
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   223
            else:
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   224
                self.RefreshInstanceChoice()
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   225
        else:
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   226
            self.RefreshView()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
    def ResetView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
        self.Controller = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
        self.PouTagName = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
        self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
        self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
    def RefreshView(self):
1222
775b48a2be3b Fixed flickering and lag when refreshing PouInstanceVariablesPanel
Laurent Bessard
parents: 1217
diff changeset
   238
        self.Freeze()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
        self.VariablesList.DeleteAllItems()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
        if self.Controller is not None and self.PouTagName is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
            self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
            self.PouInfos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
        if self.PouInfos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
            root = self.VariablesList.AddRoot("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
            for var_infos in self.PouInfos["variables"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
                if var_infos.get("type", None) is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
                    text = "%(name)s (%(type)s)" % var_infos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
                    text = var_infos["name"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
                
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   253
                right_images = []
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
                if var_infos["class"] in ITEMS_VARIABLE:
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 915
diff changeset
   255
                    if (not USE_MPL and var_infos["debug"] and self.Debug and
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                        (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                         self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))):
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   258
                        right_images.append(self.InstanceGraphImage)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
                elif var_infos["edit"]:
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   260
                    right_images.append(self.EditImage)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
                if var_infos["debug"] and self.Debug:
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   263
                    right_images.append(self.DebugInstanceImage)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   264
                
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   265
                item = self.VariablesList.AppendItem(root, text)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   266
                item.SetRightImages(right_images)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
                self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
                self.VariablesList.SetPyData(item, var_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
            
1238
24577755485d Fixed bug with InstanceChoice values in PouInstanceVariablesPanel
Laurent Bessard
parents: 1233
diff changeset
   270
        self.RefreshInstanceChoice()
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   271
        self.RefreshButtons()
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   272
        
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   273
        self.Thaw()
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   274
    
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   275
    def RefreshInstanceChoice(self):
1238
24577755485d Fixed bug with InstanceChoice values in PouInstanceVariablesPanel
Laurent Bessard
parents: 1233
diff changeset
   276
        self.InstanceChoice.Clear()
24577755485d Fixed bug with InstanceChoice values in PouInstanceVariablesPanel
Laurent Bessard
parents: 1233
diff changeset
   277
        self.InstanceChoice.SetValue("")
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   278
        if self.Controller is not None and self.PouInfos is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
            instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
            for instance in instances:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
                self.InstanceChoice.Append(instance)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
            if len(instances) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
                self.PouInstance = instances[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
            if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
                self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
                self.InstanceChoice.SetSelection(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
            elif self.PouInstance in instances:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
                self.InstanceChoice.SetStringSelection(self.PouInstance)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
                self.PouInstance = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
                self.InstanceChoice.SetValue(_("Select an instance"))
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
   292
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
    def RefreshButtons(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
        enabled = self.InstanceChoice.GetSelection() != -1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
        self.ParentButton.Enable(enabled and self.PouInfos["class"] != ITEM_CONFIGURATION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
        self.DebugButton.Enable(enabled and self.PouInfos["debug"] and self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
        root = self.VariablesList.GetRootItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
        if root is not None and root.IsOk():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
            item, item_cookie = self.VariablesList.GetFirstChild(root)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
            while item is not None and item.IsOk():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
                panel = self.VariablesList.GetItemWindow(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
                if panel is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
                    for child in panel.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
                        if child.GetName() != "edit":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
                            child.Enable(enabled)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
                item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
    
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   309
    def EditButtonCallback(self, infos):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   310
        var_class = infos["class"]
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   311
        if var_class == ITEM_RESOURCE:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   312
            tagname = self.Controller.ComputeConfigurationResourceName(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   313
                self.InstanceChoice.GetStringSelection(), 
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   314
                infos["name"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   315
        elif var_class == ITEM_TRANSITION:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   316
            tagname = self.Controller.ComputePouTransitionName(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   317
                self.PouTagName.split("::")[1],
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   318
                infos["name"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   319
        elif var_class == ITEM_ACTION:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   320
            tagname = self.Controller.ComputePouActionName(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   321
                self.PouTagName.split("::")[1],
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   322
                infos["name"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   323
        else:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   324
            var_class = ITEM_POU
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   325
            tagname = self.Controller.ComputePouName(infos["type"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   326
        self.ParentWindow.EditProjectElement(var_class, tagname)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   327
    
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   328
    def DebugButtonCallback(self, infos):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   329
        if self.InstanceChoice.GetSelection() != -1:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
            var_class = infos["class"]
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   331
            var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   332
                                  infos["name"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   333
            if var_class in ITEMS_VARIABLE:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   334
                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
   335
            elif var_class == ITEM_TRANSITION:
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   336
                self.ParentWindow.OpenDebugViewer(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   337
                    var_class,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   338
                    var_path,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   339
                    self.Controller.ComputePouTransitionName(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   340
                        self.PouTagName.split("::")[1],
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   341
                        infos["name"]))
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 821
diff changeset
   342
            elif var_class == ITEM_ACTION:
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   343
                self.ParentWindow.OpenDebugViewer(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   344
                    var_class,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   345
                    var_path,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   346
                    self.Controller.ComputePouActionName(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   347
                        self.PouTagName.split("::")[1],
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   348
                        infos["name"]))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
            else:
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   350
                self.ParentWindow.OpenDebugViewer(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   351
                    var_class,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   352
                    var_path,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   353
                    self.Controller.ComputePouName(infos["type"]))
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   354
    
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   355
    def DebugButtonDClickCallback(self, infos):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   356
        if self.InstanceChoice.GetSelection() != -1:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   357
            if infos["class"] in ITEMS_VARIABLE:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   358
                self.ParentWindow.AddDebugVariable(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   359
                    "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   360
                               infos["name"]), 
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   361
                    force=True,
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   362
                    graph=True)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   363
    
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   364
    def GraphButtonCallback(self, infos):
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   365
        if self.InstanceChoice.GetSelection() != -1:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   366
            if infos["class"] in ITEMS_VARIABLE:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
                var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
                                      infos["name"])
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   369
                self.ParentWindow.OpenDebugViewer(infos["class"], var_path, infos["type"])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
    def ShowInstanceChoicePopup(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
        self.InstanceChoice.SetFocusFromKbd()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
        size = self.InstanceChoice.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
        event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
        event.m_x = size.width / 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
        event.m_y = size.height / 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
        event.SetEventObject(self.InstanceChoice)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
        #event = wx.KeyEvent(wx.EVT_KEY_DOWN._getEvtType())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
        #event.m_keyCode = wx.WXK_SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
        self.InstanceChoice.GetEventHandler().ProcessEvent(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
    def OnParentButtonClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
        if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
            parent_path = self.InstanceChoice.GetStringSelection().rsplit(".", 1)[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
            tagname = self.Controller.GetPouInstanceTagName(parent_path, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
            if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
                wx.CallAfter(self.SetPouType, tagname, parent_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
                wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
    def OnInstanceChoiceChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
        self.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
    def OnDebugButtonClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
        if self.InstanceChoice.GetSelection() != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
            self.ParentWindow.OpenDebugViewer(
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
                self.PouInfos["class"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
                self.InstanceChoice.GetStringSelection(),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
                self.PouTagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
        event.Skip()
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   402
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
    def OnVariablesListItemActivated(self, event):
1189
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   404
        selected_item = event.GetItem()
93a4431a0cd8 Fixed bug in PouInstanceVariablesPanel, exploring child FunctionBlock variables if no instance selected
Laurent Bessard
parents: 1107
diff changeset
   405
        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
   406
            item_infos = self.VariablesList.GetPyData(selected_item)
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   407
            if item_infos is not None:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   408
                
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   409
                item_button = self.VariablesList.IsOverItemRightImage(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   410
                    selected_item, event.GetPoint())
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   411
                if item_button is not None:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   412
                    callback = self.ButtonCallBacks[item_button].dclick
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   413
                    if callback is not None:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   414
                        callback(item_infos)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   415
                
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   416
                elif item_infos["class"] not in ITEMS_VARIABLE:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   417
                    instance_path = self.InstanceChoice.GetStringSelection()
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   418
                    if item_infos["class"] == ITEM_RESOURCE:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   419
                        if instance_path != "":
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   420
                            tagname = self.Controller.ComputeConfigurationResourceName(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   421
                                           instance_path, 
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   422
                                           item_infos["name"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   423
                        else:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   424
                            tagname = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
                    else:
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   426
                        tagname = self.Controller.ComputePouName(item_infos["type"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   427
                    if tagname is not None:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   428
                        if instance_path != "":
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   429
                            item_path = "%s.%s" % (instance_path, item_infos["name"])
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   430
                        else:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   431
                            item_path = None
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   432
                        self.SetPouType(tagname, item_path)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   433
                        self.ParentWindow.SelectProjectTreeItem(tagname)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   434
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
    def OnVariablesListLeftDown(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
        if self.InstanceChoice.GetSelection() == -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
            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
   439
        else:
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   440
            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
   441
            item, flags = self.VariablesList.HitTest(event.GetPosition())
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   442
            if item is not None:
898
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   443
                item_infos = self.VariablesList.GetPyData(item)
1343
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   444
                if item_infos is not None:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   445
                    
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   446
                    item_button = self.VariablesList.IsOverItemRightImage(
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   447
                        item, event.GetPosition())
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   448
                    if item_button is not None:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   449
                        callback = self.ButtonCallBacks[item_button].leftdown
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   450
                        if callback is not None:
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   451
                            callback(item_infos)
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   452
                
a76a020b8822 Fixed PouInstanceVariablesPanel, replacing wx controls, too long to create and destroy, by bitmaps directly drawn in panel
Laurent Bessard
parents: 1281
diff changeset
   453
                elif flags & CT.TREE_HITTEST_ONITEMLABEL 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
   454
                    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
   455
                        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
   456
                    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
   457
                    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
   458
                    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
   459
                    dragSource.SetData(data)
6b2958f04f30 Adding drag'n drop of debug variable from DebugVariable grid and PouInstance variable list
Laurent Bessard
parents: 885
diff changeset
   460
                    dragSource.DoDragDrop()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
        event.Skip()
1031
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   462
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   463
    def OnVariablesListKeyDown(self, event):
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   464
        keycode = event.GetKeyCode()
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   465
        if keycode != wx.WXK_LEFT:
5743398071eb Fix bug when pressing left arrow key in PouInstanceVariablesPanel
Laurent Bessard
parents: 930
diff changeset
   466
            event.Skip()
1277
358db9d64aa1 Fixed refresh bug when activating element in instance variables list
Laurent Bessard
parents: 1238
diff changeset
   467