controls/CustomGrid.py
author laurent
Mon, 21 May 2012 11:00:40 +0200
changeset 690 a32548167224
parent 672 d751b1c609b3
child 714 131ea7f237b9
permissions -rw-r--r--
Fix bug with Properties menu entry
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     3
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     5
#based on the plcopen standard. 
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     6
#
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     8
#
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
     9
#See COPYING file for copyrights details.
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    10
#
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    15
#
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    19
#General Public License for more details.
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    20
#
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    24
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    25
import wx
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    26
import wx.grid
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    27
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    28
class CustomGrid(wx.grid.Grid):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    29
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    30
    if wx.VERSION < (2, 6, 0):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    31
        def Bind(self, event, function, id = None):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    32
            if id is not None:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    33
                event(self, id, function)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    34
            else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    35
                event(self, function)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    36
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    37
    def __init__(self, *args, **kwargs):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    38
        wx.grid.Grid.__init__(self, *args, **kwargs)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    39
        
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
    40
        self.Editable = True
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
    41
        
606
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    42
        self.AddButton = None
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    43
        self.DeleteButton = None
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    44
        self.UpButton = None
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    45
        self.DownButton = None
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    46
        
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    47
        self.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, 'Sans'))
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    48
        self.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, False, 'Sans'))
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    49
        self.SetSelectionBackground(wx.WHITE)
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    50
        self.SetSelectionForeground(wx.BLACK)
614
8c4b57808f9c Disabling drag for modifying grid row size
laurent
parents: 606
diff changeset
    51
        self.DisableDragRowSize()
606
d65122c61eaf Moving definition of grids fonts and colours into CustomGrid
laurent
parents: 600
diff changeset
    52
        
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    53
        if wx.VERSION >= (2, 6, 0):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    54
            self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnSelectCell)
655
435e2d8ee580 Fixing issues regarding control navigation in EditorPanel and CustomGrid
laurent
parents: 614
diff changeset
    55
            self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.OnEditorHidden)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    56
        else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    57
            wx.grid.EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    58
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    59
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    60
    def SetDefaultValue(self, default_value):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    61
        self.DefaultValue = default_value
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    62
    
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
    63
    def SetEditable(self, editable=True):
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
    64
        self.Editable = editable
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
    65
        self.RefreshButtons()
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
    66
        
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    67
    def SetButtons(self, buttons):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    68
        for name in ["Add", "Delete", "Up", "Down"]:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    69
            button = buttons.get(name, None)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    70
            setattr(self, "%sButton" % name, button)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    71
            if button is not None:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    72
                button.Bind(wx.EVT_BUTTON, getattr(self, "On%sButton" % name))
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    73
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    74
    def RefreshButtons(self):
672
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    75
        if self:
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    76
            rows = self.Table.GetNumberRows()
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    77
            row = self.GetGridCursorRow()
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    78
            if self.AddButton is not None:
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    79
                self.AddButton.Enable(self.Editable)
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    80
            if self.DeleteButton is not None:
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    81
                self.DeleteButton.Enable(self.Editable and rows > 0)
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    82
            if self.UpButton is not None:
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    83
                self.UpButton.Enable(self.Editable and row > 0)
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    84
            if self.DownButton is not None:
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 662
diff changeset
    85
                self.DownButton.Enable(self.Editable and 0 <= row < rows - 1)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    86
    
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    87
    def CloseEditControl(self):
662
3c4e0d4f7a61 Fix bug when grid is reset and a CellEditor is still active
laurent
parents: 655
diff changeset
    88
        row, col = self.GetGridCursorRow(), self.GetGridCursorCol()
3c4e0d4f7a61 Fix bug when grid is reset and a CellEditor is still active
laurent
parents: 655
diff changeset
    89
        if row != -1 and col != -1:
