Enter-Leave Event Order for Parent-Child Widgets

Hi folks,

The event order for entering/leaving a parent/child widget is different on Linux and Windows. On Linux it makes more sense to me with widget enter/leave events occurring in matched pairs. On Windows, the parent/child events get interleaved. Is this due to something OS-specific or a bug? I can code around it, but was curious. I'm using Python 2.5.4 and wxPython 2.8.9.2.

Here is some sample code. Run from a console window to see print statements.

#! /usr/bin/env python

'''Demo code for widget enter/leave event order'''

import wx

class MyFrame(wx.Frame):
     def __init__(self):
         wx.Frame.__init__(self, None, title='Enter/Leave Event Order Example', size=(200, 200))

         panel = wx.Panel(self)
         panel.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
         panel.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)

         button = wx.Button(panel, label='Button', pos=(50, 50))
         button.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
         button.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)

         self.count = 0

     def OnEnter(self, event):
         obj = event.GetEventObject()
         name = obj.GetName()
         print self.count, name, 'enter'
         self.count +=1
         event.Skip()

     def OnLeave(self, event):
         obj = event.GetEventObject()
         name = obj.GetName()
         print self.count, name, 'leave'
         self.count +=1
         event.Skip()

if __name__ == '__main__':
     app = wx.PySimpleApp()
     frame = MyFrame()
     frame.Show()
     app.MainLoop()

Thanks,
Dan

···

--
Dr. Daniel B. Koch
Oak Ridge National Lab
http://www.ornl.gov/sci/gist/bios/bio_koch.html
(865) 241-9096

Daniel B. Koch wrote:

Hi folks,

The event order for entering/leaving a parent/child widget is different on Linux and Windows. On Linux it makes more sense to me with widget enter/leave events occurring in matched pairs. On Windows, the parent/child events get interleaved. Is this due to something OS-specific or a bug?

OS-Specific. Order of delivery of events is one of the things that wx can not make totally consistent across platforms. In some cases they may differ even on different versions of the same platform.

···

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