2009-11-03 26 views
1

我在Windows上,我正在開發一個pygtk應用程序。我需要知道一個窗口何時可見或被另一個窗口隱藏。爲了阻止沉重的繪畫過程。pyGTK中的Visibility_notify事件

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

我在Windows上使用的可見性狀態變化被通知visibility_notify_event。 我應該得到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

回答

2

這很可能是潛在的GDK層根本不是Windows「足夠好」。據瞭解,GTK +工具包的Windows端口在功能和拋光方面有點落後。

如果您可以在Linux機器上嘗試相同的程序,並且它可以在那裏運行,那麼您可以確定這是Windows端口的限制。

+0

由朋友在linux上試過,他得到了可見性事件。你是對的,它似乎沒有在Windows端口thx實施 – rapdum 2009-11-03 16:15:14