Visibility_notify event in pyGTK
I am on windows and I am developing a pygtk app. I need to know when a window is visible or hidden by another window. In order to stop an heavy drawing process.
http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#signal-gtkwidget--visibility-notify-event
I Use the visibility_notify_event to be notified on windows visibility state change. I should get gtk.gdk.VISIBILITY_FULLY_OBSCURED, gtk.gdk.VISIBILITY_PARTIAL or gtk.gdk.VISIBILITY_UNOBSCURED
http://www.pygtk.org/docs/pygtk/class-gdkevent.html
here is a sample that display message when event occured.
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
class EventBoxExample:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Test")
window.connect("destroy", lambda w: gtk.main_quit())
window.set_border_width(10)
# Create an EventBox and add it to our toplevel window
self.event_box = gtk.EventBox()
window.add(self.event_box)
self.event_box.show()
#we want all events
self.event_box.set_events(gtk.gdk.ALL_EVENTS_MASK)
#connect events
self.event_box.connect ("map_event", self.Map)
self.event_box.connect ("unmap_event", self.unMap)
self.event_box.connect ("configure_event", self.Configure)
self.event_box.connect ("expose_event", self.Expose)
self.event_box.connect ("visibility_notify_event", self.Visibility)
self.event_box.connect ("key_press_event", self.KeyPress)
self.event_box.connect ("button_press_event", self.ButtonPress)
self.event_box.connect ("button_release_event", self.ButtonRelease)
self.event_box.connect ("motion_notify_event", self.MouseMotion)
self.event_box.connect ("destroy", self.Destroy)
self.event_box.connect ("enter_notify_event", self.Enter)
self.event_box.connect ("leave_notify_event", self.Leave)
self.event_box.connect ("delete_event", self.Destroy)
window.show()
def Map (self, *args):
print "Map ", args
return True
def unMap (self, *args):
print "unMap ", args
return True
def Configure (self, *args):
print "Configure"
return True
def Expose (self, *args):
print "Expose"
return True
def Visibility (self, *args):
print "Visibility"
return True
def KeyPress (self, *args):
print "KeyPress"
return True
def ButtonPress (self, *args):
print "ButtonPress"
return True
def ButtonRelease (self开发者_运维技巧, *args):
print "ButtonRelease"
return True
def MouseMotion (self, *args):
print "MouseMotion"
return True
def Enter (self, *args):
print "Enter"
self.event_box.grab_focus ()
return True
def Leave (self, *args):
print "Leave"
return True
def Destroy (self, *args):
print "Destroy"
def main():
gtk.main()
return 0
if __name__ == "__main__":
EventBoxExample()
main()
Does any one has any idea of why I can't get visibility_notify_event?
Thx
It's quite likely that the underlying GDK layer simply isn't "good enough" on Windows. The GTK+ toolkit's port to Windows is known to be a bit lagging in functionality and polish.
If you can try the same program on a Linux machine, and it works there, you can be pretty certain this is a limitation of the Windows port.
精彩评论