controls/LocationCellEditor.py
author Edouard Tisserant
Wed, 31 Jul 2013 10:45:07 +0900
branch1.1 Korean release
changeset 1280 72a826dfcfbb
parent 1004 bf3b6998f7b6
child 1536 3518d10487db
permissions -rw-r--r--
RC4
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
from dialogs.BrowseLocationsDialog import BrowseLocationsDialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
class LocationCellControl(wx.PyControl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
    '''
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
    Custom cell editor control with a text box and a button that launches
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
    the BrowseLocationsDialog.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
    '''
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
    def __init__(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
        wx.Control.__init__(self, parent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
        main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
        main_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
        # create location text control
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
        self.Location = wx.TextCtrl(self, size=wx.Size(0, -1), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
              style=wx.TE_PROCESS_ENTER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
        self.Location.Bind(wx.EVT_KEY_DOWN, self.OnLocationChar)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
        main_sizer.AddWindow(self.Location, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
        # create browse button
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        self.BrowseButton = wx.Button(self, label='...', size=wx.Size(30, -1))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
        self.BrowseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonClick)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
        main_sizer.AddWindow(self.BrowseButton, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        self.Bind(wx.EVT_SIZE, self.OnSize)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    57
        self.Controller = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
        self.VarType = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        self.Default = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    61
    def __del__(self):
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    62
        self.Controller = None
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    63
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    64
    def SetController(self, controller):
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    65
        self.Controller = controller
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
    def SetVarType(self, vartype):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
        self.VarType = vartype
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    70
    def GetVarType(self):
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    71
        return self.VarType
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    72
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
    def SetValue(self, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        self.Default = value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
        self.Location.SetValue(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
    def GetValue(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        return self.Location.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
    def OnSize(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        self.Layout()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
    def OnBrowseButtonClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        # pop up the location browser dialog
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
    85
        dialog = BrowseLocationsDialog(self, self.VarType, self.Controller)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
            infos = dialog.GetValues()
1004
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    88
        else:
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    89
            infos = None
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    90
        dialog.Destroy()
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    91
        
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    92
        if infos is not None:
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    93
            location = infos["location"]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
            # set the location
1004
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    95
            if not infos["location"].startswith("%"):
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    96
                dialog = wx.SingleChoiceDialog(self, 
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    97
                      _("Select a variable class:"), _("Variable class"), 
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    98
                      ["Input", "Output", "Memory"], 
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
    99
                      wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   100
                if dialog.ShowModal() == wx.ID_OK:
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   101
                    selected = dialog.GetSelection()
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   102
                else:
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   103
                    selected = None
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   104
                dialog.Destroy()
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   105
                if selected is None:
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   106
                    self.Location.SetFocus()
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   107
                    return
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   108
                if selected == 0:
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   109
                    location = "%I" + location
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   110
                elif selected == 1:
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   111
                    location = "%Q" + location
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   112
                else:
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   113
                    location = "%M" + location
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   114
            
bf3b6998f7b6 Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents: 855
diff changeset
   115
            self.Location.SetValue(location)
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
   116
            self.VarType = infos["IEC_type"]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
        self.Location.SetFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
    def OnLocationChar(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
        keycode = event.GetKeyCode()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
        if keycode in [wx.WXK_RETURN, wx.WXK_TAB]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
            self.Parent.Parent.ProcessEvent(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
        elif keycode == wx.WXK_ESCAPE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
            self.Location.SetValue(self.Default)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
            self.Parent.Parent.CloseEditControl()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
    def SetInsertionPoint(self, i):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
        self.Location.SetInsertionPoint(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
    def SetFocus(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
        self.Location.SetFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
class LocationCellEditor(wx.grid.PyGridCellEditor):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
    '''
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
    Grid cell editor that uses LocationCellControl to display a browse button.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
    '''
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
    def __init__(self, table, controller):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
        wx.grid.PyGridCellEditor.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
        self.Table = table
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
        self.Controller = controller
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
        self.CellControl = None
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
   148
        self.Controller = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
    def Create(self, parent, id, evt_handler):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
        self.CellControl = LocationCellControl(parent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        self.SetControl(self.CellControl)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        if evt_handler:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
            self.CellControl.PushEventHandler(evt_handler)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
    def BeginEdit(self, row, col, grid):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        self.CellControl.Enable()
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
   158
        self.CellControl.SetController(self.Controller)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
        if isinstance(self.CellControl, LocationCellControl):
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
   161
            self.CellControl.SetVarType(self.Table.GetValueByName(row, 'Type'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
        self.CellControl.SetFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
    def EndEdit(self, row, col, grid):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
        loc = self.CellControl.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
        old_loc = self.Table.GetValueByName(row, 'Location')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
        changed = loc != old_loc
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
        if changed:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
            self.Table.SetValueByName(row, 'Location', loc)
855
b30421d07e8c Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents: 814
diff changeset
   170
            self.Table.SetValueByName(row, 'Type', self.CellControl.GetVarType())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        self.CellControl.Disable()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
        return changed
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
    def SetSize(self, rect):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        self.CellControl.SetDimensions(rect.x + 1, rect.y,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
                                        rect.width, rect.height,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
                                        wx.SIZE_ALLOW_MINUS_ONE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
    def Clone(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
        return LocationCellEditor(self.Table, self.Controller)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181