Best way to busy-wait in Python 3 / Gtk+ 3?
- From: Filip Lamparski <matka poohatka gmail com>
- To: "GTK+ App Development List" <gtk-app-devel-list gnome org>
- Subject: Best way to busy-wait in Python 3 / Gtk+ 3?
- Date: Sat, 6 Oct 2012 15:48:27 +0100
Hello,
I'm writing a simple application which is supposed to display the contents
of the TED RSS feed in a way similar to how the official app works on
Android.
However, the thumbnail loading process takes a long time, so I want to put
it into another process, with the GUI displaying a spinner or a progress
bar until the loading finishes.
I did not do anything with multiprocessing before, so I'm kind of stuck.
Here's my current code from the main runtime script:
from getted.tedtalk import TEDTalkWidgetfrom getted.window import
*from getted.tedlister import GetTEDTalksimport shutilimport osfrom
multiprocessing import Process
def load_ted_talks(twl):
print("Worker: Loading thumbnails")
tl = GetTEDTalks() # Gets list of TED Talks
for t in tl: # Convert TED Talks to widgets
twl.append(TEDTalkWidget(t))
print("Worker: {0}/{1} done".format(tl.index(t)+1, len(tl)))
print("Worker: Finished")
def do_quit (sender, e):
print('Quitting / Delete temporary files...')
shutil.rmtree('/tmp/getted')
Gtk.main_quit(sender, e)
def do_onload (sender):
print('Window ready, loading talks...')
talkwlist = []
p = Process(target=load_ted_talks, args=(talkwlist,))
p.start()
sender.populate_ted_talks(talkwlist)
if __name__ == '__main__':
print('Welcome to GetTED.')
getted_window = GetTEDWindow()
if not os.path.exists('/tmp/getted'):
print('Creating a directory for temporary files')
os.makedirs('/tmp/getted') # Create a temp directory for thumbnail files
getted_window.set_title("GetTED")
getted_window.connect('delete-event', do_quit)
getted_window.connect('show', do_onload)
print('Starting GetTED window...')
getted_window.show_all()
Gtk.main()
(Pastebin for those who see HTML here: http://pastebin.com/Afhzh3LD )
(GetTEDTalks is a function; I know this is breaking the convention but I'll
fix that later)
I have created a couple of different versions of load_ted_talks(), but all
of them either failed to load the thumbnails, loaded them but way after the
main process pushed associated widgets for the window to display, or
deadlocked.
If anybody has any suggestion on how can I make the application busy-wait
until the thumbnails finish loading (while keeping the GUI responsive),
then please tell me.
Thanks,
Filip
--
_____________________
Filip Lamparski - FB <https://www.facebook.com/filip.lamparski> -
G+<https://plus.google.com/105688569486178456264/posts>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]