[wxpython-users] AcceptsFocusFromKeyboard help
Robin Dunn
robin at alldunn.com
Fri Apr 4 12:17:40 PDT 2008
Paul M¢Nett wrote:
> Hi,
>
> I understand that the c++ virtual method
> wx.Window.AcceptsFocusFromKeyboard() isn't overridable from wxPython
> code, as my attached script demonstrates.
>
> So... given the subclassed wx.TextCtrl that my script defines, how do I
> modify that class to be able to override AcceptsFocusFromKeyboard? I see
> wx.PyControl, wx.PyWindow exist... can I mix that in to my subclassed
> TextCtrl (I've tried and the tracebacks I receive indicate that is the
> wrong path).
Correct.
>
> As I understand it, wx.PyControl and friends exist for me to define new
> controls, and if I go that route I can indeed override functions such as
> AcceptsFocusFromKeyboard(). However, I'm not trying to build new
> controls in Python, but trying to subclass existing wx controls, and am
> unclear how to proceed.
>
> What I'm trying to do is to make a generic property, TabStop, that when
> True will allow the control to receive focus from keyboard navigation,
> and if False will not. I could see a semi-complex route of catching the
> SET_FOCUS event and then trying to figure out how the focus was gotten,
> from what direction, etc. and pass the focus to the next control,
You can use the Navigate method to make that a little easier. Watching
for EVT_NAVIGATION_KEY events may also help.
> but if
> there's some way I could instead override AcceptsFocusFromKeyboard that
> would be the cleaner solution.
There isn't a way to do that now, but in 2.9 there will be a SetCanFocus
method.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list