[pygtk] Is a bug in gtk.Menu - Motion/Enter/Leave_Notify Event ???

2004-03-04 Thread Martin . Zohlhuber
I want to make a menubar.deselect() when the mouse leave the application 
(i want avoid, that the popupmenu will still on top, if the user change 
into a other application). 

Problem: When the menu is popup i get only events from this menu. 
I can move the mousepointer around the toplevel window but i get the 
motion event from the menu. When i leave the toplevel window, i get a 
leave event from the menu. 

I think its wrong (bug), because leave the toplevelwindow i shout get the 
event from the window, not from the menu. 

The leave and enter event of the menu also occur, when i move the mouse in 
the popup menu and the menuitem change. I think this is not a very good 
implementation,  because the menu-widget was not leaved. 

For better understanding a add a small program. 

Have i make something wrong ? 
Is this a bug  ?  (use w2k, pygtk 2.0, gtk 2.2.4)
If it is correct - Why (and how can i  solve my problem) ?
Have somebody other the same failure ?

Thanks for any help !

martin

---
import gtk

def _cb_win_leave(widget, event, data=None):
print window leave, widget
def _cb_win_enter(widget, event, data=None):
print window enter, widget
def _cb_win_motion(widget, event, data=None):
print window motion, widget
def _cb_menu_leave(widget, event, data=None):
print _menu_ leave, widget
def _cb_menu_enter(widget, event, data=None):
print _menu_ enter, widget
def _cb_menu_motion(widget, event, data=None):
print _menu_ motion, widget


window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.show()
window.set_default_size(210, 300)
window.add_events(gtk.gdk.LEAVE_NOTIFY|gtk.gdk.ENTER_NOTIFY|gtk.gdk.MOTION_NOTIFY)
window.connect(leave_notify_event, _cb_win_leave)
window.connect(enter_notify_event, _cb_win_enter)
window.connect(motion_notify_event, _cb_win_motion)

menu_items = ( # menupath, accel, callback, callbackaction, itemtype, 
stock
 ( /File,  None,  None , 0, Branch ),
 ( /File/Open, None,  None , 1, None),
 ( /Edit,  None,  None , 0, Branch ),
 ( /Edit/Undo, None,  None , 1, None),
 ( /Edit/Cut, None,  None , 1, None),
 ( /Edit/Paste, None,  None , 1, None),
 ( /Edit/Copy, None,  None , 1, None)
 )

accel_group = gtk.AccelGroup()
item_factory = gtk.ItemFactory(gtk.MenuBar, main, accel_group)
item_factory.create_items(menu_items)
menubar = item_factory.get_widget(main)
menubar.show()
item = item_factory.get_widget(/Edit) 
item.add_events(gtk.gdk.LEAVE_NOTIFY|gtk.gdk.ENTER_NOTIFY|gtk.gdk.MOTION_NOTIFY)
item.connect(leave_notify_event, _cb_menu_leave)
item.connect(enter_notify_event, _cb_menu_enter)
item.connect(motion_notify_event, _cb_menu_motion)

item = item_factory.get_widget(/File) 
item.add_events(gtk.gdk.LEAVE_NOTIFY|gtk.gdk.ENTER_NOTIFY|gtk.gdk.MOTION_NOTIFY)
item.connect(leave_notify_event, _cb_menu_leave)
item.connect(enter_notify_event, _cb_menu_enter)
item.connect(motion_notify_event, _cb_menu_motion)

box = gtk.VBox()
box.show()
box.pack_start(menubar, gtk.FALSE, gtk.FALSE)
b = gtk.Button(Fill rest of the area)
b.connect(clicked, gtk.mainquit)
b.show()
box.pack_start(b)
window.add(box)
gtk.main()

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Is a bug in gtk.Menu - Motion/Enter/Leave_Notify Event ???

2004-03-04 Thread Martin Grimme
Am Do, den 04.03.2004 schrieb [EMAIL PROTECTED] um 15:20:
 I want to make a menubar.deselect() when the mouse leave the application 
 (i want avoid, that the popupmenu will still on top, if the user change 
 into a other application). 
 
 Problem: When the menu is popup i get only events from this menu. 
 I can move the mousepointer around the toplevel window but i get the 
 motion event from the menu. When i leave the toplevel window, i get a 
 leave event from the menu. 

Menu windows grab the mouse pointer globally. Therefore other windows
cannot receive events.

 I think its wrong (bug), because leave the toplevelwindow i shout get the 
 event from the window, not from the menu. 

The grabbing is not a bug but intentional. That way you can safely click
anywhere on the screen to close the menu without action.
 If it is correct - Why (and how can i  solve my problem) ?

If you really need to work around this, then consider implementing your
own menu widget instead of using the one of GTK.
Or you could run a timer that regularly checks if the mouse pointer is
still within the application window (gtk.Window.get_position(),
gtk.Window.get_size()) and close the menu if not.


Martin Grimme


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/