Python3 gi:GtkTextBuffer核心转储

时间:2015-05-12 09:09:09

标签: python python-3.x gtk pygtk glade

将Python3与gi.repository.Gtk一起使用,我试图通过GtkTextViewGtkTextBuffer内显示多个文字行。

基本上,我使用_addLine方法动态添加行,该方法以某种方式更新文本缓冲区(self._lines是一个数组,self._textBuffer是{{1} }):

GtkTextBuffer

不幸的是,在def _addLine(self, text): if len(self._lines) == self._maxLines: self._lines = self._lines[1:] self._lines.append(text) content = '\n'.join(self._lines) print("TIC: %d" % len(content)) self._textBuffer.set_text(content) print("TAC") 的随机值(低于或大于i),我随机地在" TIC"之间获得核心转储。和" TAC",所以当我尝试设置缓冲区的内容时。

此方法由线程调用,自己从构造函数调用(在所有GUI元素初始化之后):

self._maxLines

我正在使用如下结构的Glade构建器:

def _startUpdateThread(self):
    thread = threading.Thread(target=lambda: self._updateLoop())
    thread.daemon = True
    thread.start()

def _updateLoop(self):
    i=0
    for l in listings.tail(self._logFile, follow=True, n=1000):
        i+=1
        print("i=%d, nLines=%d" % (i, len(self._lines)))
        self._addLine(l)

我做错了什么?核心转储的原因是什么?

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:3)

当您从线程而不是GTK主循环修改窗口小部件时,应该使用GLib.idle_add()

在这种情况下:

GLib.idle_add(self._textBuffer.set_text, content)
相关问题