1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """This module contains utilities that can be used with wxTextCtrls."""
18
19 __id__ = "$Id: textctrlutils.py 2981 2009-04-02 02:13:58Z farrowch $"
20
21 import wx
22
23 -def textCtrlAsGridCell(panel, event):
24 """Process a textCtrl key event as if the textCtrl was a grid cell.
25
26 This catches ESC and ENTER events in textCtrls and processes them as if the
27 textCtrl were a grid cell. This method can be bound to the wx.EVT_KEY_DOWN
28 event of any textCtrl. See phaseconfigurepanel.py in diffpy.pdfgui.gui for
29 an example.
30
31 ESC -- Cancel the edit and highlight the text. This requires that
32 panel has a _focusedText attribute that stores the previous value.
33 ENTER -- Confirm the edit and move to the next cell (the default TAB
34 behavior).
35 """
36 key = event.GetKeyCode()
37
38 textctrl = event.GetEventObject()
39
40
41 if key == 27:
42
43 textctrl.ChangeValue(panel._focusedText)
44
45 wx.CallAfter(textctrl.SetSelection, -1, -1)
46
47 elif key == 13:
48 wx.CallAfter(textctrl.Navigate)
49 event.Skip()
50 return
51