2012-07-18 63 views
0

我正在設計一個小的GUI來與我寫的一段代碼進行接口。Gtk.main()阻塞在Gtk3接口

我的問題是,Gtk.main()命令似乎是阻止,即使我點擊銷燬按鈕時我的窗口關閉,我的終端仍然被絞死。

我也沒有看到任何信號交互。

這裏是我的示例:

#!/usr/bin/env python 

from gi.repository import Gtk, Gdk, GObject 

GObject.threads_init() 

class Ivolution():  

    def __init__(self): 

     print "in" 
     self.builder = Gtk.Builder() 
     self.builder.add_from_file("data/ui/IvolutionWindow.glade") 
     #builder.connect_signals({ "on_window_destroy" : gtk.main_quit }) 
     self.window = self.builder.get_object("ivolution_window") 
     print "in fin" 

    def on_stopbutton_clicked(self, widget): 
     """ 
     Asks the Facemovie thread to terminate 
     """ 
     print "Stop"  

    def on_ivolutionwindow_destroy(self, widget, data=None): 
     """Called when the IvolutionWindow is closed.""" 

     # Clean up code for saving application state should be added here. 
     print "Exiting" 
     Gtk.main_quit() 
     print "Exited" 

if __name__ == "__main__": 
    app = Ivolution() 
    print "deb" 
    app.window.show() 
    Gdk.threads_init() 
    Gdk.threads_enter() 
    print "but" 
    Gtk.main() 
    print "end" 
    Gdk.thread_leave() 
    print "ding" 

我刪除了所有非必要的部分。

Gobject和gdk.threads是我在互聯網上查看不同源代碼的測試。我不能想出他們的成功組合。

如果我運行該程序進入控制檯,這裏是我得到:

in 

(Ivolution.py:4635): Gtk-CRITICAL **: gtk_radio_button_set_group: assertion `!g_slist_find (group, radio_button)' failed 

(Ivolution.py:4635): Gtk-CRITICAL **: gtk_radio_button_set_group: assertion `!g_slist_find (group, radio_button)' failed 
in fin 
deb 
but 

即使我打的停止按鈕並關閉窗口。

一旦我關閉了我的窗口,控制檯保持不變,甚至ctrl + c也不會停止應用程序。

我確定我錯過了一些基本的東西,但作爲一個完整的GUI noob,我沒有看到什麼。 This sample code看起來真的很接近我的。任何想法?

回答

1

好吧,我在這裏同時感到既生氣又愚蠢。

我嘗試從我嘗試用Quickly

做我沒有在我的空地文件中定義的信號重用代碼。 出於某種原因,我不完全明白,快速讓您在沒有在glade文件中定義它們的情況下調用事件。

確定它無法工作。

釷Python代碼上面的正常工作,前提是你必須在你的空地文件

編輯定義正確的信號:

由於信息的補充,這裏是一個信號會是什麼樣子在林間空地文件

<signal name="delete-event" handler="on_destroy" swapped="no"/>