controls/LocationCellEditor.py
changeset 1649 3291024e00da
parent 1578 f8e2a04c4445
child 1730 64d8f52bc8c8
equal deleted inserted replaced
1648:6431f26aa501 1649:3291024e00da
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 #based on the plcopen standard. 
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     8 #
     8 #
     9 #See COPYING file for copyrights details.
     9 # See COPYING file for copyrights details.
    10 #
    10 #
    11 #This library is free software; you can redistribute it and/or
    11 # This program is free software; you can redistribute it and/or
    12 #modify it under the terms of the GNU General Public
    12 # modify it under the terms of the GNU General Public License
    13 #License as published by the Free Software Foundation; either
    13 # as published by the Free Software Foundation; either version 2
    14 #version 2.1 of the License, or (at your option) any later version.
    14 # of the License, or (at your option) any later version.
    15 #
    15 #
    16 #This library is distributed in the hope that it will be useful,
    16 # This program is distributed in the hope that it will be useful,
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19 #General Public License for more details.
    19 # GNU General Public License for more details.
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 # You should have received a copy of the GNU General Public License
    22 #License along with this library; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 import wx
    25 import wx
    26 
    26 
    27 from dialogs.BrowseLocationsDialog import BrowseLocationsDialog
    27 from dialogs.BrowseLocationsDialog import BrowseLocationsDialog
    28 
    28 
    93             location = infos["location"]
    93             location = infos["location"]
    94             # set the location
    94             # set the location
    95             if not infos["location"].startswith("%"):
    95             if not infos["location"].startswith("%"):
    96                 dialog = wx.SingleChoiceDialog(self, 
    96                 dialog = wx.SingleChoiceDialog(self, 
    97                       _("Select a variable class:"), _("Variable class"), 
    97                       _("Select a variable class:"), _("Variable class"), 
    98                       ["Input", "Output", "Memory"], 
    98                       [_("Input"), _("Output"), _("Memory")], 
    99                       wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
    99                       wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
   100                 if dialog.ShowModal() == wx.ID_OK:
   100                 if dialog.ShowModal() == wx.ID_OK:
   101                     selected = dialog.GetSelection()
   101                     selected = dialog.GetSelection()
   102                 else:
   102                 else:
   103                     selected = None
   103                     selected = None
   159         self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
   159         self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location'))
   160         if isinstance(self.CellControl, LocationCellControl):
   160         if isinstance(self.CellControl, LocationCellControl):
   161             self.CellControl.SetVarType(self.Table.GetValueByName(row, 'Type'))
   161             self.CellControl.SetVarType(self.Table.GetValueByName(row, 'Type'))
   162         self.CellControl.SetFocus()
   162         self.CellControl.SetFocus()
   163 
   163 
   164     def EndEdit(self, row, col, grid):
   164     def EndEditInternal(self, row, col, grid, old_loc):
   165         loc = self.CellControl.GetValue()
   165         loc = self.CellControl.GetValue()
   166         old_loc = self.Table.GetValueByName(row, 'Location')
       
   167         changed = loc != old_loc
   166         changed = loc != old_loc
   168         if changed:
   167         if changed:
   169             self.Table.SetValueByName(row, 'Location', loc)
   168             self.Table.SetValueByName(row, 'Location', loc)
   170             self.Table.SetValueByName(row, 'Type', self.CellControl.GetVarType())
   169             self.Table.SetValueByName(row, 'Type', self.CellControl.GetVarType())
   171         self.CellControl.Disable()
   170         self.CellControl.Disable()
   172         return changed
   171         return changed
       
   172         
       
   173     if wx.VERSION >= (3, 0, 0):
       
   174         def EndEdit(self, row, col, grid, oldval):
       
   175             return self.EndEditInternal(row, col, grid, oldval)
       
   176     else:
       
   177         def EndEdit(self, row, col, grid):
       
   178             old_loc = self.Table.GetValueByName(row, 'Location')            
       
   179             return self.EndEditInternal(row, col, grid, old_loc)
   173     
   180     
   174     def SetSize(self, rect):
   181     def SetSize(self, rect):
   175         self.CellControl.SetDimensions(rect.x + 1, rect.y,
   182         self.CellControl.SetDimensions(rect.x + 1, rect.y,
   176                                         rect.width, rect.height,
   183                                         rect.width, rect.height,
   177                                         wx.SIZE_ALLOW_MINUS_ONE)
   184                                         wx.SIZE_ALLOW_MINUS_ONE)