controls/VariablePanel.py
author Laurent Bessard
Sun, 12 May 2013 23:30:00 +0200
changeset 1122 84de51ab40d2
parent 1083 40af794ecd4b
child 1128 86527a6f06fb
permissions -rw-r--r--
Adding support for using current selected variable for generate newly added variable informations in VariablePanel
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) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import os
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import re
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
from types import TupleType, StringType, UnicodeType
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
import wx.grid
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
import wx.lib.buttons
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
from dialogs.ArrayTypeDialog import ArrayTypeDialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
from CustomGrid import CustomGrid
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
from CustomTable import CustomTable
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
from LocationCellEditor import LocationCellEditor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
#                                 Helpers
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
def AppendMenu(parent, help, id, kind, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
    if wx.VERSION >= (2, 6, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
        parent.Append(help=help, id=id, kind=kind, text=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        parent.Append(helpString=help, id=id, kind=kind, item=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
[TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
 POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
] = range(10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
def GetVariableTableColnames(location):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
    _ = lambda x : x
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
    if location:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
def GetOptions(constant=True, retain=True, non_retain=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
    _ = lambda x : x
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
    options = [""]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
    if constant:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
        options.append(_("Constant"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
    if retain:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        options.append(_("Retain"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
    if non_retain:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        options.append(_("Non-Retain"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
    return options
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
def GetFilterChoiceTransfer():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
    _ = lambda x : x
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
    return {_("All"): _("All"), _("Interface"): _("Interface"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
            _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
            _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
            _("   Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
CheckOptionForClass = {"Local": lambda x: x,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
                       "Temp": lambda x: "",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
                       "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
                       "InOut": lambda x: "",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
                       "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
                       "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
                       "External": lambda x: {"Constant": "Constant"}.get(x, "")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
                      }
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$")
1122
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
    92
VARIABLE_NAME_SUFFIX_MODEL = re.compile("([0-9]*)$")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
#                            Variables Panel Table
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
class VariableTable(CustomTable):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
    """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
    A custom wx.grid.Grid Table using user supplied data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
    """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
    def __init__(self, parent, data, colnames):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        # The base class must be initialized *first*
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        CustomTable.__init__(self, parent, data, colnames)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        self.old_value = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
    def GetValue(self, row, col):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
            if col == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
                return self.data[row]["Number"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
            colname = self.GetColLabelValue(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
            value = self.data[row].get(colname, "")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
            if colname == "Type" and isinstance(value, TupleType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
                if value[0] == "array":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
                    return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
            if not isinstance(value, (StringType, UnicodeType)):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
                value = str(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
            if colname in ["Class", "Option"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
                return _(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
            return value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
    def SetValue(self, row, col, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
        if col < len(self.colnames):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
            colname = self.GetColLabelValue(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
            if colname == "Name":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
                self.old_value = self.data[row][colname]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
            elif colname == "Class":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
                value = VARIABLE_CLASSES_DICT[value]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
                self.SetValueByName(row, "Option", CheckOptionForClass[value](self.GetValueByName(row, "Option")))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
                if value == "External":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
                    self.SetValueByName(row, "Initial Value", "")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
            elif colname == "Option":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
                value = OPTIONS_DICT[value]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
            self.data[row][colname] = value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
    def GetOldValue(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        return self.old_value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
    def _updateColAttrs(self, grid):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        wx.grid.Grid -> update the column attributes to add the
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
        appropriate renderer given the column name.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
        Otherwise default to the default renderer.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
        for row in range(self.GetNumberRows()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
            var_class = self.GetValueByName(row, "Class")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
            var_type = self.GetValueByName(row, "Type")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
            row_highlights = self.Highlights.get(row, {})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
            for col in range(self.GetNumberCols()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
                editor = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
                renderer = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
                colname = self.GetColLabelValue(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
                if self.Parent.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
                    grid.SetReadOnly(row, col, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
                    if colname == "Option":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
                        options = GetOptions(constant = var_class in ["Local", "External", "Global"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
                                             retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
                                             non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
                        if len(options) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
                            editor = wx.grid.GridCellChoiceEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
                            editor.SetParameters(",".join(map(_, options)))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
                            grid.SetReadOnly(row, col, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
                    elif col != 0 and self.GetValueByName(row, "Edit"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
                        grid.SetReadOnly(row, col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
                        if colname == "Name":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
                            if self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
                                grid.SetReadOnly(row, col, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
                                editor = wx.grid.GridCellTextEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
                                renderer = wx.grid.GridCellStringRenderer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
                        elif colname == "Initial Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
                            if var_class not in ["External", "InOut"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
                                if self.Parent.Controler.IsEnumeratedType(var_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
                                    editor = wx.grid.GridCellChoiceEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
                                    editor.SetParameters(",".join(self.Parent.Controler.GetEnumeratedDataValues(var_type)))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
                                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
                                    editor = wx.grid.GridCellTextEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
                                renderer = wx.grid.GridCellStringRenderer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
                                grid.SetReadOnly(row, col, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
                        elif colname == "Location":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
                            if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
                                editor = LocationCellEditor(self, self.Parent.Controler)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
                                renderer = wx.grid.GridCellStringRenderer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
                                grid.SetReadOnly(row, col, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
                        elif colname == "Class":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
                            if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
                                grid.SetReadOnly(row, col, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
                                editor = wx.grid.GridCellChoiceEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
                                excluded = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
                                if self.Parent.PouIsUsed:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
                                    excluded.extend(["Input","Output","InOut"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
                                if self.Parent.IsFunctionBlockType(var_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
                                    excluded.extend(["Local","Temp"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
                                editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
                    elif colname != "Documentation":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
                        grid.SetReadOnly(row, col, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
                grid.SetCellEditor(row, col, editor)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
                grid.SetCellRenderer(row, col, renderer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
                
831
dec885ba1f2b Adding support for signaling that a task interval isn't well formatted
laurent
parents: 830
diff changeset
   208
                if colname == "Location" and LOCATION_MODEL.match(self.GetValueByName(row, colname)) is None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
                    highlight_colours = ERROR_HIGHLIGHT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
                    highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
                grid.SetCellTextColour(row, col, highlight_colours[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
            self.ResizeRow(grid, row)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
#                         Variable Panel Drop Target
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
#-------------------------------------------------------------------------------   
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
class VariableDropTarget(wx.TextDropTarget):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
    '''
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
    This allows dragging a variable location from somewhere to the Location
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
    column of a variable row.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
    The drag source should be a TextDataObject containing a Python tuple like:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
        ('%ID0.0.0', 'location', 'REAL')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
    c_ext/CFileEditor.py has an example of this (you can drag a C extension
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
    variable to the Location column of the variable panel).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
    '''
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
    def __init__(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
        wx.TextDropTarget.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
        self.ParentWindow = parent
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
    def OnDropText(self, x, y, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
        self.ParentWindow.ParentWindow.Select()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
        x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
        col = self.ParentWindow.VariablesGrid.XToCol(x)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
        row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
        element_type = self.ParentWindow.ElementType
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
            values = eval(data)    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
        except:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
            message = _("Invalid value \"%s\" for variable grid element")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
            values = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
        if not isinstance(values, TupleType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
            message = _("Invalid value \"%s\" for variable grid element")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
            values = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
        if values is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
            if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
                colname = self.ParentWindow.Table.GetColLabelValue(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
                if colname == "Location" and values[1] == "location":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
                    if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
                        message = _("Can't give a location to a function block instance")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                    elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                        message = _("Can only give a location to local or global variables")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
                        location = values[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
                        variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
                        base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
830
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   262
                        
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   263
                        if values[2] is not None:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   264
                            base_location_type = self.ParentWindow.Controler.GetBaseType(values[2])
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   265
                            if values[2] != variable_type and base_type != base_location_type:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
                                message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type)
830
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   267
                        
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   268
                        if message is None:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   269
                            if not location.startswith("%"):
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   270
                                if location[0].isdigit() and base_type != "BOOL":
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   271
                                    message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   272
                                elif location[0] not in LOCATIONDATATYPES:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   273
                                    message = _("Unrecognized data size \"%s\"")%location[0]
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   274
                                elif base_type not in LOCATIONDATATYPES[location[0]]:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   275
                                    message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
                                else:
830
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   277
                                    dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, 
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   278
                                          _("Select a variable class:"), _("Variable class"), 
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   279
                                          ["Input", "Output", "Memory"], 
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   280
                                          wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   281
                                    if dialog.ShowModal() == wx.ID_OK:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   282
                                        selected = dialog.GetSelection()
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   283
                                    else:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   284
                                        selected = None
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   285
                                    dialog.Destroy()
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   286
                                    if selected is None:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   287
                                        return
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   288
                                    if selected == 0:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   289
                                        location = "%I" + location
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   290
                                    elif selected == 1:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   291
                                        location = "%Q" + location
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   292
                                    else:
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   293
                                        location = "%M" + location
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   294
                                        
4b9df5bea400 Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents: 814
diff changeset
   295
                            if message is None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
                                self.ParentWindow.Table.SetValue(row, col, location)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
                                self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
                                self.ParentWindow.SaveValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
                elif colname == "Initial Value" and values[1] == "Constant":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
                    if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
                        message = _("Can't set an initial value to a function block instance")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
                        self.ParentWindow.Table.SetValue(row, col, values[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
                        self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
                        self.ParentWindow.SaveValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
            elif (element_type not in ["config", "resource"] and values[1] == "Global" and self.ParentWindow.Filter in ["All", "Interface", "External"] or
1083
40af794ecd4b Added support for adding a variable in program VariablePanel by drap'n dropping located variable like in global VariablePanel
Laurent Bessard
parents: 1016
diff changeset
   307
                  element_type in ["config", "resource", "program"] and values[1] == "location"):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
                if values[1] == "location":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
                    var_name = values[3]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
                    var_name = values[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
                tagname = self.ParentWindow.GetTagName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
                if var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
                    message = _("\"%s\" pou already exists!")%var_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
                elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
                    var_infos = self.ParentWindow.DefaultValue.copy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
                    var_infos["Name"] = var_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
                    var_infos["Type"] = values[2]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
                    if values[1] == "location":
1083
40af794ecd4b Added support for adding a variable in program VariablePanel by drap'n dropping located variable like in global VariablePanel
Laurent Bessard
parents: 1016
diff changeset
   320
                        if element_type == "program":
40af794ecd4b Added support for adding a variable in program VariablePanel by drap'n dropping located variable like in global VariablePanel
Laurent Bessard
parents: 1016
diff changeset
   321
                            var_infos["Class"] = "Local"
40af794ecd4b Added support for adding a variable in program VariablePanel by drap'n dropping located variable like in global VariablePanel
Laurent Bessard
parents: 1016
diff changeset
   322
                        else:
40af794ecd4b Added support for adding a variable in program VariablePanel by drap'n dropping located variable like in global VariablePanel
Laurent Bessard
parents: 1016
diff changeset
   323
                            var_infos["Class"] = "Global"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
                        var_infos["Location"] = values[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
                        var_infos["Class"] = "External"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
                    var_infos["Number"] = len(self.ParentWindow.Values)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
                    self.ParentWindow.Values.append(var_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
                    self.ParentWindow.SaveValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
                    self.ParentWindow.RefreshValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
            wx.CallAfter(self.ShowMessage, message)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
    def ShowMessage(self, message):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
        message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
        message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
#                               Variable Panel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
#-------------------------------------------------------------------------------   
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
class VariablePanel(wx.Panel):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
    def __init__(self, parent, window, controler, element_type, debug=False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
        self.MainSizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
        self.MainSizer.AddGrowableRow(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
        controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
        controls_sizer.AddGrowableCol(5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
        controls_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
        self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW|wx.ALL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
        self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
        controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   360
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
        self.ReturnType = wx.ComboBox(self,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
              size=wx.Size(145, -1), style=wx.CB_READONLY)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
        self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
        controls_sizer.AddWindow(self.ReturnType)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   366
        self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
        controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
        self.Description = wx.TextCtrl(self,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
              size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
        self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
        self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
        controls_sizer.AddWindow(self.Description) 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
        class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
        controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
        self.ClassFilter = wx.ComboBox(self, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
              size=wx.Size(145, -1), style=wx.CB_READONLY)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
        self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
        controls_sizer.AddWindow(self.ClassFilter)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
        for name, bitmap, help in [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
                ("AddButton", "add_element", _("Add variable")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
                ("DeleteButton", "remove_element", _("Remove variable")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
                ("UpButton", "up", _("Move variable up")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
                ("DownButton", "down", _("Move variable down"))]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
            button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
            button.SetToolTipString(help)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
            setattr(self, name, button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
            controls_sizer.AddWindow(button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
              self.OnVariablesGridCellChange)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
              self.OnVariablesGridCellLeftClick)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
              self.OnVariablesGridEditorShown)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
        self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
        self.SetSizer(self.MainSizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
        self.ParentWindow = window
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
        self.Controler = controler
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
        self.ElementType = element_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
        self.Debug = debug
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   412
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
              self.RefreshHighlightsTimer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   414
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
        self.Filter = "All"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   416
        self.FilterChoices = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
        self.FilterChoiceTransfer = GetFilterChoiceTransfer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
        self.DefaultValue = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
             "Name" : "", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
             "Class" : "", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
             "Type" : "INT", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   423
             "Location" : "",
863
b1ead41fbd3b Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents: 853
diff changeset
   424
             "Initial Value" : "", 
b1ead41fbd3b Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents: 853
diff changeset
   425
             "Option" : "",
b1ead41fbd3b Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents: 853
diff changeset
   426
             "Documentation" : "", 
b1ead41fbd3b Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents: 853
diff changeset
   427
             "Edit" : True
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   428
        }
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   429
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
        if element_type in ["config", "resource"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   431
            self.DefaultTypes = {"All" : "Global"}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
            self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   434
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
        if element_type in ["config", "resource"] \
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
        or element_type in ["program", "transition", "action"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
            # this is an element that can have located variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
            self.Table = VariableTable(self, [], GetVariableTableColnames(True))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   439
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   440
            if element_type in ["config", "resource"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   441
                self.FilterChoices = ["All", "Global"]#,"Access"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
                self.FilterChoices = ["All",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   444
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
                                        "Variables", "   Local", "   Temp"]#,"Access"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   447
            # these condense the ColAlignements list
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   448
            l = wx.ALIGN_LEFT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   449
            c = wx.ALIGN_CENTER 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   450
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
            #                      Num  Name    Class   Type    Loc     Init    Option   Doc
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
            self.ColSizes       = [40,  80,     70,     80,     80,     80,     100,     80]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
            self.ColAlignements = [c,   l,      l,      l,      l,      l,      l,       l]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   455
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
            # this is an element that cannot have located variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
            self.Table = VariableTable(self, [], GetVariableTableColnames(False))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   458
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
            if element_type == "function":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
                self.FilterChoices = ["All",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
                                        "Interface", "   Input", "   Output", "   InOut",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
                                        "Variables", "   Local"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   463
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
                self.FilterChoices = ["All",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   465
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
                                        "Variables", "   Local", "   Temp"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   467
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   468
            # these condense the ColAlignements list
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   469
            l = wx.ALIGN_LEFT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
            c = wx.ALIGN_CENTER 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   472
            #                      Num  Name    Class   Type    Init    Option   Doc
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   473
            self.ColSizes       = [40,  80,     70,     80,     80,     100,     160]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
            self.ColAlignements = [c,   l,      l,      l,      l,      l,       l]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   475
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   476
        for choice in self.FilterChoices:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   477
            self.ClassFilter.Append(_(choice))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   478
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   479
        reverse_transfer = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   480
        for filter, choice in self.FilterChoiceTransfer.items():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
            reverse_transfer[choice] = filter
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   482
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
        self.RefreshTypeList()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   485
        self.VariablesGrid.SetTable(self.Table)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
        self.VariablesGrid.SetButtons({"Add": self.AddButton,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
                                       "Delete": self.DeleteButton,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   488
                                       "Up": self.UpButton,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
                                       "Down": self.DownButton})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
        self.VariablesGrid.SetEditable(not self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   491
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   492
        def _AddVariable(new_row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   493
            if not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]:
1122
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   494
                if new_row > 0:
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   495
                    row_content = self.Values[new_row - 1].copy()
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   496
                    result = VARIABLE_NAME_SUFFIX_MODEL.search(row_content["Name"])
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   497
                    if result is not None:
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   498
                        name = row_content["Name"][:result.start(1)]
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   499
                        suffix = result.group(1)
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   500
                        if suffix != "":
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   501
                            start_idx = int(suffix)
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   502
                        else:
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   503
                            start_idx = 0
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   504
                    else:
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   505
                        name = row_content["Name"]
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   506
                        start_idx = 0
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   507
                    row_content["Name"] = self.Controler.GenerateNewName(
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   508
                        self.TagName, None, name + "%d", start_idx)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   509
                else:
1122
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   510
                    row_content = self.DefaultValue.copy()
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   511
                    if self.Filter in self.DefaultTypes:
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   512
                        row_content["Class"] = self.DefaultTypes[self.Filter]
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   513
                    else:
84de51ab40d2 Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents: 1083
diff changeset
   514
                        row_content["Class"] = self.Filter
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   515
                if self.Filter == "All" and len(self.Values) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
                    self.Values.insert(new_row, row_content)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
                    self.Values.append(row_content)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
                    new_row = self.Table.GetNumberRows()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
                self.SaveValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
                self.RefreshValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
                return new_row
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
            return self.VariablesGrid.GetGridCursorRow()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   525
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
        def _DeleteVariable(row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   527
            if (self.Table.GetValueByName(row, "Edit") and 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
                (not self.PouIsUsed or self.Table.GetValueByName(row, "Class") not in ["Input", "Output", "InOut"])):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   529
                self.Values.remove(self.Table.GetRow(row))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   530
                self.SaveValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
                self.RefreshValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   533
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
        def _MoveVariable(row, move):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
            if (self.Filter == "All" and 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   536
                (not self.PouIsUsed or self.Table.GetValueByName(row, "Class") not in ["Input", "Output", "InOut"])):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
                new_row = max(0, min(row + move, len(self.Values) - 1))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
                if new_row != row:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
                    self.Values.insert(new_row, self.Values.pop(row))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   540
                    self.SaveValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   541
                    self.RefreshValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   542
                return new_row
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   543
            return row
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   544
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   545
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   546
        def _RefreshButtons():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
            if self:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   548
                table_length = len(self.Table.data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   549
                row_class = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   550
                row_edit = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   551
                row = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   552
                if table_length > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
                    row = self.VariablesGrid.GetGridCursorRow()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   554
                    row_edit = self.Table.GetValueByName(row, "Edit")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   555
                    if self.PouIsUsed:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   556
                        row_class = self.Table.GetValueByName(row, "Class")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   557
                self.AddButton.Enable(not self.Debug and (not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   558
                self.DeleteButton.Enable(not self.Debug and (table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
                self.UpButton.Enable(not self.Debug and (table_length > 0 and row > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
                self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
        setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   562
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   563
        self.VariablesGrid.SetRowLabelSize(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   564
        for col in range(self.Table.GetNumberCols()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
            attr = wx.grid.GridCellAttr()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   566
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   567
            self.VariablesGrid.SetColAttr(col, attr)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   568
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   569
            self.VariablesGrid.AutoSizeColumn(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   571
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   572
        self.RefreshHighlightsTimer.Stop()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   573
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   574
    def SetTagName(self, tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
        self.TagName = tagname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   577
    def GetTagName(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
        return self.TagName
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   579
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
    def IsFunctionBlockType(self, name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   581
        bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
        pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   583
        if poutype != "function" and bodytype in ["ST", "IL"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
            return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   585
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   586
            return name in self.Controler.GetFunctionBlockTypes(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   587
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   588
    def RefreshView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   589
        self.PouNames = self.Controler.GetProjectPouNames(self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   590
        returnType = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   591
        description = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
        words = self.TagName.split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
        if self.ElementType == "config":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   595
            self.PouIsUsed = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
            self.Values = self.Controler.GetConfigurationGlobalVars(words[1], self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   597
        elif self.ElementType == "resource":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
            self.PouIsUsed = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   599
            self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2], self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   600
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   601
            if self.ElementType == "function":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   602
                self.ReturnType.Clear()
853
0f97bddb5a30 Adding datatypes defined in ConfNode as possible function return type
Laurent Bessard
parents: 831
diff changeset
   603
                for data_type in self.Controler.GetDataTypes(self.TagName, debug=self.Debug):
0f97bddb5a30 Adding datatypes defined in ConfNode as possible function return type
Laurent Bessard
parents: 831
diff changeset
   604
                    self.ReturnType.Append(data_type)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   605
                returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   606
            description = self.Controler.GetPouDescription(words[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
            self.PouIsUsed = self.Controler.PouIsUsed(words[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
            self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   609
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
        if returnType is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   611
            self.ReturnType.SetStringSelection(returnType)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   612
            self.ReturnType.Enable(not self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
            self.ReturnTypeLabel.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   614
            self.ReturnType.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   615
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   616
            self.ReturnType.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   617
            self.ReturnTypeLabel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   618
            self.ReturnType.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   619
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   620
        if description is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   621
            self.Description.SetValue(description)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   622
            self.Description.Enable(not self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
            self.DescriptionLabel.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
            self.Description.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   625
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   626
            self.Description.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   627
            self.DescriptionLabel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   628
            self.Description.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   629
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   630
        self.RefreshValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   631
        self.VariablesGrid.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
        self.MainSizer.Layout()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   633
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   634
    def OnReturnTypeChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   635
        words = self.TagName.split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   636
        self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
        self.Controler.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   638
        self.ParentWindow.RefreshView(variablepanel = False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   639
        self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   641
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
    def OnDescriptionChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   643
        words = self.TagName.split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   644
        old_description = self.Controler.GetPouDescription(words[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   645
        new_description = self.Description.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   646
        if new_description != old_description:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
            self.Controler.SetPouDescription(words[1], new_description)
1009
741fbce41ec2 Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents: 894
diff changeset
   648
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   650
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
    def OnClassFilter(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   652
        self.Filter = self.FilterChoiceTransfer[VARIABLE_CHOICES_DICT[self.ClassFilter.GetStringSelection()]]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
        self.RefreshTypeList()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
        self.RefreshValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
        self.VariablesGrid.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   656
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
    def RefreshTypeList(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   659
        if self.Filter == "All":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
            self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   661
        elif self.Filter == "Interface":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
            self.ClassList = ["Input","Output","InOut","External"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   663
        elif self.Filter == "Variables":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
            self.ClassList = ["Local","Temp"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   666
            self.ClassList = [self.Filter]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   667
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   668
    def OnVariablesGridCellChange(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   669
        row, col = event.GetRow(), event.GetCol()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   670
        colname = self.Table.GetColLabelValue(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   671
        value = self.Table.GetValue(row, col)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   672
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   673
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   674
        if colname == "Name" and value != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   675
            if not TestIdentifier(value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   676
                message = _("\"%s\" is not a valid identifier!") % value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   677
            elif value.upper() in IEC_KEYWORDS:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   678
                message = _("\"%s\" is a keyword. It can't be used!") % value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   679
            elif value.upper() in self.PouNames:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   680
                message = _("A POU named \"%s\" already exists!") % value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   681
            elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   682
                message = _("A variable with \"%s\" as name already exists in this pou!") % value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   683
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
                self.SaveValues(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
                old_value = self.Table.GetOldValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
                if old_value != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
                    self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
                self.Controler.BufferProject()
1009
741fbce41ec2 Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents: 894
diff changeset
   689
                wx.CallAfter(self.ParentWindow.RefreshView, False)
1016
3d79c31e4697 Fixed bug with variable panel in project configuration editor
Laurent Bessard
parents: 1009
diff changeset
   690
                self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
            self.SaveValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
            if colname == "Class":
1009
741fbce41ec2 Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents: 894
diff changeset
   694
                wx.CallAfter(self.ParentWindow.RefreshView, False)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
            elif colname == "Location":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   696
                wx.CallAfter(self.ParentWindow.RefreshView)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
            dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
            event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   704
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   705
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
    def OnVariablesGridEditorShown(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   707
        row, col = event.GetRow(), event.GetCol() 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   708
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   709
        label_value = self.Table.GetColLabelValue(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   710
        if label_value == "Type":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   711
            type_menu = wx.Menu(title='')   # the root menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   712
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
            # build a submenu containing standard IEC types
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   714
            base_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   715
            for base_type in self.Controler.GetBaseTypes():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   716
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
                AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   719
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   720
            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   721
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   722
            # build a submenu containing user-defined types
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   723
            datatype_menu = wx.Menu(title='')
863
b1ead41fbd3b Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents: 853
diff changeset
   724
            datatypes = self.Controler.GetDataTypes(basetypes = False, confnodetypes = False)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   725
            for datatype in datatypes:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   726
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
                AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   729
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   730
            type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   731
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   732
            for category in self.Controler.GetConfNodeDataTypes():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   733
               
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   734
               if len(category["list"]) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
                   # build a submenu containing confnode types
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   736
                   confnode_datatype_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
                   for datatype in category["list"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   738
                       new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
                       AppendMenu(confnode_datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   740
                       self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   741
                   
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   742
                   type_menu.AppendMenu(wx.NewId(), category["name"], confnode_datatype_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   743
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   744
            # build a submenu containing function block types
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   745
            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   746
            pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   747
            classtype = self.Table.GetValueByName(row, "Class")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   748
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   749
            new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   750
            AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   751
            self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   752
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   753
            if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   754
            poutype != "function" and bodytype in ["ST", "IL"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   755
                functionblock_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   756
                fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   757
                for functionblock_type in fbtypes:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   758
                    new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   759
                    AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   760
                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   761
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   762
                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   763
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   764
            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   765
            corner_x = rect.x + rect.width
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   766
            corner_y = rect.y + self.VariablesGrid.GetColLabelSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   767
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   768
            # pop up this new menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
            self.VariablesGrid.PopupMenuXY(type_menu, corner_x, corner_y)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   770
            type_menu.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   771
            event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   774
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   775
    def GetVariableTypeFunction(self, base_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   776
        def VariableTypeFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   777
            row = self.VariablesGrid.GetGridCursorRow()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   778
            self.Table.SetValueByName(row, "Type", base_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   779
            self.Table.ResetView(self.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   780
            self.SaveValues(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   781
            self.ParentWindow.RefreshView(variablepanel = False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   782
            self.Controler.BufferProject()
1009
741fbce41ec2 Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents: 894
diff changeset
   783
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   784
        return VariableTypeFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   785
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   786
    def VariableArrayTypeFunction(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   787
        row = self.VariablesGrid.GetGridCursorRow()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   788
        dialog = ArrayTypeDialog(self, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   789
                                 self.Controler.GetDataTypes(self.TagName), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   790
                                 self.Table.GetValueByName(row, "Type"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   791
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   792
            self.Table.SetValueByName(row, "Type", dialog.GetValue())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
            self.Table.ResetView(self.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   794
            self.SaveValues(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   795
            self.ParentWindow.RefreshView(variablepanel = False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   796
            self.Controler.BufferProject()
1009
741fbce41ec2 Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents: 894
diff changeset
   797
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   798
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   799
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   800
    def OnVariablesGridCellLeftClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   801
        row = event.GetRow()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   802
        if not self.Debug and (event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit")):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   803
            var_name = self.Table.GetValueByName(row, "Name")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   804
            var_class = self.Table.GetValueByName(row, "Class")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   805
            var_type = self.Table.GetValueByName(row, "Type")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   806
            data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName)))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   807
            dragSource = wx.DropSource(self.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   808
            dragSource.SetData(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   809
            dragSource.DoDragDrop()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   810
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   811
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   812
    def RefreshValues(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   813
        data = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
        for num, variable in enumerate(self.Values):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   815
            if variable["Class"] in self.ClassList:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   816
                variable["Number"] = num + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   817
                data.append(variable)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   818
        self.Table.SetData(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   819
        self.Table.ResetView(self.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   820
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   821
    def SaveValues(self, buffer = True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   822
        words = self.TagName.split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   823
        if self.ElementType == "config":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   824
            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   825
        elif self.ElementType == "resource":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
            self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   827
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   828
            if self.ReturnType.IsEnabled():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   829
                self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   830
            self.Controler.SetPouInterfaceVars(words[1], self.Values)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   831
        if buffer:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   832
            self.Controler.BufferProject()
1009
741fbce41ec2 Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents: 894
diff changeset
   833
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)            
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   834
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   835
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   836
#                        Highlights showing functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   837
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   838
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   839
    def OnRefreshHighlightsTimer(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   840
        self.Table.ResetView(self.VariablesGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   841
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   842
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   843
    def AddVariableHighlight(self, infos, highlight_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   844
        if isinstance(infos[0], TupleType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   845
            for i in xrange(*infos[0]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   846
                self.Table.AddHighlight((i,) + infos[1:], highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   847
            cell_visible = infos[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   848
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   849
            self.Table.AddHighlight(infos, highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   850
            cell_visible = infos[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   851
        colnames = [colname.lower() for colname in self.Table.colnames]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   852
        self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   853
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   854
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   855
    def RemoveVariableHighlight(self, infos, highlight_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   856
        if isinstance(infos[0], TupleType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   857
            for i in xrange(*infos[0]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   858
                self.Table.RemoveHighlight((i,) + infos[1:], highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   859
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   860
            self.Table.RemoveHighlight(infos, highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   861
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   862
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   863
    def ClearHighlights(self, highlight_type=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   864
        self.Table.ClearHighlights(highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   865
        self.Table.ResetView(self.VariablesGrid)