AcceptsFocusFromKeyboard help

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).

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, but if
there's some way I could instead override AcceptsFocusFromKeyboard that
would be the cleaner solution.

Ideas?

Paul

test_but.py (395 Bytes)

Paul M¢Nett wrote:

Robin Dunn wrote:

Paul M¢Nett wrote:

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.

The Navigate() method appears to usually do exactly what I want, without even having to tell it which direction to go in even. However I'm running into trouble when at a "border": when the control that catches the event is the last control in the panel, for instance, or when no controls in the panel should receive focus.

Since you are hinting that I'm on the right path, I'll continue with implementing this by catching EVT_NAVIGATION_KEY and selectively skipping the event or calling Navigate(). When I have specific testable problems I'll post them here.

Thought I'd follow up. I finally figured out the magic incantation to get this working right:

self.Bind(wx.EVT_NAVIGATION_KEY, self.__onWxNavKey)

def __onWxNavKey(self, evt):
   # A navigation key event has caused this control to want to
   # get the focus. Only allow it if self.TabStop is True.
   evt.Skip()
   if not self.TabStop:
     dabo.ui.callAfter(self.Navigate, evt.GetDirection())

The dabo callAfter() is just like the wx.CallAfter(), and I found it was necessary to avoid recursion.

The evt.Skip() is also critical.

I'm sure others here are saying "well, duh" but this kept me stimied for months.

Paul