[wxPython] Chaining of EVT_CHAR handlers

Hello list,

I'm pretty new to wxPython. I now have a Problem with EVT_CHAR events:
On reading the event system dokumentation, I expected, that calling
event.Skip() within an event handler would chain to the next relevant
handler up the containment hirarchy.

In my test application, I have a wxPanel placed inside a wxFrame. The
wxPanel catches some keys, but most keys are unhandled and I call
event.Skip() on them. I have registered an event Handler vor EVT_CHAR
events in the wxFrame and would expect to receive all unhandled
EVT_CHAR events there, but this handler is never called. Is this the
expected behaviour and did I understand the dokumentation wrong or
should my Konzept work (and I made some stupid mistake on registering
the handlers ...)?

In code form:

from wxPython.wx import *
import sys

class MyPanel(wxPanel):
    def __init__(self,parent,id):
        wxPanel.__init__(self,parent,id)
        EVT_CHAR(self,self.OnChar)

    def OnChar(self,event):
        sys.stderr.write("MyPanel.OnChar\n")
        event.Skip()

class MyFrame(wxFrame):
    def __init__(self,title):
        wxFrame.__init__(self,None,-1,title,(-1,-1),(-1,-1))
        MyPanel(self,-1)
        EVT_CHAR(self,self.OnChar)

    def OnChar(self,event):
        sys.stderr.write("MyFrame.OnChar\n")
        event.Skip()

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame("EVT_CHAR test")
        frame.Show(true)
        self.SetTopWindow(frame)
        EVT_CLOSE(self,self.OnClose)
        return true

    def OnClose(self,event):
        self.Destroy()

app = MyApp(0)
app.MainLoop()

I would like this to call *both* MyPanel.OnChar and MyFrame.OnChar,
but only MyPanel.OnChar is called. What would be the correct way to
solve this Problem?

Stefan.

If I recall correctly, EVT_CHAR is a non-command event, so it doesn't chain
up the containment hierarchy. (Which is a pity, who wants to have to
remember that kind of stuff). So, you'd need to use something else to
propagate the events (like a command-based event).

HTH,
Mike

···

-----Original Message-----
From: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org]On Behalf Of Stefan
Bund
Sent: May 21, 2001 05:17
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython] Chaining of EVT_CHAR handlers
...
I'm pretty new to wxPython. I now have a Problem with EVT_CHAR events:
On reading the event system dokumentation, I expected, that calling
event.Skip() within an event handler would chain to the next relevant
handler up the containment hirarchy.
...

Both Win32 and SysV Unices have API for IPC (semaphores, shared mem, message
queues).
Not sure wether these are available in OS/2 or Mac though.

Maybe we could add uniform support for IPC on MSW and Unix to wxWindows?
Well, not sure if this would be useful for many people, but it would
certainly be very cool to have
those for wxPython app I am working on - it needs OS independant way to
communicate between
different parts of it (different applications, not just windows;)

At the moment I am using TCP sockets for this, but I had to write another
program to act as
a TCP server and commutate these different apps...

If IPC are available on majority of platforms which wxWindows run on - maybe
it is reasonable
to add support for them?

If everyone is too busy to actually implement, but agree that it wuld be a
good idea - I can write
code for SysV Unix and probably MSW too.

Jeekabs Andrushaitis
P.S. Well, I have doubt IPC would be useful for majority of wxWindows users
...

If I recall correctly, EVT_CHAR is a non-command event, so it doesn't

chain

up the containment hierarchy. (Which is a pity, who wants to have to
remember that kind of stuff). So, you'd need to use something else to
propagate the events (like a command-based event).

Or just bind the child's event handler to the parent's method.

If all events travelled up the child-parent chain then there would probably
a couple orders of magnitude of overhead for simple things like moving the
mouse, even if you don't catch the event anywhere.

The good news however is that there has been talk of figuring out a way to
selectivly specifiy which events should travel up to the parent.

···

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

Maybe we could add uniform support for IPC on MSW and Unix to wxWindows?
Well, not sure if this would be useful for many people, but it would
certainly be very cool to have
those for wxPython app I am working on - it needs OS independant way to
communicate between
different parts of it (different applications, not just windows;)

If you're wanting to do it in Python, then there are already several ways to
do IPC with Python modules or extensions. Look in the standard library or
at the Vaults of Parnassus

···

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

"Robin Dunn" <robin@alldunn.com> writes:

Or just bind the child's event handler to the parent's method.

Since I want to handle *some* keys in the child and some *other* keys
in the parent, this is not an option.

If all events travelled up the child-parent chain then there would probably
a couple orders of magnitude of overhead for simple things like moving the
mouse, even if you don't catch the event anywhere.

I understand.

The good news however is that there has been talk of figuring out a way to
selectivly specifiy which events should travel up to the parent.

My idea at the moment is, to catch the EVT_CHAR event and then convert
it to a userdefined command based event and only use the command based
event. As far as I understood the message from "Mike C. Fletcher"
<mcfletch@home.com>, <000401c0e206$e5fb80c0$010010ac@cr706570a>, this
should work. I will just try this now.

Thanks for all the help,

Stefan.

PS: I am a bit confused by the threading in my mail client: Is it OK
    in this lists terms to start a new thread just by replying to an
    existing thread and changing the Subject??? I don't want to start
    a debate, but on many mailing lists where I post, such practice is
    highly unwanted ...

"Robin Dunn" <robin@alldunn.com> writes:
> Or just bind the child's event handler to the parent's method.

Since I want to handle *some* keys in the child and some *other* keys
in the parent, this is not an option.

    EVT_CHAR(self, self.OnMyChar)
    EVT_CHAR(self.child, self.OnChildChar)

My idea at the moment is, to catch the EVT_CHAR event and then convert
it to a userdefined command based event and only use the command based
event. As far as I understood the message from "Mike C. Fletcher"
<mcfletch@home.com>, <000401c0e206$e5fb80c0$010010ac@cr706570a>, this
should work. I will just try this now.

Yep, that's a good idea too, especially if you're already set to catch the
command events generated by accelerators.

···

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