VariablePanel.py
author laurent
Thu, 08 Oct 2009 16:40:08 +0200
changeset 443 5f7d5d1a6f99
parent 440 e183bffc05f0
child 446 0dd1a5f2a7a1
permissions -rw-r--r--
Add support for leaving LocationControl when RETURN or TAB pressed
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     2
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     3
#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
     4
#based on the plcopen standard. 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     5
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     6
#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
     7
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     8
#See COPYING file for copyrights details.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
     9
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    10
#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
    11
#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
    12
#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
    13
#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
    14
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    15
#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
    16
#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
    17
#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
    18
#General Public License for more details.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    19
#
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    20
#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
    21
#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
    22
#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
    23
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
    24
import os
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    25
import wx, wx.grid
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    26
419
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
    27
from types import TupleType
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
    28
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    29
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
    30
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, 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
    31
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
    32
CWD = os.path.split(os.path.realpath(__file__))[0]
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    33
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    34
# Compatibility function for wx versions < 2.6
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    35
def AppendMenu(parent, help, id, kind, text):
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    36
    if wx.VERSION >= (2, 6, 0):
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    37
        parent.Append(help=help, id=id, kind=kind, text=text)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    38
    else:
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    39
        parent.Append(helpString=help, id=id, kind=kind, item=text)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    40
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    41
[TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, 
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    42
 INSTANCESTREE, LIBRARYTREE, SCALING
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
    43
] = range(9)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    44
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    45
#-------------------------------------------------------------------------------
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    46
#                            Variables Editor Panel
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    47
#-------------------------------------------------------------------------------
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
def GetVariableTableColnames(location):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    50
    _ = lambda x : x
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    51
    if location:
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
    52
    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
    53
    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    54
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    55
def GetAlternativeOptions():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    56
    _ = lambda x : x
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    57
    return [_("Yes"), _("No")]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    58
ALTERNATIVE_OPTIONS_DICT = dict([(_(option), option) for option in GetAlternativeOptions()])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    59
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    60
def GetFilterChoiceTransfer():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    61
    _ = lambda x : x
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    62
    return {_("All"): _("All"), _("Interface"): _("Interface"), 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    63
            _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"), 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    64
            _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    65
            _("   Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    66
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
    67
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    68
class VariableTable(wx.grid.PyGridTableBase):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    69
    
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
    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
    72
    """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    73
    def __init__(self, parent, data, colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    74
        # The base class must be initialized *first*
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    75
        wx.grid.PyGridTableBase.__init__(self)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    76
        self.data = data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    77
        self.old_value = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    78
        self.colnames = colnames
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    79
        self.Errors = {}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    80
        self.Parent = parent
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    81
        # XXX
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    82
        # 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
    83
        # see if the table has changed size
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    84
        self._rows = self.GetNumberRows()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    85
        self._cols = self.GetNumberCols()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    86
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    87
    def GetNumberCols(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    88
        return len(self.colnames)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    89
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    90
    def GetNumberRows(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    91
        return len(self.data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    92
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    93
    def GetColLabelValue(self, col, translate=True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    94
        if col < len(self.colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    95
            if translate:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    96
                return _(self.colnames[col])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    97
            return self.colnames[col]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    98
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    99
    def GetRowLabelValues(self, row, translate=True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   100
        return row
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   101
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   102
    def GetValue(self, row, col):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   103
        if row < self.GetNumberRows():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   104
            if col == 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   105
                return self.data[row]["Number"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   106
            colname = self.GetColLabelValue(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   107
            value = str(self.data[row].get(colname, ""))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   108
            if colname in ["Class", "Retain", "Constant"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   109
                return _(value)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   110
            return value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   111
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   112
    def SetValue(self, row, col, value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   113
        if col < len(self.colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   114
            colname = self.GetColLabelValue(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   115
            if colname == "Name":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   116
                self.old_value = self.data[row][colname]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   117
            elif colname == "Class":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   118
                value = VARIABLE_CLASSES_DICT[value]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   119
            elif colname in ["Retain", "Constant"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   120
                value = ALTERNATIVE_OPTIONS_DICT[value]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   121
            self.data[row][colname] = value
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 GetValueByName(self, row, colname):
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
            return self.data[row].get(colname)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   126
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   127
    def SetValueByName(self, row, colname, value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   128
        if row < self.GetNumberRows():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   129
            self.data[row][colname] = value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   130
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   131
    def GetOldValue(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   132
        return self.old_value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   133
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   134
    def ResetView(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   135
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   136
        (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
   137
        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
   138
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   139
        grid.BeginBatch()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   140
        for current, new, delmsg, addmsg in [
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   141
            (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
   142
            (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
   143
        ]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   144
            if new < current:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   145
                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
   146
                grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   147
            elif new > current:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   148
                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
   149
                grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   150
                self.UpdateValues(grid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   151
        grid.EndBatch()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   152
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   153
        self._rows = self.GetNumberRows()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   154
        self._cols = self.GetNumberCols()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   155
        # update the column rendering scheme
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   156
        self._updateColAttrs(grid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   157
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   158
        # 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
   159
        grid.AdjustScrollbars()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   160
        grid.ForceRefresh()
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 UpdateValues(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   163
        """Update all displayed values"""
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   164
        # 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
   165
        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
   166
        grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   167
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   168
    def _updateColAttrs(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   169
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   170
        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
   171
        appropriate renderer given the column name.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   172
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   173
        Otherwise default to the default renderer.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   174
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   175
        for row in range(self.GetNumberRows()):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   176
            for col in range(self.GetNumberCols()):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   177
                editor = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   178
                renderer = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   179
                colname = self.GetColLabelValue(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   180
                if col != 0 and self.GetValueByName(row, "Edit"):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   181
                    grid.SetReadOnly(row, col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   182
                    if colname == "Name":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   183
                        if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   184
                            grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   185
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   186
                            editor = wx.grid.GridCellTextEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   187
                            renderer = wx.grid.GridCellStringRenderer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   188
                    elif colname == "Initial Value":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   189
                        editor = wx.grid.GridCellTextEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   190
                        renderer = wx.grid.GridCellStringRenderer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   191
                    elif colname == "Location":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   192
                        if self.GetValueByName(row, "Class") in ["Local", "Global"]:
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   193
                            editor = LocationCellEditor(self, self.Parent.Controler)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   194
                            renderer = wx.grid.GridCellStringRenderer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   195
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   196
                            grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   197
                    elif colname == "Class":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   198
                        if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   199
                            grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   200
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   201
                            editor = wx.grid.GridCellChoiceEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   202
                            excluded = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   203
                            if self.Parent.PouIsUsed:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   204
                                excluded.extend(["Input","Output","InOut"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   205
                            if self.Parent.IsFunctionBlockType(self.data[row]["Type"]):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   206
                                excluded.extend(["Local","Temp"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   207
                            editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   208
                    elif colname in ["Retain", "Constant"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   209
                        editor = wx.grid.GridCellChoiceEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   210
                        editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   211
                    elif colname == "Type":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   212
                        editor = wx.grid.GridCellTextEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   213
                else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   214
                    grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   215
                
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   216
                grid.SetCellEditor(row, col, editor)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   217
                grid.SetCellRenderer(row, col, renderer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   218
                
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   219
                if row in self.Errors and self.Errors[row][0] == colname.lower():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   220
                    grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   221
                    grid.SetCellTextColour(row, col, wx.RED)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   222
                    grid.MakeCellVisible(row, col)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   223
                else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   224
                    grid.SetCellTextColour(row, col, wx.BLACK)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   225
                    grid.SetCellBackgroundColour(row, col, wx.WHITE)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   226
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   227
    def SetData(self, data):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   228
        self.data = data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   229
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   230
    def GetData(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   231
        return self.data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   232
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   233
    def GetCurrentIndex(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   234
        return self.CurrentIndex
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   235
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   236
    def SetCurrentIndex(self, index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   237
        self.CurrentIndex = index
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   238
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   239
    def AppendRow(self, row_content):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   240
        self.data.append(row_content)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   241
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   242
    def RemoveRow(self, row_index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   243
        self.data.pop(row_index)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   244
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   245
    def GetRow(self, row_index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   246
        return self.data[row_index]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   247
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   248
    def Empty(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   249
        self.data = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   250
        self.editors = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   251
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   252
    def AddError(self, infos):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   253
        self.Errors[infos[0]] = infos[1:]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   254
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   255
    def ClearErrors(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   256
        self.Errors = {}
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
class VariableDropTarget(wx.TextDropTarget):
419
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   259
    '''
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   260
    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
   261
    column of a variable row.
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   262
    
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   263
    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
   264
        ('%ID0.0.0', 'location', 'REAL')
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   265
    
8f97ed01a6a6 VariablePanel.py also depends on types.TupleType
b.taylor@willowglen.ca
parents: 418
diff changeset
   266
    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
   267
    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
   268
    '''
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   269
    def __init__(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   270
        wx.TextDropTarget.__init__(self)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   271
        self.ParentWindow = parent
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 OnDropText(self, x, y, data):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   274
        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
   275
        col = self.ParentWindow.VariablesGrid.XToCol(x)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   276
        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
   277
        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
   278
            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
   279
                return
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   280
            message = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   281
            if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 425
diff changeset
   282
                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
   283
            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
   284
                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
   285
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   286
                try:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   287
                    values = eval(data)    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   288
                except:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   289
                    message = _("Invalid value \"%s\" for location")%data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   290
                    values = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   291
                if not isinstance(values, TupleType):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   292
                    message = _("Invalid value \"%s\" for location")%data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   293
                    values = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   294
                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
   295
                    location = values[0]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   296
                    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
   297
                    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
   298
                    message = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   299
                    if location.startswith("%"):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   300
                        if base_type != values[2]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   301
                            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
   302
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   303
                            self.ParentWindow.Table.SetValue(row, col, location)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   304
                            self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   305
                            self.ParentWindow.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   306
                    else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   307
                        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
   308
                            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
   309
                        elif location[0] not in LOCATIONDATATYPES:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   310
                            message = _("Unrecognized data size \"%s\"")%location[0]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   311
                        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
   312
                            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
   313
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   314
                            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
   315
                            if dialog.ShowModal() == wx.ID_OK:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   316
                                selected = dialog.GetSelection()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   317
                                if selected == 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   318
                                    location = "%I" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   319
                                elif selected == 1:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   320
                                    location = "%Q" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   321
                                else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   322
                                    location = "%M" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   323
                                self.ParentWindow.Table.SetValue(row, col, location)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   324
                                self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   325
                                self.ParentWindow.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   326
                            dialog.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   327
            if message is not None:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   328
                wx.CallAfter(self.ShowMessage, message)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   329
            
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   330
    def ShowMessage(self, message):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   331
        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
   332
        message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   333
        message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   334
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   335
[ID_VARIABLEEDITORPANEL, ID_VARIABLEEDITORPANELVARIABLESGRID, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   336
 ID_VARIABLEEDITORCONTROLPANEL, ID_VARIABLEEDITORPANELRETURNTYPE, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   337
 ID_VARIABLEEDITORPANELCLASSFILTER, ID_VARIABLEEDITORPANELADDBUTTON, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   338
 ID_VARIABLEEDITORPANELDELETEBUTTON, ID_VARIABLEEDITORPANELUPBUTTON, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   339
 ID_VARIABLEEDITORPANELDOWNBUTTON, ID_VARIABLEEDITORPANELSTATICTEXT1, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   340
 ID_VARIABLEEDITORPANELSTATICTEXT2, ID_VARIABLEEDITORPANELSTATICTEXT3,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   341
] = [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
   342
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   343
class VariablePanel(wx.Panel):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   344
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   345
    if wx.VERSION < (2, 6, 0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   346
        def Bind(self, event, function, id = None):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   347
            if id is not None:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   348
                event(self, id, function)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   349
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   350
                event(self, function)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   351
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   352
    def _init_coll_MainSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   353
        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
   354
        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
   355
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   356
    def _init_coll_MainSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   357
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   358
        parent.AddGrowableRow(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   359
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   360
    def _init_coll_ControlPanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   361
        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
   362
        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
   363
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   364
    def _init_coll_ControlPanelSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   365
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   366
        parent.AddGrowableRow(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   367
        parent.AddGrowableRow(1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   368
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   369
    def _init_coll_ChoicePanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   370
        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
   371
        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
   372
        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
   373
        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
   374
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   375
    def _init_coll_ButtonPanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   376
        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
   377
        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
   378
        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
   379
        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
   380
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   381
    def _init_coll_ButtonPanelSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   382
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   383
        parent.AddGrowableCol(1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   384
        parent.AddGrowableCol(2)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   385
        parent.AddGrowableCol(3)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   386
        parent.AddGrowableRow(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   387
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   388
    def _init_sizers(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   389
        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
   390
        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
   391
        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
   392
        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
   393
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   394
        self._init_coll_MainSizer_Items(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   395
        self._init_coll_MainSizer_Growables(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   396
        self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   397
        self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   398
        self._init_coll_ChoicePanelSizer_Items(self.ChoicePanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   399
        self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   400
        self._init_coll_ButtonPanelSizer_Growables(self.ButtonPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   401
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   402
        self.SetSizer(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   403
        self.ControlPanel.SetSizer(self.ControlPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   404
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   405
    def _init_ctrls(self, prnt):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   406
        wx.Panel.__init__(self, id=ID_VARIABLEEDITORPANEL,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   407
              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
   408
              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
   409
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   410
        self.VariablesGrid = wx.grid.Grid(id=ID_VARIABLEEDITORPANELVARIABLESGRID,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   411
              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
   412
              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
   413
        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
   414
              'Sans'))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   415
        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
   416
              False, 'Sans'))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   417
        self.VariablesGrid.SetSelectionBackground(wx.WHITE)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   418
        self.VariablesGrid.SetSelectionForeground(wx.BLACK)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   419
        if wx.VERSION >= (2, 6, 0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   420
            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
   421
            self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   422
            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
   423
            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
   424
            #self.VariablesGrid.Bind(wx.EVT_KEY_DOWN, self.OnChar)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   425
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   426
            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
   427
            wx.grid.EVT_GRID_SELECT_CELL(self.VariablesGrid, self.OnVariablesGridSelectCell)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   428
            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
   429
            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
   430
            #wx.EVT_KEY_DOWN(self.VariablesGrid, self.OnChar)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   431
        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   432
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   433
        self.ControlPanel = wx.ScrolledWindow(id=ID_VARIABLEEDITORCONTROLPANEL,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   434
              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
   435
              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
   436
        self.ControlPanel.SetScrollRate(0, 10)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   437
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   438
        self.staticText1 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT1,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   439
              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
   440
              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
   441
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   442
        self.ReturnType = wx.ComboBox(id=ID_VARIABLEEDITORPANELRETURNTYPE,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   443
              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
   444
              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
   445
        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
   446
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   447
        self.staticText2 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT2,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   448
              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
   449
              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
   450
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   451
        self.ClassFilter = wx.ComboBox(id=ID_VARIABLEEDITORPANELCLASSFILTER,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   452
              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
   453
              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
   454
        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
   455
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   456
        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
   457
              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
   458
              size=wx.DefaultSize, style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   459
        self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_VARIABLEEDITORPANELADDBUTTON)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   460
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   461
        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
   462
              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
   463
              size=wx.DefaultSize, style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   464
        self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_VARIABLEEDITORPANELDELETEBUTTON)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   465
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   466
        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
   467
              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
   468
              size=wx.Size(32, 32), style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   469
        self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_VARIABLEEDITORPANELUPBUTTON)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   470
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   471
        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
   472
              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
   473
              size=wx.Size(32, 32), style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   474
        self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_VARIABLEEDITORPANELDOWNBUTTON)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   475
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   476
        self._init_sizers()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   477
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   478
    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
   479
        self._init_ctrls(parent)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   480
        self.ParentWindow = window
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   481
        self.Controler = controler
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   482
        self.ElementType = element_type
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   483
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   484
        self.Filter = "All"
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   485
        self.FilterChoices = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   486
        self.FilterChoiceTransfer = GetFilterChoiceTransfer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   487
        
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   488
        self.DefaultValue = {   "Name" : "", "Class" : "", "Type" : "INT", "Location" : "",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   489
                                "Initial Value" : "", "Retain" : "No", "Constant" : "No",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   490
                                "Documentation" : "", "Edit" : True
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   491
                            }
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   492
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   493
        if element_type in ["config", "resource"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   494
            self.DefaultTypes = {"All" : "Global"}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   495
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   496
            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
   497
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   498
        if element_type in ["config", "resource"] \
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   499
        or element_type in ["program", "transition", "action"]:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   500
            # 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
   501
            self.Table = VariableTable(self, [], GetVariableTableColnames(True))
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   502
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   503
            if element_type in ["config", "resource"]:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   504
                self.FilterChoices = ["All", "Global"]#,"Access"]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   505
            else:
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   506
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   507
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   508
                                        "Variables", "   Local", "   Temp"]#,"Access"]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   509
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   510
            # these condense the ColAlignements list
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   511
            l = wx.ALIGN_LEFT
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   512
            c = wx.ALIGN_CENTER 
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   513
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   514
            #                      Num  Name    Class   Type    Loc     Init    Retain  Const   Doc
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   515
            self.ColSizes       = [40,  80,     70,     80,     80,     80,     60,     70,     80]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   516
            self.ColAlignements = [c,   l,      l,      l,      l,      l,      c,      c,      l]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   517
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   518
        else:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   519
            # 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
   520
            self.Table = VariableTable(self, [], GetVariableTableColnames(False))
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   521
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   522
            if element_type == "function":
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   523
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   524
                                        "Interface", "   Input", "   Output", "   InOut",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   525
                                        "Variables", "   Local", "   Temp"]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   526
            else:
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   527
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   528
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   529
                                        "Variables", "   Local", "   Temp"]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   530
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   531
            # these condense the ColAlignements list
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   532
            l = wx.ALIGN_LEFT
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   533
            c = wx.ALIGN_CENTER 
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   534
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   535
            #                      Num  Name    Class   Type    Init    Retain  Const   Doc
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   536
            self.ColSizes       = [40,  80,     70,     80,     80,     60,     70,     160]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   537
            self.ColAlignements = [c,   l,      l,      l,      l,      c,      c,      l]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   538
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   539
        for choice in self.FilterChoices:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   540
            self.ClassFilter.Append(_(choice))
424
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
        reverse_transfer = {}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   543
        for filter, choice in self.FilterChoiceTransfer.items():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   544
            reverse_transfer[choice] = filter
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   545
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   546
        self.RefreshTypeList()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   547
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   548
        self.OptionList = GetAlternativeOptions()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   549
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   550
        if element_type == "function":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   551
            for base_type in self.Controler.GetBaseTypes():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   552
                self.ReturnType.Append(base_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   553
            self.ReturnType.Enable(True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   554
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   555
            self.ReturnType.Enable(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   556
            self.staticText1.Hide()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   557
            self.ReturnType.Hide()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   558
            
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   559
        self.VariablesGrid.SetTable(self.Table)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   560
        self.VariablesGrid.SetRowLabelSize(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   561
        for col in range(self.Table.GetNumberCols()):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   562
            attr = wx.grid.GridCellAttr()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   563
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   564
            self.VariablesGrid.SetColAttr(col, attr)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   565
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   566
            self.VariablesGrid.AutoSizeColumn(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   567
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   568
    def SetTagName(self, tagname):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   569
        self.TagName = tagname
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   570
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   571
    def IsFunctionBlockType(self, name):
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   572
        bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   573
        pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   574
        if poutype != "function" and bodytype in ["ST", "IL"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   575
            return False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   576
        else:
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   577
            return name in self.Controler.GetFunctionBlockTypes(self.TagName)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   578
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   579
    def RefreshView(self):
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   580
        self.PouNames = self.Controler.GetProjectPouNames()
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   581
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   582
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   583
        if self.ElementType == "config":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   584
            self.PouIsUsed = False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   585
            returnType = None
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   586
            self.Values = self.Controler.GetConfigurationGlobalVars(words[1])
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   587
        elif self.ElementType == "resource":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   588
            self.PouIsUsed = False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   589
            returnType = None
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   590
            self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2])
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   591
        else:
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   592
            self.PouIsUsed = self.Controler.PouIsUsed(words[1])
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   593
            returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   594
            self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   595
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   596
        if returnType and self.ReturnType.IsEnabled():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   597
            self.ReturnType.SetStringSelection(returnType)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   598
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   599
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   600
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   601
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   602
    def OnReturnTypeChanged(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   603
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   604
        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
   605
        self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   606
        self.ParentWindow.RefreshEditor(variablepanel = False)
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   607
        self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCETREE, LIBRARYTREE)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   608
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   609
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   610
    def OnClassFilter(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   611
        self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   612
        self.RefreshTypeList()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   613
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   614
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   615
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   616
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   617
    def RefreshTypeList(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   618
        if self.Filter == "All":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   619
            self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   620
        elif self.Filter == "Interface":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   621
            self.ClassList = ["Input","Output","InOut","External"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   622
        elif self.Filter == "Variables":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   623
            self.ClassList = ["Local","Temp"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   624
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   625
            self.ClassList = [self.Filter]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   626
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   627
    def RefreshButtons(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   628
        if getattr(self, "Table", None):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   629
            table_length = len(self.Table.data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   630
            row_class = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   631
            row_edit = True
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   632
            if table_length > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   633
                row = self.VariablesGrid.GetGridCursorRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   634
                row_edit = self.Table.GetValueByName(row, "Edit")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   635
                if self.PouIsUsed:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   636
                    row_class = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   637
            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
   638
            self.DeleteButton.Enable(table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   639
            self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   640
            self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   641
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   642
    def OnAddButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   643
        new_row = self.DefaultValue.copy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   644
        if self.Filter in self.DefaultTypes:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   645
            new_row["Class"] = self.DefaultTypes[self.Filter]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   646
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   647
            new_row["Class"] = self.Filter
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   648
        if self.Filter == "All" and len(self.Values) > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   649
            row_index = self.VariablesGrid.GetGridCursorRow() + 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   650
            self.Values.insert(row_index, new_row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   651
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   652
            row_index = -1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   653
            self.Values.append(new_row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   654
        self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   655
        self.RefreshValues(row_index)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   656
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   657
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   658
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   659
    def OnDeleteButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   660
        row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   661
        self.Values.remove(row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   662
        self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   663
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   664
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   665
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   666
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   667
    def OnUpButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   668
        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   669
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   670
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   671
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   672
    def OnDownButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   673
        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   674
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   675
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   676
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   677
    def OnVariablesGridCellChange(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   678
        row, col = event.GetRow(), event.GetCol()
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   679
        colname = self.Table.GetColLabelValue(col, False)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   680
        value = self.Table.GetValue(row, col)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   681
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   682
        if colname == "Name" and value != "":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   683
            if not TestIdentifier(value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   684
                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
   685
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   686
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   687
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   688
            elif value.upper() in IEC_KEYWORDS:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   689
                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
   690
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   691
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   692
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   693
            elif value.upper() in self.PouNames:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   694
                message = wx.MessageDialog(self, _("A pou with \"%s\" as name exists!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   695
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   696
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   697
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   698
            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
   699
                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
   700
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   701
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   702
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   703
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   704
                self.SaveValues(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   705
                old_value = self.Table.GetOldValue()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   706
                if old_value != "":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   707
                    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
   708
                self.Controler.BufferProject()
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   709
                self.ParentWindow.RefreshEditor(variablepanel = False)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   710
                self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCETREE, LIBRARYTREE)            
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   711
                event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   712
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   713
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   714
            if colname == "Class":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   715
                self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   716
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   717
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   718
    def OnVariablesGridEditorShown(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   719
        row, col = event.GetRow(), event.GetCol() 
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   720
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   721
        label_value = self.Table.GetColLabelValue(col)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   722
        if label_value == "Type":
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   723
            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
   724
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   725
            # 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
   726
            base_menu = wx.Menu(title='')
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   727
            for base_type in self.Controler.GetBaseTypes():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   728
                new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   729
                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
   730
                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
   731
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   732
            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
   733
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   734
            # 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
   735
            datatype_menu = wx.Menu(title='')
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   736
            datatypes = self.Controler.GetDataTypes(basetypes = False)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   737
            for datatype in datatypes:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   738
                new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   739
                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
   740
                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
   741
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   742
            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
   743
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   744
            # build a submenu containing function block types
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   745
            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   746
            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
   747
            classtype = self.Table.GetValueByName(row, "Class")
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   748
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   749
            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
   750
            poutype != "function" and bodytype in ["ST", "IL"]:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   751
                functionblock_menu = wx.Menu(title='')
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   752
                fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   753
                for functionblock_type in fbtypes:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   754
                    new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   755
                    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
   756
                    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
   757
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   758
                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
   759
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   760
            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
   761
            corner_x = rect.x + rect.width
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   762
            corner_y = rect.y + self.VariablesGrid.GetColLabelSize()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   763
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   764
            # pop up this new menu
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   765
            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
   766
            event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   767
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   768
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   769
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   770
    def GetVariableTypeFunction(self, base_type):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   771
        def VariableTypeFunction(event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   772
            row = self.VariablesGrid.GetGridCursorRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   773
            self.Table.SetValueByName(row, "Type", base_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   774
            self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   775
            self.SaveValues(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   776
            self.ParentWindow.RefreshEditor(variablepanel = False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   777
            self.Controler.BufferProject()
440
e183bffc05f0 Changes from bct merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 436
diff changeset
   778
            self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   779
        return VariableTypeFunction
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 OnVariablesGridCellLeftClick(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   782
        row = event.GetRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   783
        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
   784
            row = event.GetRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   785
            var_name = self.Table.GetValueByName(row, "Name")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   786
            var_class = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   787
            var_type = self.Table.GetValueByName(row, "Type")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   788
            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
   789
            dragSource = wx.DropSource(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   790
            dragSource.SetData(data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   791
            dragSource.DoDragDrop()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   792
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   793
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   794
    def OnVariablesGridSelectCell(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   795
        wx.CallAfter(self.RefreshButtons)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   796
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   797
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   798
    def OnChar(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   799
        keycode = event.GetKeyCode()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   800
        if keycode == wx.WXK_DELETE:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   801
            row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   802
            self.Values.remove(row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   803
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   804
            self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   805
            self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   806
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   807
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   808
    def MoveValue(self, value_index, move):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   809
        new_index = max(0, min(value_index + move, len(self.Values) - 1))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   810
        if new_index != value_index:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   811
            self.Values.insert(new_index, self.Values.pop(value_index))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   812
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   813
            self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   814
            self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   815
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   816
    def RefreshValues(self, select=0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   817
        if len(self.Table.data) > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   818
            self.VariablesGrid.SetGridCursor(0, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   819
        data = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   820
        for num, variable in enumerate(self.Values):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   821
            if variable["Class"] in self.ClassList:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   822
                variable["Number"] = num + 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   823
                data.append(variable)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   824
        self.Table.SetData(data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   825
        if len(self.Table.data) > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   826
            if select == -1:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   827
                select = len(self.Table.data) - 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   828
            self.VariablesGrid.SetGridCursor(select, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   829
            self.VariablesGrid.MakeCellVisible(select, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   830
        self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   831
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   832
    def SaveValues(self, buffer = True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   833
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   834
        if self.ElementType == "config":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   835
            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   836
        elif self.ElementType == "resource":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   837
            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
   838
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   839
            if self.ReturnType.IsEnabled():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   840
                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
   841
            self.Controler.SetPouInterfaceVars(words[1], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   842
        if buffer:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   843
            self.Controler.BufferProject()
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   844
            self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)            
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   845
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   846
    def AddVariableError(self, infos):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   847
        if isinstance(infos[0], TupleType):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   848
            for i in xrange(*infos[0]):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   849
                self.Table.AddError((i,) + infos[1:])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   850
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   851
            self.Table.AddError(infos)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   852
        self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   853
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   854
    def ClearErrors(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   855
        self.Table.ClearErrors()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   856
        self.Table.ResetView(self.VariablesGrid)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   857
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   858
class LocationCellControl(wx.PyControl):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   859
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   860
    def _init_coll_MainSizer_Items(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   861
        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
   862
        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
   863
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   864
    def _init_coll_MainSizer_Growables(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   865
        parent.AddGrowableCol(0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   866
        parent.AddGrowableRow(0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   867
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   868
    def _init_sizers(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   869
        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
   870
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   871
        self._init_coll_MainSizer_Items(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   872
        self._init_coll_MainSizer_Growables(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   873
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   874
        self.SetSizer(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   875
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   876
    def _init_ctrls(self, prnt):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   877
        wx.Control.__init__(self, id=-1, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   878
              name='LocationCellControl', parent=prnt,  
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   879
              size=wx.DefaultSize, style=0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   880
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   881
        # create location text control
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   882
        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
   883
              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
   884
        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
   885
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   886
        # create browse button
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   887
        self.BrowseButton = wx.Button(id=-1, label='...', 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   888
              name='staticText1', parent=self, pos=wx.Point(0, 0), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   889
              size=wx.Size(30, 0), style=0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   890
        self.BrowseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonClick)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   891
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   892
        self.Bind(wx.EVT_SIZE, self.OnSize)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   893
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   894
        self._init_sizers()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   895
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   896
    '''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   897
    Custom cell editor control with a text box and a button that launches
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   898
    the BrowseVariableLocationsDialog.
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   899
    '''
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   900
    def __init__(self, parent, locations):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   901
        self._init_ctrls(parent)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   902
        self.Locations = locations
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   903
        self.VarType = None
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   904
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   905
    def SetVarType(self, vartype):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   906
        self.VarType = vartype
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   907
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   908
    def SetValue(self, value):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   909
        self.Location.SetValue(value)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   910
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   911
    def GetValue(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   912
        return self.Location.GetValue()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   913
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   914
    def OnSize(self, event):
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   915
        self.Layout()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   916
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   917
    def OnBrowseButtonClick(self, event):
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   918
        # pop up the location browser dialog
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   919
        dialog = BrowseLocationsDialog(self, self.VarType, self.Locations)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   920
        if dialog.ShowModal() == wx.ID_OK:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   921
            infos = dialog.GetValues()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   922
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   923
            # set the location
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   924
            self.Location.SetValue(infos["location"])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   925
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   926
        dialog.Destroy()
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
        self.Location.SetFocus()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   929
443
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   930
    def OnLocationChar(self, event):
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   931
        keycode = event.GetKeyCode()
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   932
        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
   933
            self.Parent.Parent.ProcessEvent(event)
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   934
            self.Parent.Parent.SetFocus()
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   935
        else:
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   936
            event.Skip()
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   937
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   938
    def SetInsertionPoint(self, i):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   939
        self.Location.SetInsertionPoint(i)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   940
    
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   941
    def SetFocus(self):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   942
        self.Location.SetFocus()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   943
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   944
class LocationCellEditor(wx.grid.PyGridCellEditor):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   945
    '''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   946
    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
   947
    '''
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   948
    def __init__(self, table, controler):
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   949
        wx.grid.PyGridCellEditor.__init__(self)
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   950
        self.Table = table
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   951
        self.Controler = controler
443
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   952
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   953
    def __del__(self):
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   954
        self.CellControl = None
5f7d5d1a6f99 Add support for leaving LocationControl when RETURN or TAB pressed
laurent
parents: 440
diff changeset
   955
    
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   956
    def Create(self, parent, id, evt_handler):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   957
        locations = self.Controler.GetVariableLocationTree()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   958
        if len(locations) > 0:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   959
            self.CellControl = LocationCellControl(parent, locations)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   960
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   961
            self.CellControl = wx.TextCtrl(parent, -1)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   962
        self.SetControl(self.CellControl)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   963
        if evt_handler:
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   964
            self.CellControl.PushEventHandler(evt_handler)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   965
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   966
    def BeginEdit(self, row, col, grid):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   967
        self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   968
        if isinstance(self.CellControl, LocationCellControl):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   969
            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
   970
        self.CellControl.SetFocus()
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   971
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   972
    def EndEdit(self, row, col, grid):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   973
        loc = self.CellControl.GetValue()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   974
        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
   975
        if loc != old_loc:
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   976
            self.Table.SetValueByName(row, 'Location', loc)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   977
            return True
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   978
        return False
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   979
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   980
    def SetSize(self, rect):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   981
        self.CellControl.SetDimensions(rect.x + 1, rect.y,
431
c1c92d068ac5 Changes merged
'Laurent Bessard <laurent.bessard@lolitech.fr>'
parents: 427
diff changeset
   982
                                        rect.width, rect.height,
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   983
                                        wx.SIZE_ALLOW_MINUS_ONE)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   984
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   985
    def Clone(self):
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   986
        return LocationCellEditor(self.Table, self.Locations)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   987
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   988
def GetDirChoiceOptions():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   989
    _ = lambda x : x
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   990
    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
   991
            (_("Input"), [LOCATION_VAR_INPUT]), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   992
            (_("Output"), [LOCATION_VAR_OUTPUT]), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   993
            (_("Memory"), [LOCATION_VAR_MEMORY])]
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   994
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
   995
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   996
# turn LOCATIONDATATYPES inside-out
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   997
LOCATION_SIZES = {}
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   998
for size, types in LOCATIONDATATYPES.iteritems():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
   999
    for type in types:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1000
        LOCATION_SIZES[type] = size
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1001
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1002
[ID_BROWSELOCATIONSDIALOG, ID_BROWSELOCATIONSDIALOGLOCATIONSTREE, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1003
 ID_BROWSELOCATIONSDIALOGDIRCHOICE, ID_BROWSELOCATIONSDIALOGSTATICTEXT1, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1004
 ID_BROWSELOCATIONSDIALOGSTATICTEXT2, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1005
] = [wx.NewId() for _init_ctrls in range(5)]
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1006
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1007
class BrowseLocationsDialog(wx.Dialog):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1008
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1009
    if wx.VERSION < (2, 6, 0):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1010
        def Bind(self, event, function, id = None):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1011
            if id is not None:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1012
                event(self, id, function)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1013
            else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1014
                event(self, function)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1015
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1016
    def _init_coll_MainSizer_Items(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1017
        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
  1018
        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
  1019
        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
  1020
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1021
    def _init_coll_MainSizer_Growables(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1022
        parent.AddGrowableCol(0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1023
        parent.AddGrowableRow(1)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1024
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1025
    def _init_coll_ButtonGridSizer_Items(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1026
        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
  1027
        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
  1028
        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
  1029
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1030
    def _init_coll_ButtonGridSizer_Growables(self, parent):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1031
        parent.AddGrowableCol(2)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1032
        parent.AddGrowableRow(0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1033
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1034
    def _init_sizers(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1035
        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
  1036
        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
  1037
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1038
        self._init_coll_MainSizer_Items(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1039
        self._init_coll_MainSizer_Growables(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1040
        self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1041
        self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1042
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1043
        self.SetSizer(self.MainSizer)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1044
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1045
    def _init_ctrls(self, prnt):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1046
        wx.Dialog.__init__(self, id=ID_BROWSELOCATIONSDIALOG, 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1047
              name='BrowseLocationsDialog', parent=prnt,  
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1048
              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
  1049
              title=_('Browse Locations'))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1050
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1051
        self.staticText1 = wx.StaticText(id=ID_BROWSELOCATIONSDIALOGSTATICTEXT1,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1052
              label=_('Locations available:'), name='staticText1', parent=self,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1053
              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
  1054
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1055
        if wx.Platform == '__WXMSW__':
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1056
            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
  1057
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1058
            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
  1059
        self.LocationsTree = wx.TreeCtrl(id=ID_BROWSELOCATIONSDIALOGLOCATIONSTREE,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1060
              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
  1061
              size=wx.Size(0, 0), style=treestyle)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1062
        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
  1063
                  id=ID_BROWSELOCATIONSDIALOGLOCATIONSTREE)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1064
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1065
        self.staticText2 = wx.StaticText(id=ID_BROWSELOCATIONSDIALOGSTATICTEXT2,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1066
              label=_('Direction:'), name='staticText2', parent=self,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1067
              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
  1068
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1069
        self.DirChoice = wx.ComboBox(id=ID_BROWSELOCATIONSDIALOGDIRCHOICE,
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1070
              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
  1071
              size=wx.DefaultSize, style=wx.CB_READONLY)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1072
        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
  1073
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1074
        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
  1075
        if wx.VERSION >= (2, 5, 0):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1076
            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
  1077
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1078
            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
  1079
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1080
        self._init_sizers()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1081
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1082
    def __init__(self, parent, var_type, locations):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1083
        self._init_ctrls(parent)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1084
        self.VarType = var_type
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1085
        self.Locations = locations
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1086
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1087
        # Define Tree item icon list
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1088
        self.TreeImageList = wx.ImageList(16, 16)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1089
        self.TreeImageDict = {}
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1090
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1091
        # Icons for items
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1092
        for imgname, itemtype in [
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1093
            ("CONFIGURATION", LOCATION_PLUGIN), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1094
            ("RESOURCE",      LOCATION_MODULE), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1095
            ("PROGRAM",       LOCATION_GROUP), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1096
            ("VAR_INPUT",     LOCATION_VAR_INPUT), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1097
            ("VAR_OUTPUT",    LOCATION_VAR_OUTPUT), 
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1098
            ("VAR_LOCAL",     LOCATION_VAR_MEMORY)]:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1099
            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
  1100
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1101
        # Assign icon list to TreeCtrls
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1102
        self.LocationsTree.SetImageList(self.TreeImageList)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1103
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1104
        # Set a options for the choice
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1105
        for option, filter in GetDirChoiceOptions():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1106
            self.DirChoice.Append(_(option))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1107
        self.DirChoice.SetStringSelection(_("All"))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1108
        self.RefreshFilter()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1109
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1110
        self.RefreshLocationsTree()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1111
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1112
    def RefreshFilter(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1113
        self.Filter = DIRCHOICE_OPTIONS_FILTER[self.DirChoice.GetStringSelection()]
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
    def RefreshLocationsTree(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1116
        root = self.LocationsTree.GetRootItem()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1117
        if not root.IsOk():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1118
            if wx.Platform == '__WXMSW__':
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1119
                root = self.LocationsTree.AddRoot(_('Plugins'))
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1120
            else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1121
                root = self.LocationsTree.AddRoot("")
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1122
        self.GenerateLocationsTreeBranch(root, self.Locations)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1123
        self.LocationsTree.Expand(root)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1124
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1125
    def GenerateLocationsTreeBranch(self, root, locations):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1126
        to_delete = []
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1127
        if wx.VERSION >= (2, 6, 0):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1128
            item, root_cookie = self.LocationsTree.GetFirstChild(root)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1129
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1130
            item, root_cookie = self.LocationsTree.GetFirstChild(root, 0)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1131
        for loc_infos in locations:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1132
            infos = loc_infos.copy()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1133
            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
  1134
               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
  1135
               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
  1136
                children = [child for child in infos.pop("children")]
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1137
                if not item.IsOk():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1138
                    item = self.LocationsTree.AppendItem(root, infos["name"])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1139
                    if wx.Platform != '__WXMSW__':
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1140
                        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
  1141
                else:
436
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1142
                    self.LocationsTree.SetItemText(item, infos["name"])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1143
                self.LocationsTree.SetPyData(item, infos)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1144
                self.LocationsTree.SetItemImage(item, self.TreeImageDict[infos["type"]])
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1145
                self.GenerateLocationsTreeBranch(item, children)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1146
                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
  1147
        while item.IsOk():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1148
            to_delete.append(item)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1149
            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
  1150
        for item in to_delete:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1151
            self.LocationsTree.Delete(item)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1152
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1153
    def OnLocationsTreeItemActivated(self, event):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1154
        infos = self.LocationsTree.GetPyData(event.GetItem())
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1155
        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
  1156
            wx.CallAfter(self.EndModal, wx.ID_OK)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1157
        event.Skip()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1158
    
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1159
    def OnDirChoice(self, event):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1160
        self.RefreshFilter()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1161
        self.RefreshLocationsTree()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1162
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1163
    def GetValues(self):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1164
        selected = self.LocationsTree.GetSelection()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1165
        return self.LocationsTree.GetPyData(selected)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1166
        
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1167
    def OnOK(self, event):
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1168
        selected = self.LocationsTree.GetSelection()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1169
        var_infos = None
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1170
        if selected.IsOk():
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1171
            var_infos = self.LocationsTree.GetPyData(selected)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1172
        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
  1173
            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
  1174
            message.ShowModal()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1175
            message.Destroy()
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1176
        else:
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1177
            self.EndModal(wx.ID_OK)
f3bb091f803f Fix BrowseVariableDialog to be used in PLCOpenEditor without Beremiz plugins
laurent
parents: 431
diff changeset
  1178