Re: leave_notify after click



Hi, Wilms. The following C program works as expected:

#include <gtk/gtk.h>

int
main (int argc, char *argv[])
{
  GtkWidget *window, *darea;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK
(gtk_main_quit), NULL);

  darea = gtk_drawing_area_new ();
  gtk_container_add (GTK_CONTAINER (window), darea);

  gtk_widget_set_events (darea, GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK);
  g_signal_connect_swapped (G_OBJECT (darea), "enter_notify_event",
G_CALLBACK (g_print), "enter_notify_event\n");
  g_signal_connect_swapped (G_OBJECT (darea), "leave_notify_event",
G_CALLBACK (g_print), "leave_notify_event\n");
  g_signal_connect_swapped (G_OBJECT (darea), "button_press_event",
G_CALLBACK (g_print), "button_press_event\n");
  g_signal_connect_swapped (G_OBJECT (darea), "button_release_event",
G_CALLBACK (g_print), "button_release_event\n");

  gtk_widget_show_all (window);

  gtk_main();
  return 0;
}

Button click on the drawing area propagates only two events (button
press and release). I am using GTK+ 2.12.9. Please try it and tell us
your results.

On Mon, 2008-04-07 at 21:59 +0200, Thorsten Wilms wrote:
> Hi!
> 
> I'm trying to write a custom widget using PyGTK and stumbled over a
> strange issue: Clicking a drawingarea triggers leave_notify and
> enter_notify (before button press and release can happen). That is,
here
> on Ubuntu with GTK+/PyGTK 2.12.0, but not on someone else's system
with
> 2.12.5/2.12.1.
> 
> I've been told it's not an PyGTK issue.
> 
> Which one is the desired behaviour? I hope it's to not trigger leave
by
> clicking, as I need a way to check if the mouse cursor just moved onto
> the widget or not.
> 
> My stripped down test code:
> -----
> #!/usr/bin/env python
> 
> import pygtk
> pygtk.require('2.0')
> import gtk
> from gtk import gdk
> import gobject
> 
> # Create new widget, inherit from gtk.DrawingArea
> class PopupScroller(gtk.DrawingArea):
> 
>       def __init__(self):
>               super(PopupScroller, self).__init__()
>               
>               # gtk.Widget signals
>               self.connect("enter_notify_event", self.enter_notify)
>               self.connect("leave_notify_event", self.leave_notify)
>               
>               # unmask events
>               self.add_events(gtk.gdk.ENTER_NOTIFY_MASK |
gtk.gdk.LEAVE_NOTIFY_MASK)
>                               
>       def enter_notify(self, widget, event):
>               print "enter"
>               #self.queue_draw()
>       
>       def leave_notify(self, widget, event):
>               print "leave"
>               #self.queue_draw()
>                                                                        
> def main():
>       window = gtk.Window()
>       scroller = PopupScroller()
> 
>       window.add(scroller)
>       scroller.set_size_request(100, 200)
>       
>       # Connect       
>       window.connect("destroy", gtk.main_quit)
>       #scroller.connect(signal, signal_cb)
> 
>       window.show_all()
>     
>       gtk.main()
>    
> if __name__ == "__main__":
>     main()
> 
> 
> 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]