VariablePanel.py
author b.taylor@willowglen.ca
Thu, 17 Sep 2009 14:17:52 -0600
changeset 427 22d16c457d87
parent 425 dbc4a66190a6
child 431 c1c92d068ac5
permissions -rw-r--r--
improved English spelling & grammar
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:
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
    38
    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
    39
    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
    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"]:
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   180
                            editor = LocationCellEditor(self.Parent)
418
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"):
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 425
diff changeset
   269
                message = _("Can't give a location to a function block instance")
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   270
            elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 425
diff changeset
   271
                message = _("Can only give a location to local or global variables")
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   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
        
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   475
        self.DefaultValue = {   "Name" : "", "Class" : "", "Type" : "INT", "Location" : "",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   476
                                "Initial Value" : "", "Retain" : "No", "Constant" : "No",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   477
                                "Documentation" : "", "Edit" : True
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   478
                            }
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   479
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   480
        if element_type in ["config", "resource"]:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   481
            self.DefaultTypes = {"All" : "Global"}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   482
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   483
            self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   484
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   485
        if element_type in ["config", "resource"] \
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   486
        or element_type in ["program", "transition", "action"]:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   487
            # this is an element that can have located variables
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   488
            self.Table = VariableTable(self, [], GetVariableTableColnames(True))
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   489
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   490
            if element_type in ["config", "resource"]:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   491
                self.FilterChoices = ["All", "Global"]#,"Access"]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   492
            else:
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   493
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   494
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   495
                                        "Variables", "   Local", "   Temp"]#,"Access"]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   496
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   497
            # these condense the ColAlignements list
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   498
            l = wx.ALIGN_LEFT
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   499
            c = wx.ALIGN_CENTER 
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   500
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   501
            #                      Num  Name    Class   Type    Loc     Init    Retain  Const   Doc
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   502
            self.ColSizes       = [40,  80,     70,     80,     80,     80,     60,     70,     80]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   503
            self.ColAlignements = [c,   l,      l,      l,      l,      l,      c,      c,      l]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   504
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   505
        else:
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   506
            # this is an element that cannot have located variables
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   507
            self.Table = VariableTable(self, [], GetVariableTableColnames(False))
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   508
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   509
            if element_type == "function":
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   510
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   511
                                        "Interface", "   Input", "   Output", "   InOut",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   512
                                        "Variables", "   Local", "   Temp"]
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   513
            else:
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   514
                self.FilterChoices = ["All",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   515
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   516
                                        "Variables", "   Local", "   Temp"]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   517
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   518
            # these condense the ColAlignements list
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   519
            l = wx.ALIGN_LEFT
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   520
            c = wx.ALIGN_CENTER 
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   521
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   522
            #                      Num  Name    Class   Type    Init    Retain  Const   Doc
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   523
            self.ColSizes       = [40,  80,     70,     80,     80,     60,     70,     160]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   524
            self.ColAlignements = [c,   l,      l,      l,      l,      c,      c,      l]
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   525
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   526
        for choice in self.FilterChoices:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   527
            self.ClassFilter.Append(_(choice))
