I'm having problems with button.connect() which puzzle me.  I've attached
a simple example program which was extracted from a much larger program.

Clicking "start TASK" starts the TASK function, which opens a status
window and updates the label ten times a second.  Every time I click
"start TASK" before the current TASK finishes, the current TASK is
interrupted and a new TASK is started.  When the newer TASK finishes,
the interrupted TASK proceeds to completion.  (Absent threads, it is
quite reasonable that one TASK would displace another in this nested
manner.  I know how to prevent this nesting if that's desired.)

If TASK is not running, clicking the "QUIT" button invokes quit_pgm,
but if I click "QUIT" while the first TASK is running, I see a new
TASK started!

If I click "QUIT" before the second TASK finishes, a third instance
starts, but surprisingly if I click "QUIT" after the second or third
loop terminates, quit_pgm is called and the main window goes away.

I haven't got much further in the analysis, but it looks like the
button connections follow these rules (where each entry to state
1 starts TASK):
                                 click
      event | click "QUIT" | "start TASK" | TASK exit
      ------+--------------+--------------+----------
state 0     |    exit      |      1       |   N/A
      1     |      1       |      1       |    0

In confirmation of this observation, I've found that while TASK
is running, the "QUIT" button no longer shows a PRELIGHT color,
and the "start TASK" button shows the ACTIVE color.  This holds
until one instance of TASK has finished.

I'm about to rewrite this example in C, just to see if the problem
is fundamental to GTK, but meanwhile I'd like to see if anyone
can identify a problem in my code.  Is this behavior some function
of widget state?

-- 
Randolph Bentson
[EMAIL PROTECTED]

#!/usr/bin/python -v
from gtk import *   # from pygtk
import time

def quit_pgm(*args):
    print "Quit Pgm"
    win.hide()
    mainquit()

def TASK(*args):
    newin = GtkWindow()
    lbl = GtkLabel('__')
    newin.add(lbl)
    lbl.show()
    newin.show()

    for i in range(0,50):
        lbl.set_text('%d'%i)
        time.sleep(0.1)
        while events_pending(): mainiteration()
    newin.hide()

rc_parse("gtkrc")

win = GtkWindow()

vbox0 = GtkVBox()
win.add(vbox0)

btn1 = GtkButton(' start TASK ')
btn1.connect("button_release_event", TASK)
vbox0.pack_start(btn1,FALSE,FALSE)

btn2 = GtkButton(' QUIT ')
btn2.connect("button_release_event", quit_pgm)
vbox0.pack_start(btn2,FALSE,FALSE)

vbox0.show()
btn1.show()
btn2.show()
win.show()

mainloop()

Reply via email to