2013-05-16 52 views
-1

當添加少量文件但當文件列表> 500時崩潰時,我的程序正常工作。將元素添加到TreeView/ListStore後,應用程序崩潰

錯誤:

The program 'gui.py' received an X Window System error. 
This probably reflects a bug in the program. 
The error was 'BadAlloc (insufficient resources for operation)'. 
    (Details: serial 14768 error_code 11 request_code 53 minor_code 0) 
    (Note to programmers: normally, X errors are reported asynchronously; 
    that is, you will receive the error a while after causing it. 
    To debug your program, run it with the --sync command line 
    option to change this behavior. You can then get a meaningful 
    backtrace from your debugger if you break on the gdk_x_error() function.) 

驗證碼:

self.tf_idf_document_list = gtk.ListStore(str) 
self.tf_idf_tree_documents.set_model(self.tf_idf_document_list) 
self.tf_idf_tree_column.set_attributes(self.tf_idf_renderer, text=0) 

在文件選擇我選擇與文件的文件夾,我將它們添加到列表中:

os.chdir(dir_name) 
    for file_name in os.listdir("."): 
     self.tf_idf_document_list.append([file_name]) 

任何建議如何修復這種BoF。

回答

1

從函數_gdk_x11_display_error_event中的gdkdisplay-x11.c觸發此錯誤。 這是由pygtk引起的?請嘗試gi模塊。我已經測試與python3和gi,有追加超過500項的liststore時沒有問題:

#!/usr/bin/env python3 

from gi.repository import Gtk 
import os 


def main(dir_name='.'): 
    win = Gtk.Window() 
    win.set_default_size(300, 400) 
    win.connect('destroy', Gtk.main_quit) 

    liststore = Gtk.ListStore(str) 
    i = 0 
    for file_name in os.listdir(dir_name): 
     i += 1 
     liststore.append([file_name]) 
    for file_name in os.listdir(dir_name): 
     i += 1 
     liststore.append([file_name]) 
    print('num of items:', i) 

    treeview = Gtk.TreeView() 
    treeview.set_model(liststore) 
    renderer_text = Gtk.CellRendererText() 
    column_text = Gtk.TreeViewColumn('File', renderer_text, text=0) 
    treeview.append_column(column_text) 

    scrolledwindow = Gtk.ScrolledWindow() 
    scrolledwindow.add(treeview) 
    win.add(scrolledwindow) 

    win.show_all() 
    Gtk.main() 

if __name__ == '__main__': 
    main('/usr/share') 
+0

真有這沒有錯誤,TNX) – badc0re

+0

,但爲什麼當我樹形視圖添加到Hbox我得到的錯誤,我認爲Hbox整個時間都在問題? – badc0re

+1

嘗試將樹視圖添加到滾動窗口中,並將該滾動窗口放入hbox/vbox中。 – LiuLang

相關問題