2014-02-10 44 views
1

我想隱藏FileChooserDialog,當我刪除它的窗口。 我可以從「取消」按鈕中隱藏它,但是當我從窗口關閉它時,它並沒有響應,然後崩潰。刪除FileChooserDialog的事件

View the crash here

當我做到這一點,在序列中的崩潰發生:

  • 我打開它(正常工作)

  • 我試圖從窗戶關閉'X'按鈕:'OK'和'CANCEL'按鈕消失並且FileFilter也一樣

  • 我重新嘗試關閉它。現在窗戶變白了:看起來沒有反應。
  • 我重新嘗試關閉它。它已關閉。
  • 我嘗試重新打開剛剛關閉的FileChooserDialog。它不再工作了,shell現在告訴我它是錯的。

我的代碼很簡單:

self.__apri_FileChooserDialog = Gtk.FileChooserDialog(title='', \ 
                   parent=None, \ 
                   action=Gtk.FileChooserAction.OPEN, \ 
                   buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, \ 
                   Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) 

self.__salva_FileChooserDialog.connect("delete-event", self.nascondi) 

def nascondi(self, widget, args=()): 
     widget.get_window().hide_on_delete() 

回答

2
def nascondi(self, widget, args=()): 
     widget.get_window().hide_on_delete() 

出於某種原因,你得到的對話框控件的GdkWindow這裏,並試圖調用GdkWindow沒有一個方法。這是行不通的...

在任何情況下,據我所知,hide_on_delete()在python中有點無用(因爲參數的數量與信號不匹配)。幸運的是,自己做並不困難。試試這個:

def on_delete_event (widget, event): 
    widget.hide() 
    return True 

self.__salva_FileChooserDialog.connect("delete-event", 
             on_delete_event) 
+1

2錯誤,也許最好的一個是:我是連接事件到錯誤的FileChooserDialog: – FrancescoN