[wxPython] EVT_CHAR and wxNotebook

Summary: The EVT_CHAR callback in a subclass of wxWindow whose parent
is a wxNotebook does not work at all on win32 and only works on wxGTK
after a mouse focus event is received on the page in the wxNotebook.

EVT_CHAR however works when the wxNotebook is not the parent.

The program which fails may be repeated by:

#! /usr/bin/env python
from wxPython.wx import *

class Page(wxWindow):

    def __init__(self, parent, id,
                 position=wxDefaultPosition,
                 size=wxDefaultSize,
                 style=0):
        wxWindow.__init__(self, parent, id, position, size, style)
        EVT_CHAR (self, self.KeyPressedCB)
        return

    def KeyPressedCB(self, event):
        try:
            char = chr(event.KeyCode())
        except ValueError:
            print "KeyInput.KeyPressedCB not ASCII"
            return

        print "KeyInput.KeyPressedCB", char

class Frame(wxFrame):

    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, -1, title, size = (725, 550))
        notebook = wxNotebook(self, -1)
        page = Page(notebook, -1)
        notebook.AddPage(page, "EVT_CHAR Test")
        return

class App(wxApp):
    def OnInit(self):
        aFrame = Frame(NULL, -1, "EVT_CHAR Test")
        aFrame.Show(true)
        self.SetTopWindow(aFrame)
        return true

def main(argv):
    anApp = App(0)
    anApp.MainLoop()
    return

if __name__ == "__main__":
    import sys
    sys.exit(main(sys.argv) or 0)

Summary: The EVT_CHAR callback in a subclass of wxWindow whose parent
is a wxNotebook does not work at all on win32 and only works on wxGTK
after a mouse focus event is received on the page in the wxNotebook.

EVT_CHAR however works when the wxNotebook is not the parent.

The notebook is taking the key events, checking for navigation keys, and
then looking for children that also want the keys. If you add a
wxWANTS_CHARS style to your page window then it will work.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!