-- test.py
import threading import time
import pygtk
pygtk.require('2.0')
import gtk
class CGuiModifyThread(threading.Thread): def __init__(self, gui): threading.Thread.__init__(self) self.gui = gui self.done = 0
def run(self):
i = 0
while (i < 10):
i = i + 1
gtk.threads_enter ()
gui.addpage_cb(None)
gtk.threads_leave ()
time.sleep(.2)
Done = 1
print "Thread done"class CGui(gtk.Window):
def __init__(self):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
self.connect("destroy", self.destroy_cb)
self.vbox = gtk.VBox()
self.add(self.vbox)
self.checkbutton = gtk.CheckButton("Try to get iter")
self.checkbutton.set_active(1)
self.vbox.pack_start(self.checkbutton, gtk.FALSE, gtk.FALSE, 0)
self.startbutton = gtk.Button("start thread")
self.startbutton.connect("clicked", self.start_cb)
self.vbox.pack_start(self.startbutton, gtk.FALSE, gtk.FALSE, 0)
self.addpage = gtk.Button("Add page to notebook")
self.addpage.connect("clicked", self.addpage_cb)
self.vbox.pack_start(self.addpage, gtk.FALSE, gtk.FALSE, 0)
self.notebook = gtk.Notebook()
self.vbox.pack_start(self.notebook, gtk.FALSE, gtk.FALSE, 0)
self.startbutton.show()
self.addpage.show()
self.notebook.show()
self.vbox.show() def start_cb(self, data):
print "Starting thread"
self.modifyth = CGuiModifyThread (self)
self.modifyth.start()def destroy_cb(self,*args): self.hide()
gtk.mainquit()
def addpage_cb(self, data):
textview = gtk.TextView()
textbuffer = gtk.TextBuffer(None)
textview.set_buffer(textbuffer)
if (self.checkbutton.get_active()):
print "Getting iter"
iter = textbuffer.get_iter_at_offset(0)
print "Done"
textbuffer.insert(iter, "Hello World\n")
self.notebook.add(textview)
textview.show()gtk.threads_init () gtk.threads_enter () gui = CGui() gui.show_all() gtk.mainloop () gtk.threads_leave()
-- end
If you dont get iter while running thread, everything's OK. If you get iter from the mainloop it's ok. But if you get iter from a child thread everything freezes.
Is there any big mistake in this code (except it was made in 2 minutes)?
Thanks
-- Philippe Sam-Long [EMAIL PROTECTED] http://purplemonk.doesntexist.com
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
