pyGTK中的Visibility_notify事件

时间:2009-11-03 14:08:05

标签: python pygtk

我在Windows上,我正在开发一个pygtk应用程序。我需要知道窗口何时可见或被另一个窗口隐藏。为了阻止沉重的绘图过程。

http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#signal-gtkwidget--visibility-notify-event

我使用visibility_notify_event通知Windows可见性状态更改。 我应该得到gtk.gdk.VI​​SIBILITY_FULLY_OBSCURED,gtk.gdk.VI​​SIBILITY_PARTIAL或gtk.gdk.VI​​SIBILITY_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?

THX

1 个答案:

答案 0 :(得分:2)

基础GDK层很可能在Windows上“不够好”。众所周知,GTK +工具包到Windows的端口在功能和抛光方面有点滞后。

如果您可以在Linux机器上尝试相同的程序,并且它在那里工作,您可以非常肯定这是Windows端口的限制。