PDA

View Full Version : This Day in History Screenlet - Question


jackkerouac
August 8th, 2007, 03:53 AM
I am currently working on a This Day in History screenlet:

http://img467.imageshack.us/img467/9492/screenshot1pq2.th.png (http://img467.imageshack.us/my.php?image=screenshot1pq2.png)

But I need a little help. How do I make the screenlet update once every 24 hours? Thanks for the help!

nomego
August 8th, 2007, 06:09 AM
You could take a look at these screenlets: Word of the Day, Stocks, Horoscope, Wireless, etc..

mikedee
August 8th, 2007, 11:24 AM
The easiest way would probably be to create an infinite loop which just waits 24 hours inside it. If you start something like this when the screenlet is loaded it should work.

while True:
self.update_data ()
os.sleep (60 * 60 * 24) # sleep for 24 hours

I am not sure how the screenlets framework works, but something like that should work.

RYX
August 8th, 2007, 11:32 AM
I recommend using a timeout-function for that because the whole screenlets-framework is (currently) using gtk as underlying toolkit.import gobject
def callback_function (event):
print "24 hours passed"
self.redraw_canvas()
timeout = gobject.timeout_add(24 * 60 * 60 * 1000, callback_function)
# remove with
gobject.source_remove(timeout)

:)