Skip to content

Instantly share code, notes, and snippets.

@campaul
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save campaul/3508998e67f93403cbc1 to your computer and use it in GitHub Desktop.
Save campaul/3508998e67f93403cbc1 to your computer and use it in GitHub Desktop.
Off main thread GTK example
# Inverted version of the first example from https://wiki.gnome.org/Projects/PyGObject/Threading
# GTK runs in the spawned thread instead of the other way around.
import threading
import time
from gi.repository import GLib, Gtk, GObject
# yay hacks
registry = {}
def app_main():
win = Gtk.Window(default_height=50, default_width=300)
win.connect("delete-event", Gtk.main_quit)
progress = Gtk.ProgressBar(show_text=True)
win.add(progress)
registry['progress'] = progress
win.show_all()
if __name__ == "__main__":
def start_gtk():
app_main()
Gtk.main()
thread = threading.Thread(target=start_gtk)
thread.daemon = True
thread.start()
def update_progess(i):
progress = registry['progress']
progress.pulse()
progress.set_text(str(i))
return False
for i in range(50):
GLib.idle_add(update_progess, i)
time.sleep(0.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment