pyGTK中的Visibility_notify事件
我在 Windows 上,正在开发一个 pygtk 应用程序。我需要知道一个窗口何时被另一个窗口可见或隐藏。为了停止繁重的拉拔过程。
http://www.pygtk .org/docs/pygtk/class-gtkwidget.html#signal-gtkwidget--visibility-notify-event
我使用visibility_notify_event在Windows可见性状态更改时收到通知。 我应该得到 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?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很可能底层 GDK 层在 Windows 上“不够好”。众所周知,GTK+ 工具包移植到 Windows 的功能和完善程度有些滞后。
如果您可以在 Linux 计算机上尝试相同的程序,并且它可以在那里运行,那么您可以非常确定这是 Windows 端口的限制。
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.