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