Windows -vs- Linux anomolies

Hi All,

This is a new post with more specific information versus an earlier post on a portion of the same problem.

I have created a wxPython app under Linux. I have tested it under both Mandrake and Suse using Python 2.4 and wxPython 2.6. The behavior across the Linux platforms was as expected - the same. When I copied it to a Windows platform (both XP and 2000 using Python 2.4 and wxPython 2.6), the behavior was not as expected. Specifically, my EVT_CHAR bindings are not catching any key events. I have tried binding the EVT_CHAR to different objects, including the top level dialog as well as the individual buttons - but with no luck.

Here is a test app I created to try and flush out the specifics:

#!/usr/bin/python

from wxPython.wx import *
from wxPython.xrc import *
import os.path

def HandleKeys(event):
    print "Handling event"

class MyDialog(wxDialog):
    def __init__(self, parent):
        wxDialog.__init__(self, parent, -1, "wxDialog")
        self.res = wxXmlResource("./Test.xrc")
        istat = self.res.InitAllHandlers()
        self.dlg = self.res.LoadDialog(parent, "ID_DIALOG")
        self.dlg.SetFocus()
        self.button = XRCCTRL(self.dlg, "ID_BUTTON")
        self.button1 = XRCCTRL(self.dlg, "ID_BUTTON1")
        self.dlg.Bind(wx.EVT_CHAR, HandleKeys)
# self.button.Bind(wx.EVT_CHAR, HandleKeys)
# self.button1.Bind(wx.EVT_CHAR, HandleKeys)
        print "IsActive: ", self.dlg.IsActive()
        print "focus at: ", self.dlg.FindFocus()

        self.dlg.Show(1)
        return None

if __name__ == '__main__':
    app = wxPySimpleApp()
    frame = wxFrame(None, -1, "test")
    dlg = MyDialog(frame)
    app.MainLoop()

Here is the contents of the Test.xrc file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<resource version="2.3.0.1" xmlns="http://www.wxwidgets.org/wxxrc">
    <object class="wxApp" name="" subclass="SimpleMedium">
    </object>
    <object class="wxDialog" name="ID_DIALOG">
    <style>wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX</style>
        <exstyle>wxWS_EX_BLOCK_EVENTS</exstyle>
        <bg>#1A1A1A</bg>
        <size>400,300</size>
        <title>Basic</title>
        <centered>1</centered>
        <object class="wxBoxSizer">
            <orient>wxVERTICAL</orient>
            <object class="sizeritem">
                <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
                <border>5</border>
                <object class="wxPanel" name="ID_PANEL">
                    <style>wxSUNKEN_BORDER|wxTAB_TRAVERSAL</style>
                    <bg>#c0c0c0</bg>
                    <object class="wxBoxSizer">
                        <orient>wxVERTICAL</orient>
                        <object class="sizeritem">
                            <flag>wxGROW|wxALL</flag>
                            <border>2</border>
                            <object class="wxBoxSizer">
                                <orient>wxVERTICAL</orient>
                                <object class="sizeritem">
                                    <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
                                    <border>5</border>
                                    <object class="wxButton" name="ID_BUTTON">
                                        <label>Button</label>
                                    </object>
                                </object>
                                <object class="sizeritem">
                                    <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag>
                                    <border>5</border>
                                    <object class="wxButton" name="ID_BUTTON1">
                                        <label>Button</label>
                                    </object>
                                </object>
                            </object>
                        </object>
                    </object>
                </object>
            </object>
        </object>
    </object>
</resource>

Under Linux, I get the "Handling event" string whenever I press a key on the keyboard, as long as one of the buttons has the focus. When I copy the same app to Windows, I get no "Handling event" output. I get the same behavior on all platforms if I am binding to the dialog or the buttons for the EVT_CHAR. The Linux platforms are behaving as I expected, with the Windows behavior unexpected. Any ideas why my Windows app cannot catch the EVT_CHAR events??? I'm stumped! Is there something special I have to do in Windows land to catch EVT_CHAR events??

Another related question. Under Linux, IsActive() is reporting False with the FindFocus() reporting no object with the focus. Under Windows IsActive() reports True with FindFocus() reporting the button object with the focus. The Windows behavior here is what I expected, while the Linux behavior was unexpected (just the opposite of my EVT_CHAR probems above). Any ideas as to why this is the case??? Could this behavior somehow be related to my EVT_CHAR issues described above??

I hope I have missed something really stupid here.

Thanks in advance

Jim
James@Galbraith.name

Hello James:

I don't know the answer, but just looking at this code, it
strikes me that there may be a problem with showing
the dialog before calling app.MainLoop(). It may be that
some or all events are dependant on that call. Just a thought.

···

On 11/22/05, James Galbraith <james.galbraith@inl.gov> wrote:

if __name__ == '__main__':
    app = wxPySimpleApp()
    frame = wxFrame(None, -1, "test")
    dlg = MyDialog(frame)
    app.MainLoop()