Hello,
My usual problem: I have a threaded gtk app which doesn't thread.
Here is what it should do:
The user selects elements in the list and then presses a button. For
each selected element, a new thread should be started to do some
operations and update the clist.
Here is a sample output:
Begin doStartThreads
[1, 0]
Starting thread for row 0
Starting thread for row 1
End doStartThreads
This means that the function is called, the first two rows are selected
and that the threads have been started. The thread should print
"updateRow %d" % row but that doesn't happen.
The source is attached. My system is SuSE 6.0 (glibc based), thread
support has been compiled in every part (ie. python, glib, gtk+ and
gnome-libs).
--
Dipl. Inf. (FH) Aaron "Optimizer" Digulla Assistent im BIKS Labor, FB WI
"(to) optimize: Make a program faster by FH Konstanz, Brauneggerstr. 55
improving the algorithms rather than by Tel:+49-7531-206-514
buying a faster machine." EMail: [EMAIL PROTECTED]
#!/usr/bin/env python
import thread
import GTK
from gtk import *
def fillList():
"Fill the CList with some elements"
clist.clear ()
for c in ['test1', 'test2', 'test3']:
clist.append ((c,))
def doStartThreads (w):
"Call a function for each selected element"
print "Begin doStartThreads"
selection = clist.selection
print `selection`
def updateRow (n):
"This is the function to be called"
print 'updateRow',n
clist.set_text (n, 0, 'updated')
mainiteration (FALSE)
if selection:
selection.sort ()
for n in selection:
print 'Starting thread for row',n
thread.start_new_thread (updateRow, (n,))
print "End doStartThreads"
win = GtkWindow ()
win.set_title ("ThreadTest")
hbox = GtkHBox (homogeneous=FALSE)
win.add (hbox)
hbox.show ()
clist = GtkCList(1, (" Dummy ",))
hbox.add (clist)
clist.show ()
clist.set_selection_mode (SELECTION_EXTENDED)
fillList ()
vbox = GtkVBox (homogeneous=TRUE, spacing=5)
hbox.add (vbox)
vbox.show ()
def addButton (w,label,clickCB):
button = GtkButton (label)
w.add (button)
button.connect ("clicked", clickCB)
button.show ()
def doQuit (w):
mainquit ()
addButton (vbox, "Start Threads", doStartThreads)
addButton (vbox, "Quit", doQuit)
win.connect ("destroy", doQuit)
win.show ()
mainloop ()