Package diffpy :: Package pdfgui :: Package gui :: Package wxExtensions :: Module textctrlutils
[hide private]
[frames] | no frames]

Source Code for Module diffpy.pdfgui.gui.wxExtensions.textctrlutils

 1  # -*- coding: UTF-8 -*- 
 2  ############################################################################## 
 3  # 
 4  # wxExtensions      by DANSE Diffraction group 
 5  #                   Simon J. L. Billinge 
 6  #                   (c) 2009 trustees of Columbia University in the City of 
 7  #                   New York. 
 8  #                   All rights reserved. 
 9  # 
10  # File coded by:    Chris Farrow 
11  # 
12  # See AUTHORS.txt for a list of people who contributed. 
13  # See LICENSE.txt for license information. 
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 # ESC - cancel the edit 41 if key == 27: 42 # Restore the original value 43 textctrl.ChangeValue(panel._focusedText) 44 # Now reselect the text 45 wx.CallAfter(textctrl.SetSelection, -1, -1) 46 # ENTER - Act like TAB 47 elif key == 13: 48 wx.CallAfter(textctrl.Navigate) 49 event.Skip() 50 return
51