Mouse event does not propagate to PyScrolledWindow

Hi,

I have in my code a PlotCanvas window, which is called in a PyScrolledWindow
In the PlotCanvas, I have declared a handler on mouse left up, which work well.
But I need to propagate the event to the PyScrolledWindow and this cannot work.
Any idea ? I am not very familiar with Python.
Here are some part of the code (simplified) :

class VariableCanvas(plot.PlotCanvas):
def init(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0, name=“plotCanvas”):
plot.PlotCanvas.init(self, parent, id, pos, size, style, name)
self.canvas.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)

def OnLeftUp(self, event):
    print "VARIABLE_CANVAS HANDLER OnLeftUp"
    event.Skip()

class VariablesViewer(wx.PyScrolledWindow):
def init(self, parent, manager, range=None):
self.canvas = None
gridsizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5)
gridsizer.AddGrowableCol(0)
gridsizer.AddGrowableRow(0)
self.MainSizer.AddSizer(gridsizer, 1, border=0, flag=wx.GROW)
# The graphic window : canvas
self.canvas = VariableCanvas(id=587, name="%s_canvas" ,
parent=self, pos=wx.Point(0, 0),
size=wx.Size(0, 0), style=wx.SUNKEN_BORDER)
self.canvas.SetMinSize(wx.Size(0, 150))
gridsizer.AddWindow(self.canvas, 0, border=0, flag=wx.GROW)
self.canvas.Bind(wx.EVT_LEFT_UP, self.VARIABLE_VIEWER_OnLeftUp)

def VARIABLE_VIEWER_OnLeftUp(self, event):
print “VARIABLES_VIEWER HANDLER OnLeftUp”

It goes in OnLeftUp(), but never goes in VARIABLE_VIEWER_OnLeftUp(). I have also tested the event EVT_SCROLL_THUMBRELEASE, without success.

Thank you to all.

···

Francis wrote:

Hi,

I have in my code a PlotCanvas window, which is called in a
PyScrolledWindow
In the PlotCanvas, I have declared a handler on mouse left up, which
work well.
But I need to propagate the event to the PyScrolledWindow and this
cannot work.
Any idea ? I am not very familiar with Python.

Events derived from wx.CommandEvent propagate up the containment hierarchy until they are handled (and not Skip()ed ) or until a top-level window is encountered. Events derived from wx.Event and not wx.CommandEvent do not propagate. They are only sent to the window where the event happened. Mouse events are in the latter category.

These two propagation flavors exist because most of the time it is not desirable for parents to be notified of the low-level events in their children, because of the overhead that would impose and also because most of the time the parents don't care about those kinds of events in their children. However once in a while it is desirable for parents to be notified of certain kinds of events in their children. There is a ResumePropagation method that can be called on the event object, but personally I don't like using it because it can cause confusion in the parent if it wants to deal with the same event for itself. Rather I typically just call a method in the parent, or to reduce coupling I might send a pubsub message that the parent (or anybody else) can subscribe to and use those for notification.

See also: self.Bind vs. self.button.Bind - wxPyWiki

···

--
Robin Dunn
Software Craftsman