Timer

S

Sam Bull

I'm writing a pyGTK program, and I need to display the contents of a
window for a few seconds before automatically moving on. I have tried
using the time.sleep method, but this has problems, such as the program
becoming unresponsive.

I have now attempted to use a timer, but this does not seem to run the
function at the end of the time. The code of my latest attempt:

def next(self=None, testnum=10, testspeed=5):
self.count += 1
#Sets label, telling the user the next word to memorise
self.nobtns.set_markup("Word %s is: %s" % (self.count,
self.words[self.count-1]))
self.nobtns.show()
if self.count == testnum: #When all words are shown
self.nobtns.hide()
else:
self.timer = threading.Timer(testspeed, self.next, [testnum,
testspeed])
self.timer.start()

Putting a print statement at the beginning of the function, I can see
that the function is not being run by the timer. Any help on getting
this working would be appreciated.

Thanks,
Sam Bull

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkugljAACgkQX+kozZYmzivkswCg5m7VeEdGyIZn6/3pzoFCXcHp
ytwAoIH3l9vl8s/OTnCBVILhzlwj7bD9
=RmJ6
-----END PGP SIGNATURE-----
 
P

Peter Otten

Sam said:
I'm writing a pyGTK program, and I need to display the contents of a
window for a few seconds before automatically moving on. I have tried
using the time.sleep method, but this has problems, such as the program
becoming unresponsive.

I have now attempted to use a timer, but this does not seem to run the
function at the end of the time. The code of my latest attempt:

def next(self=None, testnum=10, testspeed=5):
self.count += 1
#Sets label, telling the user the next word to memorise
self.nobtns.set_markup("Word %s is: %s" % (self.count,
self.words[self.count-1]))
self.nobtns.show()
if self.count == testnum: #When all words are shown
self.nobtns.hide()
else:
self.timer = threading.Timer(testspeed, self.next, [testnum,
testspeed])
self.timer.start()

Putting a print statement at the beginning of the function, I can see
that the function is not being run by the timer. Any help on getting
this working would be appreciated.

GUI toolkits usually have their own way of handling timeouts. I don't know
pygtk, but the following looks promising:

http://www.pygtk.org/pygtk2tutorial/ch-TimeoutsIOAndIdleFunctions.html

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top