3c4e0d4f7a61 Fix bug when grid is reset and a CellEditor is still active
laurent
parents: 655
diff changeset
    90
            self.SetGridCursor(row, col)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    91
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    92
    def AddRow(self):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    93
        self.CloseEditControl()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    94
        new_row = self.GetGridCursorRow() + 1
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    95
        col = max(self.GetGridCursorCol(), 0)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    96
        if getattr(self, "_AddRow", None) is not None:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    97
            new_row = self._AddRow(new_row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    98
        else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
    99
            self.Table.InsertRow(new_row, self.DefaultValue.copy())
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   100
            self.Table.ResetView(self)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   101
        self.SetGridCursor(new_row, col)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   102
        self.MakeCellVisible(new_row, col)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   103
        self.RefreshButtons()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   104
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   105
    def DeleteRow(self):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   106
        self.CloseEditControl()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   107
        row = self.GetGridCursorRow()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   108
        if row >= 0:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   109
            col = self.GetGridCursorCol()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   110
            if getattr(self, "_DeleteRow", None) is not None:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   111
                self._DeleteRow(row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   112
            else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   113
                self.Table.RemoveRow(row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   114
                self.Table.ResetView(self)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   115
            new_row = min(row, self.Table.GetNumberRows() - 1)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   116
            self.SetGridCursor(new_row, col)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   117
            self.MakeCellVisible(new_row, col)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   118
            self.RefreshButtons()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   119
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   120
    def MoveRow(self, row, move):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   121
        self.CloseEditControl()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   122
        col = self.GetGridCursorCol()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   123
        if getattr(self, "_MoveRow", None) is not None:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   124
            new_row = self._MoveRow(row, move)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   125
        else:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   126
            new_row = self.Table.MoveRow(row, move)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   127
            if new_row != row:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   128
                self.Table.ResetView(self)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   129
        if new_row != row:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   130
            self.SetGridCursor(new_row, col)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   131
            self.MakeCellVisible(new_row, col)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   132
            self.RefreshButtons()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   133
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   134
    def OnAddButton(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   135
        self.AddRow()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   136
        self.SetFocus()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   137
        event.Skip()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   138
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   139
    def OnDeleteButton(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   140
        self.DeleteRow()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   141
        self.SetFocus()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   142
        event.Skip()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   143
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   144
    def OnUpButton(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   145
        self.MoveRow(self.GetGridCursorRow(), -1)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   146
        self.SetFocus()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   147
        event.Skip()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   148
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   149
    def OnDownButton(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   150
        self.MoveRow(self.GetGridCursorRow(), 1)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   151
        self.SetFocus()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   152
        event.Skip()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   153
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   154
    def OnSelectCell(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   155
        wx.CallAfter(self.RefreshButtons)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   156
        event.Skip()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   157
655
435e2d8ee580 Fixing issues regarding control navigation in EditorPanel and CustomGrid
laurent
parents: 614
diff changeset
   158
    def OnEditorHidden(self, event):
435e2d8ee580 Fixing issues regarding control navigation in EditorPanel and CustomGrid
laurent
parents: 614
diff changeset
   159
        wx.CallAfter(self.SetFocus)
435e2d8ee580 Fixing issues regarding control navigation in EditorPanel and CustomGrid
laurent
parents: 614
diff changeset
   160
        event.Skip()
435e2d8ee580 Fixing issues regarding control navigation in EditorPanel and CustomGrid
laurent
parents: 614
diff changeset
   161
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   162
    def OnKeyDown(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   163
        key_handled = False
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   164
        keycode = event.GetKeyCode()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   165
        if keycode == wx.WXK_TAB:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   166
            row = self.GetGridCursorRow()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   167
            col = self.GetGridCursorCol()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   168
            if event.ShiftDown():
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   169
                if row < 0 or col == 0:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   170
                    self.Navigate(wx.NavigationKeyEvent.IsBackward)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   171
                    key_handled = True
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   172
            elif row < 0 or col == self.Table.GetNumberCols() - 1:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   173
                self.Navigate(wx.NavigationKeyEvent.IsForward)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   174
                key_handled = True
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
   175
        elif keycode in (wx.WXK_ADD, wx.WXK_NUMPAD_ADD) and self.Editable:
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   176
            self.AddRow()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   177
            key_handled = True
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
   178
        elif keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE) and self.Editable:
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   179
            self.DeleteRow()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   180
            key_handled = True
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
   181
        elif keycode == wx.WXK_UP and event.ShiftDown() and self.Editable:
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   182
            self.MoveRow(self.GetGridCursorRow(), -1)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   183
            key_handled = True
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 577
diff changeset
   184
        elif keycode == wx.WXK_DOWN and event.ShiftDown() and self.Editable:
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   185
            self.MoveRow(self.GetGridCursorRow(), 1)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   186
            key_handled = True
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   187
        if not key_handled:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
diff changeset
   188
            event.Skip()