Mouse enter/leave events of a frame

Hi,

I'm having a problem with mouse enter/leave events. I am trying to write
a frame that automatically close it self if the mouse has left the
window for a while. However, I can't bind the event to the frame if the
frame has child panels which usually is the case. The panels cover the
frame so mouse enter/leave event of the frame will never trigger.

I tried to make all children of the frame posting the events to the
frame by calling wx.PostEvent in their event handling function, but this
will trigger the events when moving the mouse across different panels of
the frame and they cannot have their own handlers anymore.

Is there a solution for this? I mean, a frame's MouseEnter/MouseLeave
events are always called as long as the mouse is in the area if the
frame no matter what kind of children the frame is holding.

Many thanks

Andy

This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Please notify the sender by e-mail or telephone.
We utilise an anti-virus system and therefore any files sent via e-mail will have been checked for known viruses. You are however advised to run your own virus check before opening any attachments received as we will not in any event accept any liability whatsoever once an e-mail and/or any attachment is received. Any views expressed by an individual within this e-mail do not necessarily reflect the views of Systems Union Group plc or any of its subsidiary companies.

I know this is a very rudimentary solution, and I'm sure someone will
chip in with a solid solution involving the event handler.

I had a similar problem a while ago, and since it was for a minor set
of controls with the identical number and type of childrens (just 3
staticbitmaps and a statictext), what I did was to have all 4 four
windows (panel and childrens) to set/unset each one a particular bit
in a bitmask whenever there was an Enter_Window or Leave_Window event.
If the bitmask dropped to zero, then I knew they were not involved
with the position of the mouse.

-F

How about using a timer and checking to see it the mouse is inside the frame or outside the frame?
You will have to make sure that the mouse starts inside the frame or… implement some kind of a trigger mechanism
Like this:

import wx

class CustomFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None)
self.armed = False
self.t1 = wx.Timer(self)
self.t1.Start
(100)
self.Bind(wx.EVT_TIMER, self.OnTimer)

def OnTimer(self, evt):
    mouse_pos = wx.GetMousePosition()
    frame_pos = self.GetPosition()
    frame_size = self.GetSize

()
rect = wx.Rect(frame_pos[0], frame_pos[1], frame_size[0], frame_size[1])
if rect.Inside(mouse_pos) and not self.armed:
self.armed = True
print “Mouse captured. If the mouse leaves the frame it will die!”

    elif not rect.Inside(mouse_pos) and self.armed:
        print "I've warned you! Now the frame died!"
        self.Close()

app = wx.App(0)
frame = CustomFrame()

frame.Show()
app.MainLoop()

···

On 8/9/06, Andy Wu Andy_Wu@systemsunion.com wrote:

Is there a solution for this? I mean, a frame’s MouseEnter/MouseLeave
events are always called as long as the mouse is in the area if the
frame no matter what kind of children the frame is holding.