python - Python3 gi: GtkTextBuffer core dump -
using python3 gi.repository.gtk
, i'm trying display multiple text lines inside gtktextview
via gtktextbuffer
.
basically, i'm dynamically adding lines using _addline
method, updates text buffer way (self._lines
array , self._textbuffer
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")
unfortunately, @ random values of i
(either lower or bigger self._maxlines
), randomly core dump between "tic" , "tac", when try set content of buffer.
this method called threading, himself called constructor (after gui elements initialized):
def _startupdatethread(self): thread = threading.thread(target=lambda: self._updateloop()) thread.daemon = true thread.start() def _updateloop(self): i=0 l in listings.tail(self._logfile, follow=true, n=1000): i+=1 print("i=%d, nlines=%d" % (i, len(self._lines))) self._addline(l)
i'm using glade builder structured below:
gtkwindow - gtkvbox - gtkscrolledwindow - gtktextview (linked gtktextbuffer) - gtkbutton (to close window) - gtktextbuffer
what did wrong? cause of core dump?
thanks lot help.
you should use glib.idle_add()
when modifying widgets thread , not gtk main loop.
in case:
glib.idle_add(self._textbuffer.set_text, content)
Comments
Post a Comment