controls/VariablePanel.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com
Mon, 18 Apr 2016 18:48:15 +0300
changeset 1476 49f1763a5613
parent 1422 458d93275f71
child 1510 7272baadd7f6
permissions -rw-r--r--
fixes sometimes happened error during project compilation

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