rind: Start idle processing when a task has been queued

And stop the idle source when all tasks have been processed.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-04 13:45:34 -04:00
parent 6c7e063eac
commit 9af3d251c1
2 changed files with 12 additions and 4 deletions

View File

@ -18,6 +18,7 @@ class EmmentalApplication(Gtk.Application):
super().__init__(*args, application_id="org.gtk.emmental", **kwargs)
self.window = None
self.idle_id = None
curds.notify.register("task-queued", self.task_queued)
def do_activate(self):
if self.window == None:
@ -27,16 +28,20 @@ class EmmentalApplication(Gtk.Application):
def do_shutdown(self):
Gtk.Application.do_shutdown(self)
GLib.source_remove(self.idle_id)
if self.idle_id != None:
GLib.source_remove(self.idle_id)
curds.stop()
def do_startup(self):
Gtk.Application.do_startup(self)
self.idle_id = GLib.idle_add(self.on_idle)
def on_idle(self):
curds.notify.run_queued()
return GLib.SOURCE_CONTINUE
if curds.notify.run_queued() == False:
self.idle_id = None
return GLib.SOURCE_CONTINUE if self.idle_id else GLib.SOURCE_REMOVE
def task_queued(self):
self.idle_id = GLib.idle_add(self.on_idle)
def updown_toggled(self, *args):

View File

@ -20,6 +20,9 @@ class TestGtk(unittest.TestCase):
while gtk.Application.window == None:
time.sleep(0.1)
self.assertTrue(window.is_visible())
self.assertIsNone(gtk.Application.idle_id)
gtk.Application.task_queued()
self.assertGreater(gtk.Application.idle_id, 0)
gtk.Application.quit()
thread.stop()