pyGTK中的Visibility_notify事件
我在Windows上开发一个pygtk应用程序。我需要知道一个窗口是可见的还是被另一个窗口遮住了。这样我才能停止一些比较耗资源的绘图过程。
http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#signal-gtkwidget--visibility-notify-event
我使用了visibility_notify_event来监听窗口可见状态的变化。这样我就能得到gtk.gdk.VISIBILITY_FULLY_OBSCURED(完全被遮挡)、gtk.gdk.VISIBILITY_PARTIAL(部分遮挡)或gtk.gdk.VISIBILITY_UNOBSCURED(完全可见)这几种状态。
http://www.pygtk.org/docs/pygtk/class-gdkevent.html
这里有一个示例,当事件发生时会显示消息。
#!/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()
有没有人知道为什么我收不到visibility_notify_event的通知呢?
谢谢!
1 个回答
2
很可能,底层的GDK层在Windows上并不是“足够好”。GTK+工具包在Windows上的移植功能和细节上都比较落后。
如果你能在Linux机器上试试同样的程序,并且它能正常运行,那你就可以很确定这是Windows版本的限制。