event binding and propagation

Question regarding event binding and propagation:

Is it possible to bind an event to a frame (the parent widget) even
though there are other widgets like panels on top of it? What I am
saying is, I have a frame that contains numerous panels and the frame
has a mouse motion event bound to itself (see code below). Now is it
possible that the mouse events are caught even though there are other
panels on top of the frame. Kind of like reversed propagation?

class MainFrame(wx.Frame):

    def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title)
            self.parent = parent
            self.initialize()

    def initialize(self):
            hbox = wx.BoxSizer(wx.HORIZONTAL)

            panel1 = wx.Panel(self, wx.ID_ANY)
            panel2 = wx.Panel(self, wx.ID_ANY)
            panel3 = wx.Panel(self, wx.ID_ANY)
            panel4 = wx.Panel(self, wx.ID_ANY)

            hbox.Add(panel1, 1, wx.EXPAND)
            hbox.Add(panel2, 1, wx.EXPAND)
            hbox.Add(panel3, 1, wx.EXPAND)
            hbox.Add(panel4, 1, wx.EXPAND)

            self.SetSizer(hbox)
            self.Centre()

            self.Bind(wx.EVT_MOTION, self.OnMotion)

    def OnMotion(self, event):

            xpt = wx.GetMousePosition()
            print "i am moving "+str(xpt)

class MyApp(wx.App):

    def OnInit(self):
            frame = MainFrame(None, -1, 'EXperiment')
            frame.Show(True)
            frame.SetPosition(wx.Point(0,0))
            frame.SetSize(wx.Size(1600,800))

            self.SetTopWindow(frame)
            return True

    app = MyApp(0)
    app.MainLoop()

Not sure if this is the right place for my question... Sorry. Dom

Hi,

···

On Mon, Sep 27, 2010 at 3:56 PM, dom <dominicwinkler@gmail.com> wrote:

Question regarding event binding and propagation:

Is it possible to bind an event to a frame (the parent widget) even
though there are other widgets like panels on top of it? What I am
saying is, I have a frame that contains numerous panels and the frame
has a mouse motion event bound to itself (see code below). Now is it
possible that the mouse events are caught even though there are other
panels on top of the frame. Kind of like reversed propagation?

The panel is contained by the frame it is not on top of it. Events
only propagate up the containment (parental) hierarchy not down. Also
only command events propagate. Mouse events are not command events so
they are only delivered to the window that they originate from.

Cody

Yes you are completely right. Sorry about my wording, the frame
contains the panels and I am aware that only command events like
button events propagate. However, with event.ResumePropagation()/
event.ShouldPropagate() it is possible to propagate non-command events
down the hierarchy. So my questions now is, if it is somehow possible
that events propagate up the containment hierarchy, so to say from
parent to child. How else can I bind a MouseEvent to a frame and catch
the event regardless of the other widgets the frame contains... Or is
the only way to do it to bind an event to each single widget contained
by the frame?

Cheers
Dom

···

On Sep 28, 10:37 am, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

On Mon, Sep 27, 2010 at 3:56 PM, dom <dominicwink...@gmail.com> wrote:
> Question regarding event binding and propagation:

> Is it possible to bind an event to a frame (the parent widget) even
> though there are other widgets like panels on top of it? What I am
> saying is, I have a frame that contains numerous panels and the frame
> has a mouse motion event bound to itself (see code below). Now is it
> possible that the mouse events are caught even though there are other
> panels on top of the frame. Kind of like reversed propagation?

The panel is contained by the frame it is not on top of it. Events
only propagate up the containment (parental) hierarchy not down. Also
only command events propagate. Mouse events are not command events so
they are only delivered to the window that they originate from.

Cody