VariablePanel.py
author laurent
Fri, 14 Oct 2011 19:26:29 +0200
changeset 577 9dbb79722fbc
parent 566 6014ef82a98a
child 580 ad996deb920e
permissions -rw-r--r--
Adding support for giving keyboard focus to the first control of every dialogs
Adding support for using keyboard to edit informations displayed in Grid and in EditableListBox
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
     1
#!/usr/bin/env python
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     3
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     5
#based on the plcopen standard. 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     6
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     8
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     9
#See COPYING file for copyrights details.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    10
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    15
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    19
#General Public License for more details.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    20
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    24
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
    25
import os
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    26
import wx, wx.grid
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    27
419
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
    28
from types import TupleType
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
    29
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    30
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
    31
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
    32
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
507
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
    33
from dialogs import ArrayTypeDialog
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
    34
from controls import CustomGrid
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
    35
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
    36
CWD = os.path.split(os.path.realpath(__file__))[0]
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    37
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    38
# Compatibility function for wx versions < 2.6
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    39
def AppendMenu(parent, help, id, kind, text):
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    40
    if wx.VERSION >= (2, 6, 0):
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    41
        parent.Append(help=help, id=id, kind=kind, text=text)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    42
    else:
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    43
        parent.Append(helpString=help, id=id, kind=kind, item=text)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    44
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    45
[TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, 
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    46
 INSTANCESTREE, LIBRARYTREE, SCALING
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    47
] = range(9)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    48
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    49
#-------------------------------------------------------------------------------
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    50
#                            Variables Editor Panel
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    51
#-------------------------------------------------------------------------------
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    52
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    53
def GetVariableTableColnames(location):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    54
    _ = lambda x : x
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    55
    if location:
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
    56
    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")]
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
    57
    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")]
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
    58
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    59
def GetOptions(constant=True, retain=True, non_retain=True):
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    60
    _ = lambda x : x
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    61
    options = [""]
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    62
    if constant:
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    63
        options.append(_("Constant"))
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    64
    if retain:
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    65
        options.append(_("Retain"))
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    66
    if non_retain:
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    67
        options.append(_("Non-Retain"))
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    68
    return options
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
    69
OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()])
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    70
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    71
def GetFilterChoiceTransfer():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    72
    _ = lambda x : x
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    73
    return {_("All"): _("All"), _("Interface"): _("Interface"), 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    74
            _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"), 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    75
            _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    76
            _("   Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")}
509
6f72513bc074 Bug on variable panel row size in grid preventing readability of value inside cell editors fixed
laurent
parents: 507
diff changeset
    77
VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()])
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    78
VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    79
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    80
CheckOptionForClass = {"Local": lambda x: x,
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    81
                       "Temp": lambda x: "",
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    82
                       "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    83
                       "InOut": lambda x: "",
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    84
                       "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    85
                       "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""),
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    86
                       "External": lambda x: {"Constant": "Constant"}.get(x, "")
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    87
                      }
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
    88
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    89
class VariableTable(wx.grid.PyGridTableBase):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    90
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    91
    """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    92
    A custom wx.grid.Grid Table using user supplied data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    93
    """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    94
    def __init__(self, parent, data, colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    95
        # The base class must be initialized *first*
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    96
        wx.grid.PyGridTableBase.__init__(self)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    97
        self.data = data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    98
        self.old_value = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    99
        self.colnames = colnames
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   100
        self.Highlights = {}
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   101
        self.Parent = parent
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   102
        # XXX
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   103
        # we need to store the row length and collength to
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   104
        # see if the table has changed size
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   105
        self._rows = self.GetNumberRows()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   106
        self._cols = self.GetNumberCols()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   107
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   108
    def GetNumberCols(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   109
        return len(self.colnames)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   110
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   111
    def GetNumberRows(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   112
        return len(self.data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   113
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   114
    def GetColLabelValue(self, col, translate=True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   115
        if col < len(self.colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   116
            if translate:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   117
                return _(self.colnames[col])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   118
            return self.colnames[col]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   119
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   120
    def GetRowLabelValues(self, row, translate=True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   121
        return row
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   122
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   123
    def GetValue(self, row, col):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   124
        if row < self.GetNumberRows():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   125
            if col == 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   126
                return self.data[row]["Number"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   127
            colname = self.GetColLabelValue(col, False)
507
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   128
            value = self.data[row].get(colname, "")
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   129
            if colname == "Type" and isinstance(value, TupleType):
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   130
                if value[0] == "array":
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   131
                    return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1])
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   132
            value = str(value)
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   133
            if colname in ["Class", "Option"]:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   134
                return _(value)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   135
            return value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   136
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   137
    def SetValue(self, row, col, value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   138
        if col < len(self.colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   139
            colname = self.GetColLabelValue(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   140
            if colname == "Name":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   141
                self.old_value = self.data[row][colname]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   142
            elif colname == "Class":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   143
                value = VARIABLE_CLASSES_DICT[value]
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   144
                self.SetValueByName(row, "Option", CheckOptionForClass[value](self.GetValueByName(row, "Option")))
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   145
                if value == "External":
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   146
                    self.SetValueByName(row, "Initial Value", "")
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   147
            elif colname == "Option":
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   148
                value = OPTIONS_DICT[value]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   149
            self.data[row][colname] = value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   150
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   151
    def GetValueByName(self, row, colname):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   152
        if row < self.GetNumberRows():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   153
            return self.data[row].get(colname)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   154
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   155
    def SetValueByName(self, row, colname, value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   156
        if row < self.GetNumberRows():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   157
            self.data[row][colname] = value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   158
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   159
    def GetOldValue(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   160
        return self.old_value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   161
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   162
    def ResetView(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   163
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   164
        (wx.grid.Grid) -> Reset the grid view.   Call this to
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   165
        update the grid if rows and columns have been added or deleted
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   166
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   167
        grid.BeginBatch()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   168
        for current, new, delmsg, addmsg in [
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   169
            (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   170
            (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   171
        ]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   172
            if new < current:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   173
                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   174
                grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   175
            elif new > current:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   176
                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   177
                grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   178
                self.UpdateValues(grid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   179
        grid.EndBatch()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   180
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   181
        self._rows = self.GetNumberRows()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   182
        self._cols = self.GetNumberCols()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   183
        # update the column rendering scheme
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   184
        self._updateColAttrs(grid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   185
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   186
        # update the scrollbars and the displayed part of the grid
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   187
        grid.AdjustScrollbars()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   188
        grid.ForceRefresh()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   189
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   190
    def UpdateValues(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   191
        """Update all displayed values"""
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   192
        # This sends an event to the grid table to update all of the values
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   193
        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   194
        grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   195
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   196
    def _updateColAttrs(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   197
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   198
        wx.grid.Grid -> update the column attributes to add the
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   199
        appropriate renderer given the column name.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   200
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   201
        Otherwise default to the default renderer.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   202
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   203
        for row in range(self.GetNumberRows()):
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   204
            var_class = self.GetValueByName(row, "Class")
552
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 544
diff changeset
   205
            var_type = self.GetValueByName(row, "Type")
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   206
            row_highlights = self.Highlights.get(row, {})
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   207
            for col in range(self.GetNumberCols()):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   208
                editor = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   209
                renderer = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   210
                colname = self.GetColLabelValue(col, False)
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   211
                if colname == "Option":
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   212
                    options = GetOptions(constant = var_class in ["Local", "External", "Global"],
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   213
                                         retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   214
                                         non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   215
                    if len(options) > 1:
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   216
                        editor = wx.grid.GridCellChoiceEditor()
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   217
                        editor.SetParameters(",".join(map(_, options)))
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   218
                    else:
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   219
                        grid.SetReadOnly(row, col, True)
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   220
                elif col != 0 and self.GetValueByName(row, "Edit"):
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   221
                    grid.SetReadOnly(row, col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   222
                    if colname == "Name":
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   223
                        if self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   224
                            grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   225
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   226
                            editor = wx.grid.GridCellTextEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   227
                            renderer = wx.grid.GridCellStringRenderer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   228
                    elif colname == "Initial Value":
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   229
                        if var_class != "External":
552
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 544
diff changeset
   230
                            if self.Parent.Controler.IsEnumeratedType(var_type):
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 544
diff changeset
   231
                                editor = wx.grid.GridCellChoiceEditor()
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 544
diff changeset
   232
                                editor.SetParameters(",".join(self.Parent.Controler.GetEnumeratedDataValues(var_type)))
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 544
diff changeset
   233
                            else:
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 544
diff changeset
   234
                                editor = wx.grid.GridCellTextEditor()
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   235
                            renderer = wx.grid.GridCellStringRenderer()
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   236
                        else:
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   237
                            grid.SetReadOnly(row, col, True)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   238
                    elif colname == "Location":
552
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 544
diff changeset
   239
                        if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   240
                            editor = LocationCellEditor(self, self.Parent.Controler)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   241
                            renderer = wx.grid.GridCellStringRenderer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   242
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   243
                            grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   244
                    elif colname == "Class":
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   245
                        if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   246
                            grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   247
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   248
                            editor = wx.grid.GridCellChoiceEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   249
                            excluded = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   250
                            if self.Parent.PouIsUsed:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   251
                                excluded.extend(["Input","Output","InOut"])
552
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 544
diff changeset
   252
                            if self.Parent.IsFunctionBlockType(var_type):
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   253
                                excluded.extend(["Local","Temp"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   254
                            editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   255
                elif colname != "Documentation":
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   256
                    grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   257
                
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   258
                grid.SetCellEditor(row, col, editor)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   259
                grid.SetCellRenderer(row, col, renderer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   260
                
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   261
                highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   262
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   263
                grid.SetCellTextColour(row, col, highlight_colours[1])
509
6f72513bc074 Bug on variable panel row size in grid preventing readability of value inside cell editors fixed
laurent
parents: 507
diff changeset
   264
            if wx.Platform == '__WXMSW__':
6f72513bc074 Bug on variable panel row size in grid preventing readability of value inside cell editors fixed
laurent
parents: 507
diff changeset
   265
                grid.SetRowMinimalHeight(row, 20)
6f72513bc074 Bug on variable panel row size in grid preventing readability of value inside cell editors fixed
laurent
parents: 507
diff changeset
   266
            else:
6f72513bc074 Bug on variable panel row size in grid preventing readability of value inside cell editors fixed
laurent
parents: 507
diff changeset
   267
                grid.SetRowMinimalHeight(row, 28)
6f72513bc074 Bug on variable panel row size in grid preventing readability of value inside cell editors fixed
laurent
parents: 507
diff changeset
   268
            grid.AutoSizeRow(row, False)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   269
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   270
    def SetData(self, data):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   271
        self.data = data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   272
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   273
    def GetData(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   274
        return self.data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   275
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   276
    def GetCurrentIndex(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   277
        return self.CurrentIndex
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   278
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   279
    def SetCurrentIndex(self, index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   280
        self.CurrentIndex = index
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   281
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   282
    def AppendRow(self, row_content):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   283
        self.data.append(row_content)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   284
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   285
    def RemoveRow(self, row_index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   286
        self.data.pop(row_index)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   287
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   288
    def GetRow(self, row_index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   289
        return self.data[row_index]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   290
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   291
    def Empty(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   292
        self.data = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   293
        self.editors = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   294
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   295
    def AddHighlight(self, infos, highlight_type):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   296
        row_highlights = self.Highlights.setdefault(infos[0], {})
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   297
        col_highlights = row_highlights.setdefault(infos[1], [])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   298
        col_highlights.append(highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   299
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   300
    def ClearHighlights(self, highlight_type=None):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   301
        if highlight_type is None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   302
            self.Highlights = {}
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   303
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   304
            for row, row_highlights in self.Highlights.iteritems():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   305
                row_items = row_highlights.items()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   306
                for col, col_highlights in row_items:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   307
                    if highlight_type in col_highlights:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   308
                        col_highlights.remove(highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   309
                    if len(col_highlights) == 0:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   310
                        row_highlights.pop(col)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   311
                    
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   312
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   313
class VariableDropTarget(wx.TextDropTarget):
419
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   314
    '''
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   315
    This allows dragging a variable location from somewhere to the Location
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   316
    column of a variable row.
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   317
    
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   318
    The drag source should be a TextDataObject containing a Python tuple like:
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   319
        ('%ID0.0.0', 'location', 'REAL')
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   320
    
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   321
    c_ext/CFileEditor.py has an example of this (you can drag a C extension
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   322
    variable to the Location column of the variable panel).
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   323
    '''
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   324
    def __init__(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   325
        wx.TextDropTarget.__init__(self)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   326
        self.ParentWindow = parent
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   327
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   328
    def OnDropText(self, x, y, data):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   329
        x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   330
        col = self.ParentWindow.VariablesGrid.XToCol(x)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   331
        row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   332
        if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   333
            if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   334
                return
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   335
            message = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   336
            if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 425
diff changeset
   337
                message = _("Can't give a location to a function block instance")
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   338
            elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 425
diff changeset
   339
                message = _("Can only give a location to local or global variables")
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   340
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   341
                try:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   342
                    values = eval(data)    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   343
                except:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   344
                    message = _("Invalid value \"%s\" for location")%data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   345
                    values = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   346
                if not isinstance(values, TupleType):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   347
                    message = _("Invalid value \"%s\" for location")%data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   348
                    values = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   349
                if values is not None and values[1] == "location":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   350
                    location = values[0]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   351
                    variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   352
                    base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   353
                    message = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   354
                    if location.startswith("%"):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   355
                        if base_type != values[2]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   356
                            message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   357
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   358
                            self.ParentWindow.Table.SetValue(row, col, location)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   359
                            self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   360
                            self.ParentWindow.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   361
                    else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   362
                        if location[0].isdigit() and base_type != "BOOL":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   363
                            message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   364
                        elif location[0] not in LOCATIONDATATYPES:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   365
                            message = _("Unrecognized data size \"%s\"")%location[0]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   366
                        elif base_type not in LOCATIONDATATYPES[location[0]]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   367
                            message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   368
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   369
                            dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Select a variable class:"), _("Variable class"), ["Input", "Output", "Memory"], wx.OK|wx.CANCEL)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   370
                            if dialog.ShowModal() == wx.ID_OK:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   371
                                selected = dialog.GetSelection()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   372
                                if selected == 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   373
                                    location = "%I" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   374
                                elif selected == 1:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   375
                                    location = "%Q" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   376
                                else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   377
                                    location = "%M" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   378
                                self.ParentWindow.Table.SetValue(row, col, location)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   379
                                self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   380
                                self.ParentWindow.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   381
                            dialog.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   382
            if message is not None:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   383
                wx.CallAfter(self.ShowMessage, message)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   384
            
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   385
    def ShowMessage(self, message):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   386
        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   387
        message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   388
        message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   389
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   390
[ID_VARIABLEEDITORPANEL, ID_VARIABLEEDITORPANELVARIABLESGRID, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   391
 ID_VARIABLEEDITORCONTROLPANEL, ID_VARIABLEEDITORPANELRETURNTYPE, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   392
 ID_VARIABLEEDITORPANELCLASSFILTER, ID_VARIABLEEDITORPANELADDBUTTON, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   393
 ID_VARIABLEEDITORPANELDELETEBUTTON, ID_VARIABLEEDITORPANELUPBUTTON, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   394
 ID_VARIABLEEDITORPANELDOWNBUTTON, ID_VARIABLEEDITORPANELSTATICTEXT1, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   395
 ID_VARIABLEEDITORPANELSTATICTEXT2, ID_VARIABLEEDITORPANELSTATICTEXT3,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   396
] = [wx.NewId() for _init_ctrls in range(12)]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   397
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   398
class VariablePanel(wx.Panel):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   399
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   400
    if wx.VERSION < (2, 6, 0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   401
        def Bind(self, event, function, id = None):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   402
            if id is not None:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   403
                event(self, id, function)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   404
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   405
                event(self, function)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   406
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   407
    def _init_coll_MainSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   408
        parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   409
        parent.AddWindow(self.ControlPanel, 0, border=5, flag=wx.GROW|wx.ALL)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   410
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   411
    def _init_coll_MainSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   412
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   413
        parent.AddGrowableRow(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   414
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   415
    def _init_coll_ControlPanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   416
        parent.AddSizer(self.ChoicePanelSizer, 0, border=0, flag=wx.GROW)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   417
        parent.AddSizer(self.ButtonPanelSizer, 0, border=0, flag=wx.ALIGN_CENTER)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   419
    def _init_coll_ControlPanelSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   420
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   421
        parent.AddGrowableRow(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   422
        parent.AddGrowableRow(1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   423
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   424
    def _init_coll_ChoicePanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   425
        parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   426
        parent.AddWindow(self.ReturnType, 0, border=0, flag=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   427
        parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   428
        parent.AddWindow(self.ClassFilter, 0, border=0, flag=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   429
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   430
    def _init_coll_ButtonPanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   431
        parent.AddWindow(self.UpButton, 0, border=0, flag=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   432
        parent.AddWindow(self.AddButton, 0, border=0, flag=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   433
        parent.AddWindow(self.DownButton, 0, border=0, flag=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   434
        parent.AddWindow(self.DeleteButton, 0, border=0, flag=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   435
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   436
    def _init_coll_ButtonPanelSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   437
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   438
        parent.AddGrowableCol(1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   439
        parent.AddGrowableCol(2)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   440
        parent.AddGrowableCol(3)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   441
        parent.AddGrowableRow(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   442
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   443
    def _init_sizers(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   444
        self.MainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   445
        self.ControlPanelSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   446
        self.ChoicePanelSizer = wx.GridSizer(cols=1, hgap=5, rows=4, vgap=5)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   447
        self.ButtonPanelSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   448
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   449
        self._init_coll_MainSizer_Items(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   450
        self._init_coll_MainSizer_Growables(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   451
        self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   452
        self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   453
        self._init_coll_ChoicePanelSizer_Items(self.ChoicePanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   454
        self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   455
        self._init_coll_ButtonPanelSizer_Growables(self.ButtonPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   456
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   457
        self.SetSizer(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   458
        self.ControlPanel.SetSizer(self.ControlPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   459
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   460
    def _init_ctrls(self, prnt):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   461
        wx.Panel.__init__(self, id=ID_VARIABLEEDITORPANEL,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   462
              name='VariableEditorPanel', parent=prnt, pos=wx.Point(0, 0),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   463
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   464
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   465
        self.VariablesGrid = CustomGrid(id=ID_VARIABLEEDITORPANELVARIABLESGRID,
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   466
              name='VariablesGrid', parent=self, pos=wx.Point(0, 0), 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   467
              size=wx.Size(0, 0), style=wx.VSCROLL)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   468
        self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   469
              'Sans'))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   470
        self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   471
              False, 'Sans'))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   472
        self.VariablesGrid.SetSelectionBackground(wx.WHITE)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   473
        self.VariablesGrid.SetSelectionForeground(wx.BLACK)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   474
        if wx.VERSION >= (2, 6, 0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   475
            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   476
            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   477
            self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   478
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   479
            wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   480
            wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   481
            wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   482
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   483
        self.ControlPanel = wx.ScrolledWindow(id=ID_VARIABLEEDITORCONTROLPANEL,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   484
              name='ControlPanel', parent=self, pos=wx.Point(0, 0),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   485
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   486
        self.ControlPanel.SetScrollRate(0, 10)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   487
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   488
        self.staticText1 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT1,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   489
              label=_('Return Type:'), name='staticText1', parent=self.ControlPanel,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   490
              pos=wx.Point(0, 0), size=wx.Size(145, 17), style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   491
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   492
        self.ReturnType = wx.ComboBox(id=ID_VARIABLEEDITORPANELRETURNTYPE,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   493
              name='ReturnType', parent=self.ControlPanel, pos=wx.Point(0, 0),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   494
              size=wx.Size(145, 28), style=wx.CB_READONLY)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   495
        self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, id=ID_VARIABLEEDITORPANELRETURNTYPE)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   496
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   497
        self.staticText2 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT2,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   498
              label=_('Class Filter:'), name='staticText2', parent=self.ControlPanel,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   499
              pos=wx.Point(0, 0), size=wx.Size(145, 17), style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   500
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   501
        self.ClassFilter = wx.ComboBox(id=ID_VARIABLEEDITORPANELCLASSFILTER,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   502
              name='ClassFilter', parent=self.ControlPanel, pos=wx.Point(0, 0),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   503
              size=wx.Size(145, 28), style=wx.CB_READONLY)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   504
        self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, id=ID_VARIABLEEDITORPANELCLASSFILTER)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   505
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   506
        self.AddButton = wx.Button(id=ID_VARIABLEEDITORPANELADDBUTTON, label=_('Add'),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   507
              name='AddButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   508
              size=wx.DefaultSize, style=0)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   509
        
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   510
        self.DeleteButton = wx.Button(id=ID_VARIABLEEDITORPANELDELETEBUTTON, label=_('Delete'),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   511
              name='DeleteButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   512
              size=wx.DefaultSize, style=0)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   513
        
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   514
        self.UpButton = wx.Button(id=ID_VARIABLEEDITORPANELUPBUTTON, label='^',
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   515
              name='UpButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   516
              size=wx.Size(32, 32), style=0)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   517
        
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   518
        self.DownButton = wx.Button(id=ID_VARIABLEEDITORPANELDOWNBUTTON, label='v',
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   519
              name='DownButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   520
              size=wx.Size(32, 32), style=0)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   521
        
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   522
        self._init_sizers()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   523
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   524
    def __init__(self, parent, window, controler, element_type):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   525
        self._init_ctrls(parent)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   526
        self.ParentWindow = window
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   527
        self.Controler = controler
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   528
        self.ElementType = element_type
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   529
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   530
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   531
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   532
        
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   533
        self.Filter = "All"
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   534
        self.FilterChoices = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   535
        self.FilterChoiceTransfer = GetFilterChoiceTransfer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   536
        
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   537
        self.DefaultValue = {   "Name" : "", "Class" : "", "Type" : "INT", "Location" : "",
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   538
                                "Initial Value" : "", "Option" : "",
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   539
                                "Documentation" : "", "Edit" : True
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   540
                            }
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   541
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   542
        if element_type in ["config", "resource"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   543
            self.DefaultTypes = {"All" : "Global"}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   544
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   545
            self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   546
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   547
        if element_type in ["config", "resource"] \
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   548
        or element_type in ["program", "transition", "action"]:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   549
            # this is an element that can have located variables
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   550
            self.Table = VariableTable(self, [], GetVariableTableColnames(True))
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   551
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   552
            if element_type in ["config", "resource"]:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   553
                self.FilterChoices = ["All", "Global"]#,"Access"]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   554
            else:
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   555
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   556
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   557
                                        "Variables", "   Local", "   Temp"]#,"Access"]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   558
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   559
            # these condense the ColAlignements list
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   560
            l = wx.ALIGN_LEFT
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   561
            c = wx.ALIGN_CENTER 
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   562
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   563
            #                      Num  Name    Class   Type    Loc     Init    Option   Doc
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   564
            self.ColSizes       = [40,  80,     70,     80,     80,     80,     100,     80]
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   565
            self.ColAlignements = [c,   l,      l,      l,      l,      l,      l,       l]
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   566
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   567
        else:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   568
            # this is an element that cannot have located variables
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   569
            self.Table = VariableTable(self, [], GetVariableTableColnames(False))
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   570
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   571
            if element_type == "function":
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   572
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   573
                                        "Interface", "   Input", "   Output", "   InOut",
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   574
                                        "Variables", "   Local"]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   575
            else:
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   576
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   577
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   578
                                        "Variables", "   Local", "   Temp"]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   579
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   580
            # these condense the ColAlignements list
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   581
            l = wx.ALIGN_LEFT
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   582
            c = wx.ALIGN_CENTER 
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   583
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   584
            #                      Num  Name    Class   Type    Init    Option   Doc
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   585
            self.ColSizes       = [40,  80,     70,     80,     80,     100,     160]
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   586
            self.ColAlignements = [c,   l,      l,      l,      l,      l,       l]
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   587
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   588
        for choice in self.FilterChoices:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   589
            self.ClassFilter.Append(_(choice))
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   590
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   591
        reverse_transfer = {}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   592
        for filter, choice in self.FilterChoiceTransfer.items():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   593
            reverse_transfer[choice] = filter
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   594
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   595
        self.RefreshTypeList()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   596
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   597
        self.VariablesGrid.SetTable(self.Table)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   598
        self.VariablesGrid.SetButtons({"Add": self.AddButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   599
                                       "Delete": self.DeleteButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   600
                                       "Up": self.UpButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   601
                                       "Down": self.DownButton})
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   602
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   603
        def _AddVariable(new_row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   604
            if not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   605
                row_content = self.DefaultValue.copy()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   606
                if self.Filter in self.DefaultTypes:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   607
                    row_content["Class"] = self.DefaultTypes[self.Filter]
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   608
                else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   609
                    row_content["Class"] = self.Filter
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   610
                if self.Filter == "All" and len(self.Values) > 0:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   611
                    self.Values.insert(new_row, row_content)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   612
                else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   613
                    self.Values.append(row_content)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   614
                    new_row = self.Table.GetNumberRows()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   615
                self.SaveValues()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   616
                self.RefreshValues()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   617
                return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   618
            return self.VariablesGrid.GetGridCursorRow()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   619
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   620
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   621
        def _DeleteVariable(row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   622
            if (self.Table.GetValueByName(row, "Edit") and 
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   623
                (not self.PouIsUsed or self.Table.GetValueByName(row, "Class") not in ["Input", "Output", "InOut"])):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   624
                self.Values.remove(self.Table.GetRow(row))
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   625
                self.SaveValues()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   626
                self.RefreshValues()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   627
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   628
            
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   629
        def _MoveVariable(row, move):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   630
            if (self.Filter == "All" and 
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   631
                (not self.PouIsUsed or self.Table.GetValueByName(row, "Class") not in ["Input", "Output", "InOut"])):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   632
                new_row = max(0, min(row + move, len(self.Values) - 1))
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   633
                if new_row != row:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   634
                    self.Values.insert(new_row, self.Values.pop(row))
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   635
                    self.SaveValues()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   636
                    self.RefreshValues()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   637
                return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   638
            return row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   639
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   640
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   641
        def _RefreshButtons():
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   642
            table_length = len(self.Table.data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   643
            row_class = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   644
            row_edit = True
496
5ff24ccff2c7 Disable Up and Down buttons when not useful
laurent
parents: 494
diff changeset
   645
            row = 0
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   646
            if table_length > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   647
                row = self.VariablesGrid.GetGridCursorRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   648
                row_edit = self.Table.GetValueByName(row, "Edit")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   649
                if self.PouIsUsed:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   650
                    row_class = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   651
            self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   652
            self.DeleteButton.Enable(table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"])
496
5ff24ccff2c7 Disable Up and Down buttons when not useful
laurent
parents: 494
diff changeset
   653
            self.UpButton.Enable(table_length > 0 and row > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
5ff24ccff2c7 Disable Up and Down buttons when not useful
laurent
parents: 494
diff changeset
   654
            self.DownButton.Enable(table_length > 0 and row < table_length - 1 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   655
        setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   656
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   657
        self.VariablesGrid.SetRowLabelSize(0)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   658
        for col in range(self.Table.GetNumberCols()):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   659
            attr = wx.grid.GridCellAttr()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   660
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   661
            self.VariablesGrid.SetColAttr(col, attr)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   662
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   663
            self.VariablesGrid.AutoSizeColumn(col, False)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   664
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   665
    def __del__(self):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   666
        self.RefreshHighlightsTimer.Stop()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   667
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   668
    def SetTagName(self, tagname):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   669
        self.TagName = tagname
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   670
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   671
    def IsFunctionBlockType(self, name):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   672
        bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   673
        pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   674
        if poutype != "function" and bodytype in ["ST", "IL"]:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   675
            return False
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   676
        else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   677
            return name in self.Controler.GetFunctionBlockTypes(self.TagName)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   678
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   679
    def RefreshView(self):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   680
        self.PouNames = self.Controler.GetProjectPouNames()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   681
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   682
        words = self.TagName.split("::")
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   683
        if self.ElementType == "config":
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   684
            self.PouIsUsed = False
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   685
            returnType = None
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   686
            self.Values = self.Controler.GetConfigurationGlobalVars(words[1])
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   687
        elif self.ElementType == "resource":
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   688
            self.PouIsUsed = False
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   689
            returnType = None
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   690
            self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2])
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   691
        else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   692
            if self.ElementType == "function":
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   693
                self.ReturnType.Clear()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   694
                for base_type in self.Controler.GetDataTypes(self.TagName, True):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   695
                    self.ReturnType.Append(base_type)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   696
                returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   697
            else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   698
                returnType = None
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   699
            self.PouIsUsed = self.Controler.PouIsUsed(words[1])
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   700
            self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   701
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   702
        if returnType is not None:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   703
            self.ReturnType.SetStringSelection(returnType)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   704
            self.ReturnType.Enable(True)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   705
            self.staticText1.Show()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   706
            self.ReturnType.Show()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   707
        else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   708
            self.ReturnType.Enable(False)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   709
            self.staticText1.Hide()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   710
            self.ReturnType.Hide()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   711
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   712
        self.RefreshValues()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   713
        self.VariablesGrid.RefreshButtons()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   714
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   715
    def OnReturnTypeChanged(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   716
        words = self.TagName.split("::")
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   717
        self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   718
        self.Controler.BufferProject()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   719
        self.ParentWindow.RefreshEditor(variablepanel = False)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   720
        self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   721
        event.Skip()
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   722
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   723
    def OnClassFilter(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   724
        self.Filter = self.FilterChoiceTransfer[VARIABLE_CHOICES_DICT[self.ClassFilter.GetStringSelection()]]
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   725
        self.RefreshTypeList()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   726
        self.RefreshValues()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   727
        self.VariablesGrid.RefreshButtons()
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   728
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   729
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   730
    def RefreshTypeList(self):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   731
        if self.Filter == "All":
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   732
            self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]]
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   733
        elif self.Filter == "Interface":
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   734
            self.ClassList = ["Input","Output","InOut","External"]
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   735
        elif self.Filter == "Variables":
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   736
            self.ClassList = ["Local","Temp"]
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   737
        else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   738
            self.ClassList = [self.Filter]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   739
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   740
    def OnVariablesGridCellChange(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   741
        row, col = event.GetRow(), event.GetCol()
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   742
        colname = self.Table.GetColLabelValue(col, False)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   743
        value = self.Table.GetValue(row, col)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   744
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   745
        if colname == "Name" and value != "":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   746
            if not TestIdentifier(value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   747
                message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   748
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   749
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   750
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   751
            elif value.upper() in IEC_KEYWORDS:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   752
                message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   753
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   754
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   755
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   756
            elif value.upper() in self.PouNames:
446
0dd1a5f2a7a1 Update internationalization
laurent
parents: 443
diff changeset
   757
                message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   758
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   759
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   760
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   761
            elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   762
                message = wx.MessageDialog(self, _("A variable with \"%s\" as name already exists in this pou!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   763
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   764
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   765
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   766
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   767
                self.SaveValues(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   768
                old_value = self.Table.GetOldValue()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   769
                if old_value != "":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   770
                    self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   771
                self.Controler.BufferProject()
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   772
                self.ParentWindow.RefreshEditor(variablepanel = False)
483
779a519f78f2 Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents: 449
diff changeset
   773
                self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   774
                event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   775
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   776
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   777
            if colname == "Class":
520
7ca6c3e076f7 Bug on changing variable class fixed
laurent
parents: 509
diff changeset
   778
                self.ParentWindow.RefreshEditor(variablepanel = False)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   779
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   780
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   781
    def OnVariablesGridEditorShown(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   782
        row, col = event.GetRow(), event.GetCol() 
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   783
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   784
        label_value = self.Table.GetColLabelValue(col)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   785
        if label_value == "Type":
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   786
            type_menu = wx.Menu(title='')   # the root menu
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   787
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   788
            # build a submenu containing standard IEC types
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   789
            base_menu = wx.Menu(title='')
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   790
            for base_type in self.Controler.GetBaseTypes():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   791
                new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   792
                AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   793
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   794
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   795
            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   796
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   797
            # build a submenu containing user-defined types
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   798
            datatype_menu = wx.Menu(title='')
484
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   799
            
acef952101a5 Adding support for excluding option when not available according to IEC 61131 standard
laurent
parents: 483
diff changeset
   800
            # TODO : remove complextypes argument when matiec can manage complex types in pou interface
491
d22a4a95fd5e Remove limitation on complex types in POU interface
laurent
parents: 484
diff changeset
   801
            datatypes = self.Controler.GetDataTypes(basetypes = False)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   802
            for datatype in datatypes:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   803
                new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   804
                AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   805
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   806
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   807
            type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   808
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   809
            # build a submenu containing function block types
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   810
            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   811
            pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   812
            classtype = self.Table.GetValueByName(row, "Class")
507
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   813
            
556
69214983dd03 Enabling support for direct array variable declaration
laurent
parents: 552
diff changeset
   814
            new_id = wx.NewId()
69214983dd03 Enabling support for direct array variable declaration
laurent
parents: 552
diff changeset
   815
            AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array"))
69214983dd03 Enabling support for direct array variable declaration
laurent
parents: 552
diff changeset
   816
            self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id)
507
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   817
            
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   818
            if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   819
            poutype != "function" and bodytype in ["ST", "IL"]:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   820
                functionblock_menu = wx.Menu(title='')
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   821
                fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   822
                for functionblock_type in fbtypes:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   823
                    new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   824
                    AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   825
                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   826
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   827
                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   828
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   829
            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   830
            corner_x = rect.x + rect.width
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   831
            corner_y = rect.y + self.VariablesGrid.GetColLabelSize()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   832
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   833
            # pop up this new menu
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   834
            self.VariablesGrid.PopupMenuXY(type_menu, corner_x, corner_y)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   835
            event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   836
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   837
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   838
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   839
    def GetVariableTypeFunction(self, base_type):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   840
        def VariableTypeFunction(event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   841
            row = self.VariablesGrid.GetGridCursorRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   842
            self.Table.SetValueByName(row, "Type", base_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   843
            self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   844
            self.SaveValues(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   845
            self.ParentWindow.RefreshEditor(variablepanel = False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   846
            self.Controler.BufferProject()
494
c91644c2bfa7 Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 491
diff changeset
   847
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   848
        return VariableTypeFunction
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   849
    
507
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   850
    def VariableArrayTypeFunction(self, event):
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   851
        row = self.VariablesGrid.GetGridCursorRow()
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   852
        dialog = ArrayTypeDialog(self, 
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   853
                                 self.Controler.GetDataTypes(self.TagName), 
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   854
                                 self.Table.GetValueByName(row, "Type"))
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   855
        if dialog.ShowModal() == wx.ID_OK:
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   856
            self.Table.SetValueByName(row, "Type", dialog.GetValue())
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   857
            self.Table.ResetView(self.VariablesGrid)
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   858
            self.SaveValues(False)
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   859
            self.ParentWindow.RefreshEditor(variablepanel = False)
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   860
            self.Controler.BufferProject()
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   861
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   862
        dialog.Destroy()
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 496
diff changeset
   863
    
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   864
    def OnVariablesGridCellLeftClick(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   865
        row = event.GetRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   866
        if event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit"):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   867
            row = event.GetRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   868
            var_name = self.Table.GetValueByName(row, "Name")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   869
            var_class = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   870
            var_type = self.Table.GetValueByName(row, "Type")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   871
            data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName)))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   872
            dragSource = wx.DropSource(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   873
            dragSource.SetData(data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   874
            dragSource.DoDragDrop()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   875
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   876
    
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   877
    def RefreshValues(self):
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   878
        data = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   879
        for num, variable in enumerate(self.Values):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   880
            if variable["Class"] in self.ClassList:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   881
                variable["Number"] = num + 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   882
                data.append(variable)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   883
        self.Table.SetData(data)
561
5c8fa95eb834 Fixing bug in Variable Panel when pressing Add,Delete,Up or Down button while a cell editor in variable grid is active
laurent
parents: 556
diff changeset
   884
        self.Table.ResetView(self.VariablesGrid)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 566
diff changeset
   885
            
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   886
    def SaveValues(self, buffer = True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   887
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   888
        if self.ElementType == "config":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   889
            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   890
        elif self.ElementType == "resource":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   891
            self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   892
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   893
            if self.ReturnType.IsEnabled():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   894
                self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   895
            self.Controler.SetPouInterfaceVars(words[1], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   896
        if buffer:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   897
            self.Controler.BufferProject()
494
c91644c2bfa7 Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 491
diff changeset
   898
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)            
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   899
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   900
#-------------------------------------------------------------------------------
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   901
#                        Highlights showing functions
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   902
#-------------------------------------------------------------------------------
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   903
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   904
    def OnRefreshHighlightsTimer(self, event):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   905
        self.Table.ResetView(self.VariablesGrid)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   906
        event.Skip()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   907
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   908
    def AddVariableHighlight(self, infos, highlight_type):
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   909
        if isinstance(infos[0], TupleType):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   910
            for i in xrange(*infos[0]):
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   911
                self.Table.AddHighlight((i,) + infos[1:], highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   912
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   913
            self.Table.AddHighlight(infos, highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   914
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   915
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   916
    def ClearHighlights(self, highlight_type=None):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   917
        self.Table.ClearHighlights(highlight_type)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   918
        self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   919
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   920
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   921
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   922
class LocationCellControl(wx.PyControl):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   923
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   924
    def _init_coll_MainSizer_Items(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   925
        parent.AddWindow(self.Location, 0, border=0, flag=wx.GROW)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   926
        parent.AddWindow(self.BrowseButton, 0, border=0, flag=wx.GROW)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   927
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   928
    def _init_coll_MainSizer_Growables(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   929
        parent.AddGrowableCol(0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   930
        parent.AddGrowableRow(0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   931
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   932
    def _init_sizers(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   933
        self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   934
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   935
        self._init_coll_MainSizer_Items(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   936
        self._init_coll_MainSizer_Growables(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   937
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   938
        self.SetSizer(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   939
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   940
    def _init_ctrls(self, prnt):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   941
        wx.Control.__init__(self, id=-1, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   942
              name='LocationCellControl', parent=prnt,  
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   943
              size=wx.DefaultSize, style=0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   944
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   945
        # create location text control
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   946
        self.Location = wx.TextCtrl(id=-1, name='Location', parent=self,
443
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   947
              pos=wx.Point(0, 0), size=wx.Size(0, 0), style=wx.TE_PROCESS_ENTER)
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   948
        self.Location.Bind(wx.EVT_KEY_DOWN, self.OnLocationChar)
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   949
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   950
        # create browse button
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   951
        self.BrowseButton = wx.Button(id=-1, label='...', 
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 561
diff changeset
   952
              name='BrowseButton', parent=self, pos=wx.Point(0, 0), 
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   953
              size=wx.Size(30, 0), style=0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   954
        self.BrowseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonClick)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   955
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   956
        self.Bind(wx.EVT_SIZE, self.OnSize)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   957
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   958
        self._init_sizers()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   959
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   960
    '''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   961
    Custom cell editor control with a text box and a button that launches
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 561
diff changeset
   962
    the BrowseLocationsDialog.
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   963
    '''
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   964
    def __init__(self, parent, locations):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   965
        self._init_ctrls(parent)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   966
        self.Locations = locations
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   967
        self.VarType = None
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   968
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   969
    def SetVarType(self, vartype):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   970
        self.VarType = vartype
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   971
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   972
    def SetValue(self, value):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   973
        self.Location.SetValue(value)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   974
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   975
    def GetValue(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   976
        return self.Location.GetValue()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   977
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   978
    def OnSize(self, event):
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   979
        self.Layout()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   980
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   981
    def OnBrowseButtonClick(self, event):
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   982
        # pop up the location browser dialog
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   983
        dialog = BrowseLocationsDialog(self, self.VarType, self.Locations)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   984
        if dialog.ShowModal() == wx.ID_OK:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   985
            infos = dialog.GetValues()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   986
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   987
            # set the location
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   988
            self.Location.SetValue(infos["location"])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   989
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   990
        dialog.Destroy()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   991
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   992
        self.Location.SetFocus()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   993
443
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   994
    def OnLocationChar(self, event):
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   995
        keycode = event.GetKeyCode()
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   996
        if keycode == wx.WXK_RETURN or keycode == wx.WXK_TAB:
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   997
            self.Parent.Parent.ProcessEvent(event)
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   998
            self.Parent.Parent.SetFocus()
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   999
        else:
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
  1000
            event.Skip()
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
  1001
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1002
    def SetInsertionPoint(self, i):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1003
        self.Location.SetInsertionPoint(i)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1004
    
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1005
    def SetFocus(self):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1006
        self.Location.SetFocus()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1007
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1008
class LocationCellEditor(wx.grid.PyGridCellEditor):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1009
    '''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1010
    Grid cell editor that uses LocationCellControl to display a browse button.
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1011
    '''
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1012
    def __init__(self, table, controler):
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1013
        wx.grid.PyGridCellEditor.__init__(self)
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1014
        self.Table = table
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1015
        self.Controler = controler
443
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
  1016
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
  1017
    def __del__(self):
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
  1018
        self.CellControl = None
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
  1019
    
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1020
    def Create(self, parent, id, evt_handler):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1021
        locations = self.Controler.GetVariableLocationTree()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1022
        if len(locations) > 0:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1023
            self.CellControl = LocationCellControl(parent, locations)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1024
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1025
            self.CellControl = wx.TextCtrl(parent, -1)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1026
        self.SetControl(self.CellControl)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1027
        if evt_handler:
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1028
            self.CellControl.PushEventHandler(evt_handler)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1029
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1030
    def BeginEdit(self, row, col, grid):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1031
        self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1032
        if isinstance(self.CellControl, LocationCellControl):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1033
            self.CellControl.SetVarType(self.Controler.GetBaseType(self.Table.GetValueByName(row, 'Type')))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1034
        self.CellControl.SetFocus()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1035
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1036
    def EndEdit(self, row, col, grid):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1037
        loc = self.CellControl.GetValue()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1038
        old_loc = self.Table.GetValueByName(row, 'Location')
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1039
        if loc != old_loc:
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1040
            self.Table.SetValueByName(row, 'Location', loc)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1041
            return True
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1042
        return False
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1043
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1044
    def SetSize(self, rect):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1045
        self.CellControl.SetDimensions(rect.x + 1, rect.y,
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
  1046
                                        rect.width, rect.height,
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1047
                                        wx.SIZE_ALLOW_MINUS_ONE)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1048
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1049
    def Clone(self):
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 561
diff changeset
  1050
        return LocationCellEditor(self.Table, self.Controler)
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1051
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1052
def GetDirChoiceOptions():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1053
    _ = lambda x : x
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1054
    return [(_("All"), [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1055
            (_("Input"), [LOCATION_VAR_INPUT]), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1056
            (_("Output"), [LOCATION_VAR_OUTPUT]), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1057
            (_("Memory"), [LOCATION_VAR_MEMORY])]
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1058
DIRCHOICE_OPTIONS_FILTER = dict([(_(option), filter) for option, filter in GetDirChoiceOptions()])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1059
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1060
# turn LOCATIONDATATYPES inside-out
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1061
LOCATION_SIZES = {}
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1062
for size, types in LOCATIONDATATYPES.iteritems():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1063
    for type in types:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1064
        LOCATION_SIZES[type] = size
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1065
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1066
[ID_BROWSELOCATIONSDIALOG, ID_BROWSELOCATIONSDIALOGLOCATIONSTREE, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1067
 ID_BROWSELOCATIONSDIALOGDIRCHOICE, ID_BROWSELOCATIONSDIALOGSTATICTEXT1, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1068
 ID_BROWSELOCATIONSDIALOGSTATICTEXT2, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1069
] = [wx.NewId() for _init_ctrls in range(5)]
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1070
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1071
class BrowseLocationsDialog(wx.Dialog):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1072
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1073
    if wx.VERSION < (2, 6, 0):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1074
        def Bind(self, event, function, id = None):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1075
            if id is not None:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1076
                event(self, id, function)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1077
            else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1078
                event(self, function)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1079
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1080
    def _init_coll_MainSizer_Items(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1081
        parent.AddWindow(self.staticText1, 0, border=20, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1082
        parent.AddWindow(self.LocationsTree, 0, border=20, flag=wx.LEFT|wx.RIGHT|wx.GROW)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1083
        parent.AddSizer(self.ButtonGridSizer, 0, border=20, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1084
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1085
    def _init_coll_MainSizer_Growables(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1086
        parent.AddGrowableCol(0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1087
        parent.AddGrowableRow(1)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1088
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1089
    def _init_coll_ButtonGridSizer_Items(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1090
        parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1091
        parent.AddWindow(self.DirChoice, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1092
        parent.AddSizer(self.ButtonSizer, 0, border=0, flag=wx.ALIGN_RIGHT)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1093
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1094
    def _init_coll_ButtonGridSizer_Growables(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1095
        parent.AddGrowableCol(2)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1096
        parent.AddGrowableRow(0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1097
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1098
    def _init_sizers(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1099
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1100
        self.ButtonGridSizer = wx.FlexGridSizer(cols=3, hgap=5, rows=1, vgap=0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1101
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1102
        self._init_coll_MainSizer_Items(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1103
        self._init_coll_MainSizer_Growables(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1104
        self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1105
        self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1106
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1107
        self.SetSizer(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1108
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1109
    def _init_ctrls(self, prnt):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1110
        wx.Dialog.__init__(self, id=ID_BROWSELOCATIONSDIALOG, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1111
              name='BrowseLocationsDialog', parent=prnt,  
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1112
              size=wx.Size(600, 400), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1113
              title=_('Browse Locations'))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1114
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1115
        self.staticText1 = wx.StaticText(id=ID_BROWSELOCATIONSDIALOGSTATICTEXT1,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1116
              label=_('Locations available:'), name='staticText1', parent=self,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1117
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1118
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1119
        if wx.Platform == '__WXMSW__':
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1120
            treestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1121
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1122
            treestyle = wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1123
        self.LocationsTree = wx.TreeCtrl(id=ID_BROWSELOCATIONSDIALOGLOCATIONSTREE,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1124
              name='LocationsTree', parent=self, pos=wx.Point(0, 0),
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1125
              size=wx.Size(0, 0), style=treestyle)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1126
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnLocationsTreeItemActivated, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1127
                  id=ID_BROWSELOCATIONSDIALOGLOCATIONSTREE)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1128
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1129
        self.staticText2 = wx.StaticText(id=ID_BROWSELOCATIONSDIALOGSTATICTEXT2,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1130
              label=_('Direction:'), name='staticText2', parent=self,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1131
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1132
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1133
        self.DirChoice = wx.ComboBox(id=ID_BROWSELOCATIONSDIALOGDIRCHOICE,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1134
              name='DirChoice', parent=self, pos=wx.Point(0, 0),
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1135
              size=wx.DefaultSize, style=wx.CB_READONLY)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1136
        self.Bind(wx.EVT_COMBOBOX, self.OnDirChoice, id=ID_BROWSELOCATIONSDIALOGDIRCHOICE)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1137
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1138
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1139
        if wx.VERSION >= (2, 5, 0):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1140
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1141
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1142
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1143
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1144
        self._init_sizers()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1145
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1146
    def __init__(self, parent, var_type, locations):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1147
        self._init_ctrls(parent)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1148
        self.VarType = var_type
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1149
        self.Locations = locations
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1150
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1151
        # Define Tree item icon list
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1152
        self.TreeImageList = wx.ImageList(16, 16)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1153
        self.TreeImageDict = {}
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1154
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1155
        # Icons for items
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1156
        for imgname, itemtype in [
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1157
            ("CONFIGURATION", LOCATION_PLUGIN), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1158
            ("RESOURCE",      LOCATION_MODULE), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1159
            ("PROGRAM",       LOCATION_GROUP), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1160
            ("VAR_INPUT",     LOCATION_VAR_INPUT), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1161
            ("VAR_OUTPUT",    LOCATION_VAR_OUTPUT), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1162
            ("VAR_LOCAL",     LOCATION_VAR_MEMORY)]:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1163
            self.TreeImageDict[itemtype]=self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%imgname)))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1164
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1165
        # Assign icon list to TreeCtrls
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1166
        self.LocationsTree.SetImageList(self.TreeImageList)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1167
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1168
        # Set a options for the choice
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1169
        for option, filter in GetDirChoiceOptions():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1170
            self.DirChoice.Append(_(option))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1171
        self.DirChoice.SetStringSelection(_("All"))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1172
        self.RefreshFilter()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1173
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1174
        self.RefreshLocationsTree()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1175
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1176
    def RefreshFilter(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1177
        self.Filter = DIRCHOICE_OPTIONS_FILTER[self.DirChoice.GetStringSelection()]
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1178
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1179
    def RefreshLocationsTree(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1180
        root = self.LocationsTree.GetRootItem()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1181
        if not root.IsOk():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1182
            if wx.Platform == '__WXMSW__':
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1183
                root = self.LocationsTree.AddRoot(_('Plugins'))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1184
            else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1185
                root = self.LocationsTree.AddRoot("")
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1186
        self.GenerateLocationsTreeBranch(root, self.Locations)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1187
        self.LocationsTree.Expand(root)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1188
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1189
    def GenerateLocationsTreeBranch(self, root, locations):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1190
        to_delete = []
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1191
        if wx.VERSION >= (2, 6, 0):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1192
            item, root_cookie = self.LocationsTree.GetFirstChild(root)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1193
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1194
            item, root_cookie = self.LocationsTree.GetFirstChild(root, 0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1195
        for loc_infos in locations:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1196
            infos = loc_infos.copy()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1197
            if infos["type"] in [LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP] or\
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1198
               infos["type"] in self.Filter and (infos["IEC_type"] == self.VarType or
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1199
               infos["IEC_type"] is None and LOCATION_SIZES[self.VarType] == infos["size"]):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1200
                children = [child for child in infos.pop("children")]
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1201
                if not item.IsOk():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1202
                    item = self.LocationsTree.AppendItem(root, infos["name"])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1203
                    if wx.Platform != '__WXMSW__':
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1204
                        item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1205
                else:
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1206
                    self.LocationsTree.SetItemText(item, infos["name"])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1207
                self.LocationsTree.SetPyData(item, infos)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1208
                self.LocationsTree.SetItemImage(item, self.TreeImageDict[infos["type"]])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1209
                self.GenerateLocationsTreeBranch(item, children)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1210
                item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1211
        while item.IsOk():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1212
            to_delete.append(item)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1213
            item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1214
        for item in to_delete:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1215
            self.LocationsTree.Delete(item)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1216
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1217
    def OnLocationsTreeItemActivated(self, event):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1218
        infos = self.LocationsTree.GetPyData(event.GetItem())
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1219
        if infos["type"] not in [LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP]:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1220
            wx.CallAfter(self.EndModal, wx.ID_OK)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1221
        event.Skip()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1222
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1223
    def OnDirChoice(self, event):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1224
        self.RefreshFilter()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1225
        self.RefreshLocationsTree()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1226
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1227
    def GetValues(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1228
        selected = self.LocationsTree.GetSelection()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1229
        return self.LocationsTree.GetPyData(selected)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1230
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1231
    def OnOK(self, event):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1232
        selected = self.LocationsTree.GetSelection()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1233
        var_infos = None
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1234
        if selected.IsOk():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1235
            var_infos = self.LocationsTree.GetPyData(selected)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1236
        if var_infos is None or var_infos["type"] in [LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP]:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1237
            message = wx.MessageDialog(self, _("A location must be selected!"), _("Error"), wx.OK|wx.ICON_ERROR)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1238
            message.ShowModal()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1239
            message.Destroy()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1240
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1241
            self.EndModal(wx.ID_OK)