I'm using Windows if that matters.
Bind event handlers for the mouse events to the panel.
--
Robin Dunn
Software Craftsman
http://wxPython.org
self.panel.Bind(wx.EVT_LEFT_DOWN, self.onMouseClick)
But couldn't get any events.
I am able to get some reaction from:
self.panel.Bind(wx.EVT_MOUSE_EVENTS, self.onMouseClick)
But the only events I'm getting from that is when the mouse first
enters the window, and first leaves.
Is there some other method of binding I should be using?
Here's my test:
"""test_panel.py - Testing wx.EVT_LEFT_DOWN event in a panel"""
import wx
class TestFrame(wx.Frame):
def __init__(self, parent, id, **kwargs):
""" Simple test frame"""
wx.Frame.__init__(self, parent, id, **kwargs)
self.panel = TestPanel(self, -1)
# Comment the following line to see the event handler from
TestPanel
self.panel.Bind(wx.EVT_LEFT_DOWN, self.onMouseClick)
self.Centre()
self.Show(True)
def onMouseClick(self, event):
print "Defined in TestFrame"
class TestPanel(wx.Panel):
"""Simple test panel"""
def __init__(self, parent, id, **kwargs):
wx.Panel.__init__(self, parent,size=(200,400))
self.Bind(wx.EVT_LEFT_DOWN, self.onMouseClick)
self.Show(True)
def onMouseClick(self, event):
print "Defined in TestPanel"
if __name__ == "__main__":
app = wx.PySimpleApp()
foo = TestFrame(None, -1, title="Testing Panels", size=(200,200))
app.MainLoop()
If the event is caught in the parent frame, it fires the handler
defined in TestFrame, but NOT the handler in TestPanel. When I comment
the event binding in TestFrame.__init__(), the handler
TestPanel.onMouseClick() is fired.
If this works for you, then the problem is somewhere else in the app.
Regards,
Joel
Is there some other child window that is covering the panel? If so you
should be binding to that window as it is the one that is getting the
events. Otherwise check if you are already intercepting the events from
the panel in some other binding.