424
d19c4a6460ab add a Documentation column to the VariablePanel
b.taylor@willowglen.ca
parents: 422
diff changeset
   528
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   529
        reverse_transfer = {}
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   530
        for filter, choice in self.FilterChoiceTransfer.items():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   531
            reverse_transfer[choice] = filter
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   532
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   533
        self.RefreshTypeList()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   534
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   535
        self.OptionList = GetAlternativeOptions()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   536
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   537
        if element_type == "function":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   538
            for base_type in self.Controler.GetBaseTypes():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   539
                self.ReturnType.Append(base_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   540
            self.ReturnType.Enable(True)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   541
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   542
            self.ReturnType.Enable(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   543
            self.staticText1.Hide()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   544
            self.ReturnType.Hide()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   545
            
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   546
        self.VariablesGrid.SetTable(self.Table)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   547
        self.VariablesGrid.SetRowLabelSize(0)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   548
        for col in range(self.Table.GetNumberCols()):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   549
            attr = wx.grid.GridCellAttr()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   550
            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
   551
            self.VariablesGrid.SetColAttr(col, attr)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   552
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   553
            self.VariablesGrid.AutoSizeColumn(col, False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   554
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   555
    def SetTagName(self, tagname):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   556
        self.TagName = tagname
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   557
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   558
    def IsFunctionBlockType(self, name):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   559
        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
   560
        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
   561
        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
   562
            return False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   563
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   564
            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
   565
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   566
    def RefreshView(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   567
        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
   568
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   569
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   570
        if self.ElementType == "config":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   571
            self.PouIsUsed = False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   572
            returnType = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   573
            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
   574
        elif self.ElementType == "resource":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   575
            self.PouIsUsed = False
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   576
            returnType = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   577
            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
   578
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   579
            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
   580
            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
   581
            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
   582
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   583
        if returnType and self.ReturnType.IsEnabled():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   584
            self.ReturnType.SetStringSelection(returnType)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   585
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   586
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   587
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   588
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   589
    def OnReturnTypeChanged(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   590
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   591
        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
   592
        self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   593
        self.ParentWindow.RefreshEditor(variablepanel = False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   594
        self.ParentWindow.RefreshTitle()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   595
        self.ParentWindow.RefreshEditMenu()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   596
        self.ParentWindow.RefreshInstancesTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   597
        self.ParentWindow.RefreshLibraryTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   598
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   599
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   600
    def OnClassFilter(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   601
        self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   602
        self.RefreshTypeList()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   603
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   604
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   605
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   606
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   607
    def RefreshTypeList(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   608
        if self.Filter == "All":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   609
            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
   610
        elif self.Filter == "Interface":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   611
            self.ClassList = ["Input","Output","InOut","External"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   612
        elif self.Filter == "Variables":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   613
            self.ClassList = ["Local","Temp"]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   614
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   615
            self.ClassList = [self.Filter]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   616
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   617
    def RefreshButtons(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   618
        if getattr(self, "Table", None):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   619
            table_length = len(self.Table.data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   620
            row_class = None
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   621
            row_edit = True
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   622
            if table_length > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   623
                row = self.VariablesGrid.GetGridCursorRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   624
                row_edit = self.Table.GetValueByName(row, "Edit")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   625
                if self.PouIsUsed:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   626
                    row_class = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   627
            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
   628
            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
   629
            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
   630
            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
   631
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   632
    def OnAddButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   633
        new_row = self.DefaultValue.copy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   634
        if self.Filter in self.DefaultTypes:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   635
            new_row["Class"] = self.DefaultTypes[self.Filter]
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   636
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   637
            new_row["Class"] = self.Filter
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   638
        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
   639
            row_index = self.VariablesGrid.GetGridCursorRow() + 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   640
            self.Values.insert(row_index, new_row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   641
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   642
            row_index = -1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   643
            self.Values.append(new_row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   644
        self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   645
        self.RefreshValues(row_index)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   646
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   647
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   648
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   649
    def OnDeleteButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   650
        row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   651
        self.Values.remove(row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   652
        self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   653
        self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   654
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   655
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   656
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   657
    def OnUpButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   658
        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   659
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   660
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   661
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   662
    def OnDownButton(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   663
        self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   664
        self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   665
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   666
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   667
    def OnVariablesGridCellChange(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   668
        row, col = event.GetRow(), event.GetCol()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   669
        colname = self.Table.GetColLabelValue(col)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   670
        value = self.Table.GetValue(row, col)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   671
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   672
        if colname == "Name" and value != "":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   673
            if not TestIdentifier(value):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   674
                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
   675
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   676
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   677
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   678
            elif value.upper() in IEC_KEYWORDS:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   679
                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
   680
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   681
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   682
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   683
            elif value.upper() in self.PouNames:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   684
                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
   685
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   686
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   687
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   688
            elif value.upper() in [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
   689
                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
   690
                message.ShowModal()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   691
                message.Destroy()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   692
                event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   693
            else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   694
                self.SaveValues(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   695
                old_value = self.Table.GetOldValue()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   696
                if old_value != "":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   697
                    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
   698
                self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   699
                self.ParentWindow.RefreshEditor(variablepanel = False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   700
                self.ParentWindow.RefreshTitle()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   701
                self.ParentWindow.RefreshEditMenu()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   702
                self.ParentWindow.RefreshInstancesTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   703
                self.ParentWindow.RefreshLibraryTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   704
                event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   705
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   706
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   707
            if colname == "Class":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   708
                self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   709
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   710
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   711
    def OnVariablesGridEditorShown(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   712
        row, col = event.GetRow(), event.GetCol() 
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   713
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   714
        label_value = self.Table.GetColLabelValue(col)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   715
        if label_value == "Type":
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   716
            debug = self.ParentWindow.Debug
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   717
            type_menu = wx.Menu(title='')   # the root menu
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   718
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   719
            # build a submenu containing standard IEC types
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   720
            base_menu = wx.Menu(title='')
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   721
            for base_type in self.Controler.GetBaseTypes():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   722
                new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   723
                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
   724
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   725
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   726
            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   727
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   728
            # build a submenu containing user-defined types
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   729
            datatype_menu = wx.Menu(title='')
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   730
            datatypes = self.Controler.GetDataTypes(basetypes = False, debug = debug)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   731
            for datatype in datatypes:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   732
                new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   733
                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
   734
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   735
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   736
            type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   737
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   738
            # build a submenu containing function block types
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   739
            bodytype = self.Controler.GetEditedElementBodyType(self.TagName, debug)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   740
            pouname, poutype = self.Controler.GetEditedElementType(self.TagName, debug)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   741
            classtype = self.Table.GetValueByName(row, "Class")
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   742
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   743
            if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   744
            poutype != "function" and bodytype in ["ST", "IL"]:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   745
                functionblock_menu = wx.Menu(title='')
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   746
                fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName, debug)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   747
                for functionblock_type in fbtypes:
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   748
                    new_id = wx.NewId()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   749
                    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
   750
                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   751
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   752
                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   753
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   754
            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   755
            corner_x = rect.x + rect.width
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   756
            corner_y = rect.y + self.VariablesGrid.GetColLabelSize()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   757
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   758
            # pop up this new menu
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   759
            self.VariablesGrid.PopupMenuXY(type_menu, corner_x, corner_y)
418
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   760
            event.Veto()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   761
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   762
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   763
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   764
    def GetVariableTypeFunction(self, base_type):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   765
        def VariableTypeFunction(event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   766
            row = self.VariablesGrid.GetGridCursorRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   767
            self.Table.SetValueByName(row, "Type", base_type)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   768
            self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   769
            self.SaveValues(False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   770
            self.ParentWindow.RefreshEditor(variablepanel = False)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   771
            self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   772
            self.ParentWindow.RefreshTitle()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   773
            self.ParentWindow.RefreshEditMenu()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   774
            self.ParentWindow.RefreshInstancesTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   775
            self.ParentWindow.RefreshLibraryTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   776
            event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   777
        return VariableTypeFunction
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   778
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   779
    def OnVariablesGridCellLeftClick(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   780
        row = event.GetRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   781
        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
   782
            row = event.GetRow()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   783
            var_name = self.Table.GetValueByName(row, "Name")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   784
            var_class = self.Table.GetValueByName(row, "Class")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   785
            var_type = self.Table.GetValueByName(row, "Type")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   786
            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
   787
            dragSource = wx.DropSource(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   788
            dragSource.SetData(data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   789
            dragSource.DoDragDrop()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   790
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   791
    
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   792
    def OnVariablesGridSelectCell(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   793
        wx.CallAfter(self.RefreshButtons)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   794
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   795
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   796
    def OnChar(self, event):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   797
        keycode = event.GetKeyCode()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   798
        if keycode == wx.WXK_DELETE:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   799
            row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   800
            self.Values.remove(row)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   801
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   802
            self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   803
            self.RefreshButtons()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   804
        event.Skip()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   805
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   806
    def MoveValue(self, value_index, move):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   807
        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
   808
        if new_index != value_index:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   809
            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
   810
            self.SaveValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   811
            self.RefreshValues()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   812
            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
   813
        
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   814
    def RefreshValues(self, select=0):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   815
        if len(self.Table.data) > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   816
            self.VariablesGrid.SetGridCursor(0, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   817
        data = []
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   818
        for num, variable in enumerate(self.Values):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   819
            if variable["Class"] in self.ClassList:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   820
                variable["Number"] = num + 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   821
                data.append(variable)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   822
        self.Table.SetData(data)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   823
        if len(self.Table.data) > 0:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   824
            if select == -1:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   825
                select = len(self.Table.data) - 1
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   826
            self.VariablesGrid.SetGridCursor(select, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   827
            self.VariablesGrid.MakeCellVisible(select, 1)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   828
        self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   829
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   830
    def SaveValues(self, buffer = True):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   831
        words = self.TagName.split("::")
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   832
        if self.ElementType == "config":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   833
            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   834
        elif self.ElementType == "resource":
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   835
            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
   836
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   837
            if self.ReturnType.IsEnabled():
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   838
                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
   839
            self.Controler.SetPouInterfaceVars(words[1], self.Values)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   840
        if buffer:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   841
            self.Controler.BufferProject()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   842
            self.ParentWindow.RefreshTitle()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   843
            self.ParentWindow.RefreshEditMenu()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   844
            self.ParentWindow.RefreshInstancesTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   845
            self.ParentWindow.RefreshLibraryTree()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   846
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   847
    def AddVariableError(self, infos):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   848
        if isinstance(infos[0], TupleType):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   849
            for i in xrange(*infos[0]):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   850
                self.Table.AddError((i,) + infos[1:])
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   851
        else:
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   852
            self.Table.AddError(infos)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   853
        self.Table.ResetView(self.VariablesGrid)
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   854
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   855
    def ClearErrors(self):
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   856
        self.Table.ClearErrors()
a06221a0930b split the variable editor panel into its own file
b.taylor@willowglen.ca
parents:
diff changeset
   857
        self.Table.ResetView(self.VariablesGrid)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   858
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   859
class LocationCellControl(wx.PyControl):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   860
    '''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   861
    Custom cell editor control with a text box and a button that launches
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   862
    the BrowseVariableLocationsDialog.
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   863
    '''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   864
    def __init__(self, parent, var_panel):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   865
        wx.Control.__init__(self, parent, -1)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   866
        self.ParentWindow = parent
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   867
        self.VarPanel = var_panel
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   868
        self.Row = -1
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   869
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   870
        self.Bind(wx.EVT_SIZE, self.OnSize)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   871
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   872
        # create text control
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   873
        self.txt = wx.TextCtrl(self, -1, '')
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   874
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   875
        # create browse button
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   876
        self.btn = wx.Button(self, -1, '...', size=(20,20))
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   877
        self.btn.Bind(wx.EVT_BUTTON, self.OnBtnBrowseClick)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   878
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   879
        szr = wx.BoxSizer(wx.HORIZONTAL)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   880
        szr.Add(self.txt, proportion=1, flag=wx.EXPAND)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   881
        szr.Add(self.btn, proportion=0, flag=wx.ALIGN_RIGHT)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   882
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   883
        szr.SetSizeHints(self)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   884
        self.SetSizer(szr)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   885
        self.Layout()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   886
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   887
    def SetRow(self, row):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   888
        '''set the grid row that we're working on'''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   889
        self.Row = row
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   890
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   891
    def OnSize(self, event):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   892
        '''resize the button and text control to fit'''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   893
        overall_width = self.GetSize()[0]
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   894
        btn_width, btn_height = self.btn.GetSize()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   895
        new_txt_width = overall_width - btn_width
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   896
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   897
        self.txt.SetSize(wx.Size(new_txt_width, -1))
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   898
        self.btn.SetDimensions(new_txt_width, -1, btn_width, btn_height)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   899
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   900
    def OnBtnBrowseClick(self, event):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   901
        # pop up the location browser dialog
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   902
        dia = BrowseVariableLocationsDialog(self.ParentWindow, self.VarPanel)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   903
        dia.ShowModal()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   904
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   905
        if dia.Selection:
425
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
   906
            loc, iec_type, doc = dia.Selection
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   907
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   908
            # set the location
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   909
            self.SetText(loc)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   910
425
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
   911
            # set the variable type and documentation
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   912
            # NOTE: this update won't be displayed until editing is complete
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   913
            # (when EndEdit is called).
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   914
            # we can't call VarPanel.RefreshValues() here because it causes
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   915
            # an exception. 
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   916
            self.VarPanel.Table.SetValueByName(self.Row, 'Type', iec_type)
425
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
   917
            self.VarPanel.Table.SetValueByName(self.Row, 'Documentation', doc)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   918
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   919
        self.txt.SetFocus()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   920
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   921
    def SetText(self, text):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   922
        self.txt.SetValue(text)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   923
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   924
    def SetInsertionPoint(self, i):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   925
        self.txt.SetInsertionPoint(i)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   926
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   927
    def GetText(self):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   928
        return self.txt.GetValue()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   929
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   930
    def SetFocus(self):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   931
        self.txt.SetFocus()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   932
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   933
class LocationCellEditor(wx.grid.PyGridCellEditor):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   934
    '''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   935
    Grid cell editor that uses LocationCellControl to display a browse button.
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   936
    '''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   937
    def __init__(self, var_panel):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   938
        wx.grid.PyGridCellEditor.__init__(self)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   939
        self.VarPanel = var_panel
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   940
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   941
    def Create(self, parent, id, evt_handler):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   942
        self.text_browse = LocationCellControl(parent, self.VarPanel)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   943
        self.SetControl(self.text_browse)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   944
        if evt_handler:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   945
            self.text_browse.PushEventHandler(evt_handler)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   946
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   947
    def BeginEdit(self, row, col, grid):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   948
        loc = self.VarPanel.Table.GetValueByName(row, 'Location')
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   949
        self.text_browse.SetText(loc)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   950
        self.text_browse.SetRow(row)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   951
        self.text_browse.SetFocus()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   952
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   953
    def EndEdit(self, row, col, grid):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   954
        loc = self.text_browse.GetText()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   955
        old_loc = self.VarPanel.Table.GetValueByName(row, 'Location')
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   956
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   957
        if loc != old_loc:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   958
            self.VarPanel.Table.SetValueByName(row, 'Location', loc)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   959
            
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   960
            # NOTE: this is a really lame hack to force this row's
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   961
            # 'Type' cell to redraw (since it may have changed). 
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   962
            # There's got to be a better way than this.
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   963
            self.VarPanel.VariablesGrid.AutoSizeRow(row)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   964
            return True
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   965
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   966
    def SetSize(self, rect):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   967
        # -2 and +5 give this some extra vertical padding
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   968
        self.text_browse.SetDimensions(rect.x, rect.y-2,
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   969
                                        rect.width, rect.height+5,
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   970
                                        wx.SIZE_ALLOW_MINUS_ONE)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   971
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   972
    def Clone(self):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   973
        return LocationCellEditor(self.VarPanel)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   974
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   975
class BrowseVariableLocationsDialog(wx.Dialog):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   976
    # turn LOCATIONDATATYPES inside-out
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   977
    LOCATION_SIZES = {}
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   978
    for size, types in LOCATIONDATATYPES.iteritems():
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   979
        for type in types:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   980
            LOCATION_SIZES[type] = size
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   981
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   982
    class PluginData:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   983
        '''contains a plugin's VariableLocationTree'''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   984
        def __init__(self, plugin):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   985
            self.subtree  = plugin.GetVariableLocationTree()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   986
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   987
    class SubtreeData:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   988
        '''contains a subtree of a plugin's VariableLocationTree'''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   989
        def __init__(self, subtree):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   990
            self.subtree = subtree
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   991
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   992
    class VariableData:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   993
        '''contains all the information about a valid variable location'''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   994
        def __init__(self, type, dir, loc):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   995
            self.type   = type
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   996
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   997
            loc_suffix = '.'.join([str(x) for x in loc])
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   998
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
   999
            size = BrowseVariableLocationsDialog.LOCATION_SIZES[type]
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1000
            self.loc = size + loc_suffix
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1001
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1002
            # if a direction was given, use it
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1003
            # (if not we'll prompt the user to select one)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1004
            if dir:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1005
                self.loc = '%' + dir + self.loc
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1006
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1007
    def __init__(self, parent, var_panel):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1008
        self.VarPanel   = var_panel
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1009
        self.Selection  = None
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1010
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1011
        # create the dialog
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1012
        wx.Dialog.__init__(self, parent=parent, title=_('Browse Variables'),
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1013
                            style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1014
                            size=(-1, 400))
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1015
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1016
        # create the root sizer
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1017
        sizer = wx.BoxSizer(wx.VERTICAL)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1018
        self.SetSizer(sizer)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1019
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1020
        # create the tree control
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1021
        self.tree = wx.TreeCtrl(self, style=wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1022
        sizer.Add(self.tree, 1, wx.EXPAND|wx.ALL, border=20)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1023
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1024
        # create the Direction sizer and field
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1025
        dsizer = wx.BoxSizer(wx.HORIZONTAL)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1026
        sizer.Add(dsizer, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, border=20)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1027
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1028
        #   direction label
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1029
        ltext = wx.StaticText(self, -1, _('Direction:'))
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1030
        dsizer.Add(ltext, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, border=20)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1031
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1032
        #   direction choice
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1033
        self.DirChoice = wx.Choice(id=-1, parent=self, choices=[_('Input'), _('Output'), _('Memory')])
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1034
        dsizer.Add(self.DirChoice, flag=wx.EXPAND)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1035
        #   set a default for the choice   
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1036
        self.SetSelectedDirection('I')
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1037
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1038
        # create the button sizer
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1039
        btsizer = wx.BoxSizer(wx.HORIZONTAL)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1040
        sizer.Add(btsizer, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT, border=20)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1041
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1042
        # add plugins to the tree
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1043
        root = self.tree.AddRoot(_('Plugins'))
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1044
        ctrl = self.VarPanel.Controler
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1045
        self.AddChildPluginsToTree(ctrl.PluginsRoot, root)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1046
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1047
        #       -- buttons --
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1048
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1049
        # ok button
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1050
        self.OkButton = wx.Button(self, wx.ID_OK, _('Use Location'))
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1051
        self.OkButton.SetDefault()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1052
        btsizer.Add(self.OkButton, flag=wx.RIGHT, border=5)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1053
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1054
        # cancel button
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1055
        b = wx.Button(self, wx.ID_CANCEL, _('Cancel'))
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1056
        btsizer.Add(b)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1057
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1058
        #       -- event handlers --
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1059
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1060
        # accept the location on doubleclick or clicking the Use Location button
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1061
        self.Bind(wx.EVT_BUTTON, self.OnOk, self.OkButton)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1062
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnOk, self.tree)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1063
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1064
        # disable the Add button when we're not on a valid variable
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1065
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChange, self.tree)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1066
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1067
        # handle the Expand event. this lets us create the tree as it's expanded
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1068
        # (trying to create it all at once is slow since plugin variable location
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1069
        # trees can be big)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1070
        wx.EVT_TREE_ITEM_EXPANDING(self.tree, self.tree.GetId(), self.OnExpand)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1071
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1072
    def OnExpand(self, event):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1073
        item = event.GetItem()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1074
        if not item.IsOk():
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1075
            item = self.tree.GetSelection()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1076
        
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1077
        data = self.tree.GetPyData(item)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1078
        self.ExpandTree(item, data.subtree)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1079
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1080
    def AddChildPluginsToTree(self, plugin, root):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1081
        for p in plugin.IECSortedChilds():
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1082
            plug_name = p.BaseParams.getName()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1083
            new_item = self.tree.AppendItem(root, plug_name)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1084
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1085
            # make it look like the tree item has children (since it doesn't yet)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1086
            self.tree.SetItemHasChildren(new_item) 
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1087
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1088
            # attach the plugin data to the tree item
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1089
            self.tree.SetPyData(new_item, BrowseVariableLocationsDialog.PluginData(p))
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1090
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1091
            # add child plugins recursively
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1092
            self.AddChildPluginsToTree(p, new_item)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1093
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1094
    def ExpandTree(self, root, subtree):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1095
            items = subtree.items()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1096
            items.sort()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1097
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1098
            for node_name, data in items:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1099
                if isinstance(data, dict):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1100
                    # this is a new subtree
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1101
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1102
                    new_item = self.tree.AppendItem(root, node_name)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1103
                    self.tree.SetItemHasChildren(new_item)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1104
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1105
                    # attach the new subtree's data to the tree item
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1106
                    new_data = BrowseVariableLocationsDialog.SubtreeData(data)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1107
                    self.tree.SetPyData(new_item, new_data)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1108
                else:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1109
                    # this is a new leaf.
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1110
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1111
                    # data is a tuple containing (IEC type, I/Q/M/None, IEC path tuple)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1112
                    type, dir, loc = data
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1113
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1114
                    node_name = '%s (%s)' % (node_name, type)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1115
                    new_item = self.tree.AppendItem(root, node_name)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1116
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1117
                    vd = BrowseVariableLocationsDialog.VariableData(type, dir, loc)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1118
                    self.tree.SetPyData(new_item, vd)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1119
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1120
    def OnSelChange(self, event):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1121
        '''updates the text field and the "Use Location"  button.'''
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1122
        item = self.tree.GetSelection()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1123
        data = self.tree.GetPyData(item)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1124
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1125
        if isinstance(data, BrowseVariableLocationsDialog.VariableData):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1126
            self.OkButton.Enable()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1127
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1128
            location = data.loc
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1129
            if location[0] == '%':
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1130
                # location has a fixed direction
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1131
                self.SetSelectedDirection(location[1])
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1132
                self.DirChoice.Disable()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1133
            else:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1134
                # this location can have any direction (user selects)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1135
                self.DirChoice.Enable()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1136
        else:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1137
            self.OkButton.Disable()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1138
            self.DirChoice.Disable()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1139
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1140
    def GetSelectedDirection(self):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1141
        selected = self.DirChoice.GetSelection()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1142
        if selected == 0:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1143
            return 'I'
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1144
        elif selected == 1:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1145
            return 'Q'
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1146
        else:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1147
            return 'M'
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1148
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1149
    def SetSelectedDirection(self, dir_letter):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1150
        if dir_letter == 'I':
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1151
            self.DirChoice.SetSelection(0)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1152
        elif dir_letter == 'Q':
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1153
            self.DirChoice.SetSelection(1)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1154
        else:
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1155
            self.DirChoice.SetSelection(2)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1156
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1157
    def OnOk(self, event):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1158
        item = self.tree.GetSelection()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1159
        data = self.tree.GetPyData(item)
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1160
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1161
        if not isinstance(data, BrowseVariableLocationsDialog.VariableData):
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1162
            return
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1163
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1164
        location = data.loc
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1165
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1166
        if location[0] != '%':
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1167
            # no direction was given, grab the one from the wxChoice
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1168
            dir = self.GetSelectedDirection()
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1169
            location = '%' + dir + location
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1170
425
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1171
        # walk up the tree, building documentation for the variable
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1172
        documentation = self.tree.GetItemText(item)
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1173
        parent = self.tree.GetItemParent(item)
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1174
        root = self.tree.GetRootItem()
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1175
        while parent != root:
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1176
            text = self.tree.GetItemText(parent)
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1177
            documentation = text + ":" + documentation
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1178
            parent = self.tree.GetItemParent(parent)
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1179
dbc4a66190a6 set variable documentation when a location is selected from the VariableLocationBrowser
b.taylor@willowglen.ca
parents: 424
diff changeset
  1180
        self.Selection = (location, data.type, documentation)
422
31c3dc45cfab introduced BrowseVariableLocationsDialog and the GridCellEditor that launches it.
b.taylor@willowglen.ca
parents: 419
diff changeset
  1181
        self.Destroy()