[wxPython] catching event at different levels

Hi

I’d like to catch the same command event in two classes. I mean i have a button in a class derived from wxScrolledWindow. This button has an event (click) handler in the class. I’d like to add another handler in an upper class so that the two handlers are called on a click on the button.

---- Sample code ---- :

from wxPython.wx import *

class thing:

def init(self,parent,h,w):
self.btn=wxButton(parent,-1,“tutu”,pos=(0,0),size=(h,w))

EVT_BUTTON(self.btn,self.btn.GetId(),self.OnClick)

def OnClick(self,event):
print “thing-click”
event.Skip()

class MyFrame(wxFrame):
def init(self,w,h):
wxFrame.init(self,parent=NULL,id=-1,title=“test”,size=(w,h),pos=(0,0))
self.testThing=thing(self,w,h)
EVT_BUTTON(self.testThing.btn,self.testThing.btn.GetId(),self.OnThingClick)
self.Show(true)

def OnThingClick(self,event):
    print "waza-click"
    event.Skip()

class MyApp(wxApp):
def OnInit(self):
test=MyFrame(200,200)
self.SetTopWindow(test)
return true

app = MyApp(0)
app.MainLoop()

---- end ----

When the button is pressed, i wanted “waza-click” and “thing-click” to be printed but only “thing-click” is printed.

How can i do to have both handlers working ?

Thanks

Pierre

···

Get your FREE download of MSN Explorer at http://explorer.msn.com

evt.Skip() at the end of the “thing-click” handler. See the discussion on event handling in the wxWindows manual, or recent mailing list messages (try searching the archives for “evt.Skip()”…

Cheerio, Chris

···

Chris Fama mailto:Chris.Fama@whollysnakes.com
or mailto:Chris.Fama@uq.net.au
Brisbane, Australia
Phone: (0/+61)(7) 3870 5639 {10am-10pm GMT+10 on both these numbers please}
Mobile: (0/+61)(400) 833 700

Business page: <http://whollysnakes.com>
Personal page: <http://uq.net.au/~zzcfama>

----- Original Message -----

From:
pierre seillé

To: wxpython-users@lists.wxwindows.org

Sent: Wednesday, August 29, 2001 7:42 PM

Subject: [wxPython] catching event at different levels

Hi

I’d like to catch the same command event in two classes. I mean i have a button in a class derived from wxScrolledWindow. This button has an event (click) handler in the class. I’d like to add another handler in an upper class so that the two handlers are called on a click on the button.

---- Sample code ---- :

from wxPython.wx import *

class thing:

def init(self,parent,h,w):
self.btn=wxButton(parent,-1,“tutu”,pos=(0,0),size=(h,w))

EVT_BUTTON(self.btn,self.btn.GetId(),self.OnClick)

def OnClick(self,event):
print “thing-click”
event.Skip()

class MyFrame(wxFrame):
def init(self,w,h):
wxFrame.init(self,parent=NULL,id=-1,title=“test”,size=(w,h),pos=(0,0))
self.testThing=thing(self,w,h)
EVT_BUTTON(self.testThing.btn,self.testThing.btn.GetId(),self.OnThingClick)
self.Show(true)

  def OnThingClick(self,event):
      print "waza-click"
    event.Skip()

class MyApp(wxApp):
def OnInit(self):
test=MyFrame(200,200)
self.SetTopWindow(test)
return true

app = MyApp(0)
app.MainLoop()

---- end ----

When the button is pressed, i wanted “waza-click” and “thing-click” to be printed but only “thing-click” is printed.

How can i do to have both handlers working ?

Thanks

Pierre


Get your FREE download of MSN Explorer at http://explorer.msn.com
_______________________________________________ wxpython-users mailing list wxpython-users@lists.wxwindows.org http://lists.wxwindows.org/mailman/listinfo/wxpython-users

When the button is pressed, i wanted "waza-click" and
"thing-click" to be printed but only "thing-click" is printed.
How can i do to have both handlers working ?

In MyFrame.__init__ change the EVT_BUTTON to bind to self, not
self.testThing.btn, and take the self.Skip() out of the OnThingClick method.
Since the button click is a wxCommandEvent then it will travel up the
containment heirarchy if it is not caught or is skipped. I also expected
what you did to have worked, but something must have changed there, probably
an optimization. If you really need to bind the same event to the same
object then you can derive a class from wxEvtHandler and push an instance of
it onto the object with obj.PushEventHandler.

···

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

In MyFrame.__init__ change the EVT_BUTTON to bind to self, not
self.testThing.btn, and take the self.Skip() out of the OnThingClick

method.

Since the button click is a wxCommandEvent then it will travel up the
containment heirarchy if it is not caught or is skipped. I also expected
what you did to have worked, but something must have changed there,

probably

an optimization. If you really need to bind the same event to the same
object then you can derive a class from wxEvtHandler and push an instance

of

it onto the object with obj.PushEventHandler.

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

Thanks for the tip.
I didn't include all my code because the both handlers are pretty big. In
fact a class (an interface) containing a stand-alone class (visualisation
module with its own interface) and i wanted to add some functionnality to
the "click on the button" without changing this separate module.
Pierre