James
James

Reputation: 47

wxpython bind mouse events to all panels?

hey all im looking for a way to bind a mouse event to all panels. basically im using wx.Window.FindFocus() to find which panel has the focus in my app of many panels. the problem is i want to bind the wx.LEFT_DOWN event to something to then put wx.Window.FindFocus() in the event handler. what to bind to tho? self, panel1, panel2 obviously wont work cos itll only call the event when clicking on that panel. i need something to catch clicks in anypanel so i can determine which panel has the focus? pls help!!!

Upvotes: 1

Views: 1793

Answers (1)

Mike Driscoll
Mike Driscoll

Reputation: 33071

If a wx.Panel has any children widgets that can accept focus, they will set focus to the first child that can take it. What this means is that wx.Panels don't usually get focus unless you set it explicitly...

If you need to catch clicks on the panel, then bind the wx.EVT_LEFT_DOWN event to the panels like this:

panelOne.Bind(wx.EVT_LEFT_DOWN, self.doSomething)

I think you can use HitTest to figure out what you clicked on, if that's even necessary. Heck, you can probably find out which panel it was by doing something like this in the event handler:

panel = event.GetEventObject()
panel_id = panel.GetId()
panel_name = panel.GetName()

Hope that helps!

Upvotes: 3

Related Questions