VariablePanel.py
author b.taylor@willowglen.ca
Wed, 02 Sep 2009 12:39:52 -0600
changeset 418 a06221a0930b
child 419 8f97ed01a6a6
permissions -rw-r--r--
split the variable editor panel into its own file
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
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    24
import wx, wx.grid
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    25
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    26
from PLCOpenEditor import AppendMenu
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    27
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    28
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    29
#-------------------------------------------------------------------------------
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    30
#                            Variables Editor Panel
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    31
#-------------------------------------------------------------------------------
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    32
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    33
def GetVariableTableColnames(location):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    34
    _ = lambda x : x
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    35
    if location:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    36
    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant")]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    37
    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant")]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    38
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    39
def GetAlternativeOptions():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    40
    _ = lambda x : x
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    41
    return [_("Yes"), _("No")]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    42
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
    43
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    44
def GetFilterChoiceTransfer():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    45
    _ = lambda x : x
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    46
    return {_("All"): _("All"), _("Interface"): _("Interface"), 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    47
            _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"), 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    48
            _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    49
            _("   Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    50
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
    51
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    52
class VariableTable(wx.grid.PyGridTableBase):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    53
    
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
    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
    56
    """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    57
    def __init__(self, parent, data, colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    58
        # The base class must be initialized *first*
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    59
        wx.grid.PyGridTableBase.__init__(self)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    60
        self.data = data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    61
        self.old_value = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    62
        self.colnames = colnames
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    63
        self.Errors = {}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    64
        self.Parent = parent
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    65
        # XXX
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    66
        # 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
    67
        # see if the table has changed size
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    68
        self._rows = self.GetNumberRows()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    69
        self._cols = self.GetNumberCols()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    70
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    71
    def GetNumberCols(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    72
        return len(self.colnames)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    73
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    74
    def GetNumberRows(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    75
        return len(self.data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    76
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    77
    def GetColLabelValue(self, col, translate=True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    78
        if col < len(self.colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    79
            if translate:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    80
                return _(self.colnames[col])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    81
            return self.colnames[col]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    82
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    83
    def GetRowLabelValues(self, row, translate=True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    84
        return row
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    85
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    86
    def GetValue(self, row, col):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    87
        if row < self.GetNumberRows():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    88
            if col == 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    89
                return self.data[row]["Number"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    90
            colname = self.GetColLabelValue(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    91
            value = str(self.data[row].get(colname, ""))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    92
            if colname in ["Class", "Retain", "Constant"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    93
                return _(value)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    94
            return value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    95
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    96
    def SetValue(self, row, col, value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    97
        if col < len(self.colnames):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    98
            colname = self.GetColLabelValue(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    99
            if colname == "Name":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   100
                self.old_value = self.data[row][colname]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   101
            elif colname == "Class":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   102
                value = VARIABLE_CLASSES_DICT[value]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   103
            elif colname in ["Retain", "Constant"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   104
                value = ALTERNATIVE_OPTIONS_DICT[value]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   105
            self.data[row][colname] = value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   106
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   107
    def GetValueByName(self, row, colname):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   108
        if row < self.GetNumberRows():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   109
            return self.data[row].get(colname)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   110
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   111
    def SetValueByName(self, row, colname, value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   112
        if row < self.GetNumberRows():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   113
            self.data[row][colname] = value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   114
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   115
    def GetOldValue(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   116
        return self.old_value
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   117
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   118
    def ResetView(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   119
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   120
        (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
   121
        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
   122
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   123
        grid.BeginBatch()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   124
        for current, new, delmsg, addmsg in [
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   125
            (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
   126
            (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
   127
        ]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   128
            if new < current:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   129
                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
   130
                grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   131
            elif new > current:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   132
                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
   133
                grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   134
                self.UpdateValues(grid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   135
        grid.EndBatch()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   136
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   137
        self._rows = self.GetNumberRows()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   138
        self._cols = self.GetNumberCols()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   139
        # update the column rendering scheme
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   140
        self._updateColAttrs(grid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   141
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   142
        # 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
   143
        grid.AdjustScrollbars()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   144
        grid.ForceRefresh()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   145
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   146
    def UpdateValues(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   147
        """Update all displayed values"""
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   148
        # 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
   149
        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
   150
        grid.ProcessTableMessage(msg)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   151
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   152
    def _updateColAttrs(self, grid):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   153
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   154
        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
   155
        appropriate renderer given the column name.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   156
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   157
        Otherwise default to the default renderer.
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   158
        """
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   159
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   160
        for row in range(self.GetNumberRows()):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   161
            for col in range(self.GetNumberCols()):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   162
                editor = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   163
                renderer = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   164
                colname = self.GetColLabelValue(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   165
                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
   166
                    grid.SetReadOnly(row, col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   167
                    if colname == "Name":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   168
                        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
   169
                            grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   170
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   171
                            editor = wx.grid.GridCellTextEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   172
                            renderer = wx.grid.GridCellStringRenderer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   173
                    elif colname == "Initial Value":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   174
                        editor = wx.grid.GridCellTextEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   175
                        renderer = wx.grid.GridCellStringRenderer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   176
                    elif colname == "Location":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   177
                        if self.GetValueByName(row, "Class") in ["Local", "Global"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   178
                            editor = wx.grid.GridCellTextEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   179
                            renderer = wx.grid.GridCellStringRenderer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   180
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   181
                            grid.SetReadOnly(row, col, True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   182
                    elif colname == "Class":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   183
                        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
   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.GridCellChoiceEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   187
                            excluded = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   188
                            if self.Parent.PouIsUsed:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   189
                                excluded.extend(["Input","Output","InOut"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   190
                            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
   191
                                excluded.extend(["Local","Temp"])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   192
                            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
   193
                    elif colname in ["Retain", "Constant"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   194
                        editor = wx.grid.GridCellChoiceEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   195
                        editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   196
                    elif colname == "Type":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   197
                        editor = wx.grid.GridCellTextEditor()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   198
                else:
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
                
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   201
                grid.SetCellEditor(row, col, editor)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   202
                grid.SetCellRenderer(row, col, renderer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   203
                
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   204
                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
   205
                    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
   206
                    grid.SetCellTextColour(row, col, wx.RED)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   207
                    grid.MakeCellVisible(row, col)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   208
                else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   209
                    grid.SetCellTextColour(row, col, wx.BLACK)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   210
                    grid.SetCellBackgroundColour(row, col, wx.WHITE)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   211
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   212
    def SetData(self, data):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   213
        self.data = data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   214
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   215
    def GetData(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   216
        return self.data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   217
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   218
    def GetCurrentIndex(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   219
        return self.CurrentIndex
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   220
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   221
    def SetCurrentIndex(self, index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   222
        self.CurrentIndex = index
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   223
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   224
    def AppendRow(self, row_content):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   225
        self.data.append(row_content)
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 RemoveRow(self, row_index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   228
        self.data.pop(row_index)
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 GetRow(self, row_index):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   231
        return self.data[row_index]
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 Empty(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   234
        self.data = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   235
        self.editors = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   236
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   237
    def AddError(self, infos):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   238
        self.Errors[infos[0]] = infos[1:]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   239
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   240
    def ClearErrors(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   241
        self.Errors = {}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   242
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   243
class VariableDropTarget(wx.TextDropTarget):
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 __init__(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   246
        wx.TextDropTarget.__init__(self)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   247
        self.ParentWindow = parent
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   248
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   249
    def OnDropText(self, x, y, data):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   250
        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
   251
        col = self.ParentWindow.VariablesGrid.XToCol(x)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   252
        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
   253
        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
   254
            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
   255
                return
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   256
            message = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   257
            if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   258
                message = _("Can't affect a location to a function block instance")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   259
            elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   260
                message = _("Can affect a location only to local or global variables")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   261
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   262
                try:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   263
                    values = eval(data)    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   264
                except:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   265
                    message = _("Invalid value \"%s\" for location")%data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   266
                    values = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   267
                if not isinstance(values, TupleType):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   268
                    message = _("Invalid value \"%s\" for location")%data
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   269
                    values = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   270
                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
   271
                    location = values[0]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   272
                    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
   273
                    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
   274
                    message = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   275
                    if location.startswith("%"):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   276
                        if base_type != values[2]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   277
                            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
   278
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   279
                            self.ParentWindow.Table.SetValue(row, col, location)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   280
                            self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   281
                            self.ParentWindow.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   282
                    else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   283
                        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
   284
                            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
   285
                        elif location[0] not in LOCATIONDATATYPES:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   286
                            message = _("Unrecognized data size \"%s\"")%location[0]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   287
                        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
   288
                            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
   289
                        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   290
                            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
   291
                            if dialog.ShowModal() == wx.ID_OK:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   292
                                selected = dialog.GetSelection()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   293
                                if selected == 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   294
                                    location = "%I" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   295
                                elif selected == 1:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   296
                                    location = "%Q" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   297
                                else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   298
                                    location = "%M" + location
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   299
                                self.ParentWindow.Table.SetValue(row, col, location)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   300
                                self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   301
                                self.ParentWindow.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   302
                            dialog.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   303
            if message is not None:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   304
                wx.CallAfter(self.ShowMessage, message)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   305
            
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   306
    def ShowMessage(self, message):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   307
        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
   308
        message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   309
        message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   310
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   311
[ID_VARIABLEEDITORPANEL, ID_VARIABLEEDITORPANELVARIABLESGRID, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   312
 ID_VARIABLEEDITORCONTROLPANEL, ID_VARIABLEEDITORPANELRETURNTYPE, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   313
 ID_VARIABLEEDITORPANELCLASSFILTER, ID_VARIABLEEDITORPANELADDBUTTON, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   314
 ID_VARIABLEEDITORPANELDELETEBUTTON, ID_VARIABLEEDITORPANELUPBUTTON, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   315
 ID_VARIABLEEDITORPANELDOWNBUTTON, ID_VARIABLEEDITORPANELSTATICTEXT1, 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   316
 ID_VARIABLEEDITORPANELSTATICTEXT2, ID_VARIABLEEDITORPANELSTATICTEXT3,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   317
] = [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
   318
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   319
class VariablePanel(wx.Panel):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   320
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   321
    if wx.VERSION < (2, 6, 0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   322
        def Bind(self, event, function, id = None):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   323
            if id is not None:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   324
                event(self, id, function)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   325
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   326
                event(self, function)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   327
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   328
    def _init_coll_MainSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   329
        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
   330
        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
   331
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   332
    def _init_coll_MainSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   333
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   334
        parent.AddGrowableRow(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   335
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   336
    def _init_coll_ControlPanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   337
        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
   338
        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
   339
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   340
    def _init_coll_ControlPanelSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   341
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   342
        parent.AddGrowableRow(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   343
        parent.AddGrowableRow(1)
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
    def _init_coll_ChoicePanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   346
        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
   347
        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
   348
        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
   349
        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
   350
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   351
    def _init_coll_ButtonPanelSizer_Items(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   352
        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
   353
        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
   354
        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
   355
        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
   356
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   357
    def _init_coll_ButtonPanelSizer_Growables(self, parent):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   358
        parent.AddGrowableCol(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   359
        parent.AddGrowableCol(1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   360
        parent.AddGrowableCol(2)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   361
        parent.AddGrowableCol(3)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   362
        parent.AddGrowableRow(0)
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_sizers(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   365
        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
   366
        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
   367
        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
   368
        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
   369
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   370
        self._init_coll_MainSizer_Items(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   371
        self._init_coll_MainSizer_Growables(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   372
        self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   373
        self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   374
        self._init_coll_ChoicePanelSizer_Items(self.ChoicePanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   375
        self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   376
        self._init_coll_ButtonPanelSizer_Growables(self.ButtonPanelSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   377
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   378
        self.SetSizer(self.MainSizer)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   379
        self.ControlPanel.SetSizer(self.ControlPanelSizer)
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_ctrls(self, prnt):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   382
        wx.Panel.__init__(self, id=ID_VARIABLEEDITORPANEL,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   383
              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
   384
              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
   385
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   386
        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
   387
              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
   388
              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
   389
        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
   390
              'Sans'))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   391
        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
   392
              False, 'Sans'))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   393
        self.VariablesGrid.SetSelectionBackground(wx.WHITE)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   394
        self.VariablesGrid.SetSelectionForeground(wx.BLACK)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   395
        if wx.VERSION >= (2, 6, 0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   396
            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
   397
            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
   398
            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
   399
            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
   400
            #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
   401
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   402
            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
   403
            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
   404
            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
   405
            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
   406
            #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
   407
        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   408
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   409
        self.ControlPanel = wx.ScrolledWindow(id=ID_VARIABLEEDITORCONTROLPANEL,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   410
              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
   411
              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
   412
        self.ControlPanel.SetScrollRate(0, 10)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   413
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   414
        self.staticText1 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT1,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   415
              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
   416
              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
   417
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   418
        self.ReturnType = wx.ComboBox(id=ID_VARIABLEEDITORPANELRETURNTYPE,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   419
              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
   420
              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
   421
        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
   422
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   423
        self.staticText2 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT2,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   424
              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
   425
              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
   426
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   427
        self.ClassFilter = wx.ComboBox(id=ID_VARIABLEEDITORPANELCLASSFILTER,
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   428
              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
   429
              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
   430
        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
   431
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   432
        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
   433
              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
   434
              size=wx.DefaultSize, style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   435
        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
   436
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   437
        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
   438
              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
   439
              size=wx.DefaultSize, style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   440
        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
   441
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   442
        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
   443
              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
   444
              size=wx.Size(32, 32), style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   445
        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
   446
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   447
        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
   448
              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
   449
              size=wx.Size(32, 32), style=0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   450
        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
   451
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   452
        self._init_sizers()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   453
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   454
    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
   455
        self._init_ctrls(parent)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   456
        self.ParentWindow = window
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   457
        self.Controler = controler
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   458
        self.ElementType = element_type
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   459
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   460
        self.Filter = "All"
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   461
        self.FilterChoices = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   462
        self.FilterChoiceTransfer = GetFilterChoiceTransfer()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   463
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   464
        if element_type in ["config", "resource"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   465
            self.DefaultTypes = {"All" : "Global"}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   466
            self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   467
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   468
            self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   469
            self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   470
        if element_type in ["config", "resource"] or element_type in ["program", "transition", "action"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   471
            self.Table = VariableTable(self, [], GetVariableTableColnames(True))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   472
            if element_type not in ["config", "resource"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   473
                self.FilterChoices = ["All", "Interface", "   Input", "   Output", "   InOut", "   External", "Variables", "   Local", "   Temp"]#,"Access"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   474
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   475
                self.FilterChoices = ["All", "Global"]#,"Access"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   476
            self.ColSizes = [40, 80, 70, 80, 80, 80, 60, 70]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   477
            self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   478
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   479
            self.Table = VariableTable(self, [], GetVariableTableColnames(False))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   480
            if element_type == "function":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   481
                self.FilterChoices = ["All", "Interface", "   Input", "   Output", "   InOut", "Variables", "   Local", "   Temp"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   482
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   483
                self.FilterChoices = ["All", "Interface", "   Input", "   Output", "   InOut", "   External", "Variables", "   Local", "   Temp"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   484
            self.ColSizes = [40, 120, 70, 80, 120, 60, 70]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   485
            self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   486
        for choice in self.FilterChoices:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   487
            self.ClassFilter.Append(_(choice))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   488
        reverse_transfer = {}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   489
        for filter, choice in self.FilterChoiceTransfer.items():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   490
            reverse_transfer[choice] = filter
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   491
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   492
        self.RefreshTypeList()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   493
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   494
        self.OptionList = GetAlternativeOptions()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   495
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   496
        if element_type == "function":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   497
            for base_type in self.Controler.GetBaseTypes():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   498
                self.ReturnType.Append(base_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   499
            self.ReturnType.Enable(True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   500
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   501
            self.ReturnType.Enable(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   502
            self.staticText1.Hide()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   503
            self.ReturnType.Hide()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   504
            
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   505
        self.VariablesGrid.SetTable(self.Table)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   506
        self.VariablesGrid.SetRowLabelSize(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   507
        for col in range(self.Table.GetNumberCols()):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   508
            attr = wx.grid.GridCellAttr()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   509
            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
   510
            self.VariablesGrid.SetColAttr(col, attr)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   511
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   512
            self.VariablesGrid.AutoSizeColumn(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   513
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   514
    def SetTagName(self, tagname):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   515
        self.TagName = tagname
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   516
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   517
    def IsFunctionBlockType(self, name):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   518
        bodytype = self.Controler.GetEditedElementBodyType(self.TagName, self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   519
        pouname, poutype = self.Controler.GetEditedElementType(self.TagName, self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   520
        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
   521
            return False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   522
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   523
            return name in self.Controler.GetFunctionBlockTypes(self.TagName, self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   524
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   525
    def RefreshView(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   526
        self.PouNames = self.Controler.GetProjectPouNames(self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   527
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   528
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   529
        if self.ElementType == "config":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   530
            self.PouIsUsed = False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   531
            returnType = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   532
            self.Values = self.Controler.GetConfigurationGlobalVars(words[1], self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   533
        elif self.ElementType == "resource":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   534
            self.PouIsUsed = False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   535
            returnType = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   536
            self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2], self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   537
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   538
            self.PouIsUsed = self.Controler.PouIsUsed(words[1], self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   539
            returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   540
            self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   541
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   542
        if returnType and self.ReturnType.IsEnabled():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   543
            self.ReturnType.SetStringSelection(returnType)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   544
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   545
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   546
        self.RefreshButtons()
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
    def OnReturnTypeChanged(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   549
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   550
        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
   551
        self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   552
        self.ParentWindow.RefreshEditor(variablepanel = False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   553
        self.ParentWindow.RefreshTitle()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   554
        self.ParentWindow.RefreshEditMenu()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   555
        self.ParentWindow.RefreshInstancesTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   556
        self.ParentWindow.RefreshLibraryTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   557
        event.Skip()
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
    def OnClassFilter(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   560
        self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   561
        self.RefreshTypeList()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   562
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   563
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   564
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   565
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   566
    def RefreshTypeList(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   567
        if self.Filter == "All":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   568
            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
   569
        elif self.Filter == "Interface":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   570
            self.ClassList = ["Input","Output","InOut","External"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   571
        elif self.Filter == "Variables":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   572
            self.ClassList = ["Local","Temp"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   573
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   574
            self.ClassList = [self.Filter]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   575
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   576
    def RefreshButtons(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   577
        if getattr(self, "Table", None):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   578
            table_length = len(self.Table.data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   579
            row_class = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   580
            row_edit = True
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   581
            if table_length > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   582
                row = self.VariablesGrid.GetGridCursorRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   583
                row_edit = self.Table.GetValueByName(row, "Edit")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   584
                if self.PouIsUsed:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   585
                    row_class = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   586
            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
   587
            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
   588
            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
   589
            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
   590
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   591
    def OnAddButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   592
        new_row = self.DefaultValue.copy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   593
        if self.Filter in self.DefaultTypes:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   594
            new_row["Class"] = self.DefaultTypes[self.Filter]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   595
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   596
            new_row["Class"] = self.Filter
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   597
        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
   598
            row_index = self.VariablesGrid.GetGridCursorRow() + 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   599
            self.Values.insert(row_index, new_row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   600
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   601
            row_index = -1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   602
            self.Values.append(new_row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   603
        self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   604
        self.RefreshValues(row_index)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   605
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   606
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   607
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   608
    def OnDeleteButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   609
        row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   610
        self.Values.remove(row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   611
        self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   612
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   613
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   614
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   615
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   616
    def OnUpButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   617
        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   618
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   619
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   620
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   621
    def OnDownButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   622
        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   623
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   624
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   625
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   626
    def OnVariablesGridCellChange(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   627
        row, col = event.GetRow(), event.GetCol()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   628
        colname = self.Table.GetColLabelValue(col)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   629
        value = self.Table.GetValue(row, col)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   630
        if colname == "Name" and value != "":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   631
            if not TestIdentifier(value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   632
                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
   633
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   634
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   635
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   636
            elif value.upper() in IEC_KEYWORDS:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   637
                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
   638
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   639
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   640
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   641
            elif value.upper() in self.PouNames:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   642
                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
   643
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   644
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   645
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   646
            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
   647
                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
   648
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   649
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   650
                event.Veto()
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
                self.SaveValues(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   653
                old_value = self.Table.GetOldValue()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   654
                if old_value != "":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   655
                    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
   656
                self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   657
                self.ParentWindow.RefreshEditor(variablepanel = False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   658
                self.ParentWindow.RefreshTitle()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   659
                self.ParentWindow.RefreshEditMenu()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   660
                self.ParentWindow.RefreshInstancesTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   661
                self.ParentWindow.RefreshLibraryTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   662
                event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   663
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   664
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   665
            if colname == "Class":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   666
                self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   667
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   668
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   669
    def OnVariablesGridEditorShown(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   670
        row, col = event.GetRow(), event.GetCol() 
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   671
        classtype = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   672
        if self.Table.GetColLabelValue(col) == "Type":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   673
            type_menu = wx.Menu(title='')
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   674
            base_menu = wx.Menu(title='')
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   675
            for base_type in self.Controler.GetBaseTypes():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   676
                new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   677
                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
   678
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   679
            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   680
            datatype_menu = wx.Menu(title='')
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   681
            for datatype in self.Controler.GetDataTypes(basetypes = False, debug = self.ParentWindow.Debug):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   682
                new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   683
                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
   684
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   685
            type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   686
            functionblock_menu = wx.Menu(title='')
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   687
            bodytype = self.Controler.GetEditedElementBodyType(self.TagName, self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   688
            pouname, poutype = self.Controler.GetEditedElementType(self.TagName, self.ParentWindow.Debug)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   689
            if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   690
                for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName, self.ParentWindow.Debug):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   691
                    new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   692
                    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
   693
                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   694
                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   695
            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   696
            self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
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
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   699
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   700
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   701
    def GetVariableTypeFunction(self, base_type):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   702
        def VariableTypeFunction(event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   703
            row = self.VariablesGrid.GetGridCursorRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   704
            self.Table.SetValueByName(row, "Type", base_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   705
            self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   706
            self.SaveValues(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   707
            self.ParentWindow.RefreshEditor(variablepanel = False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   708
            self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   709
            self.ParentWindow.RefreshTitle()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   710
            self.ParentWindow.RefreshEditMenu()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   711
            self.ParentWindow.RefreshInstancesTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   712
            self.ParentWindow.RefreshLibraryTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   713
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   714
        return VariableTypeFunction
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   715
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   716
    def OnVariablesGridCellLeftClick(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   717
        row = event.GetRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   718
        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
   719
            row = event.GetRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   720
            var_name = self.Table.GetValueByName(row, "Name")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   721
            var_class = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   722
            var_type = self.Table.GetValueByName(row, "Type")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   723
            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
   724
            dragSource = wx.DropSource(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   725
            dragSource.SetData(data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   726
            dragSource.DoDragDrop()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   727
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   728
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   729
    def OnVariablesGridSelectCell(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   730
        wx.CallAfter(self.RefreshButtons)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   731
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   732
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   733
    def OnChar(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   734
        keycode = event.GetKeyCode()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   735
        if keycode == wx.WXK_DELETE:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   736
            row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   737
            self.Values.remove(row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   738
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   739
            self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   740
            self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   741
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   742
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   743
    def MoveValue(self, value_index, move):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   744
        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
   745
        if new_index != value_index:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   746
            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
   747
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   748
            self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   749
            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
   750
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   751
    def RefreshValues(self, select=0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   752
        if len(self.Table.data) > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   753
            self.VariablesGrid.SetGridCursor(0, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   754
        data = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   755
        for num, variable in enumerate(self.Values):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   756
            if variable["Class"] in self.ClassList:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   757
                variable["Number"] = num + 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   758
                data.append(variable)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   759
        self.Table.SetData(data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   760
        if len(self.Table.data) > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   761
            if select == -1:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   762
                select = len(self.Table.data) - 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   763
            self.VariablesGrid.SetGridCursor(select, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   764
            self.VariablesGrid.MakeCellVisible(select, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   765
        self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   766
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   767
    def SaveValues(self, buffer = True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   768
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   769
        if self.ElementType == "config":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   770
            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   771
        elif self.ElementType == "resource":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   772
            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
   773
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   774
            if self.ReturnType.IsEnabled():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   775
                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
   776
            self.Controler.SetPouInterfaceVars(words[1], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   777
        if buffer:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   778
            self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   779
            self.ParentWindow.RefreshTitle()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   780
            self.ParentWindow.RefreshEditMenu()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   781
            self.ParentWindow.RefreshInstancesTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   782
            self.ParentWindow.RefreshLibraryTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   783
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   784
    def AddVariableError(self, infos):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   785
        if isinstance(infos[0], TupleType):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   786
            for i in xrange(*infos[0]):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   787
                self.Table.AddError((i,) + infos[1:])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   788
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   789
            self.Table.AddError(infos)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   790
        self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   791
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   792
    def ClearErrors(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   793
        self.Table.ClearErrors()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   794
        self.Table.ResetView(self.VariablesGrid)