pulser: Hide the pulser when not pulsing

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-06-18 13:58:40 -04:00
parent dc86b1c32e
commit d98eca8533
2 changed files with 7 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Threads = [ ]
Lock = threading.Lock()
Timeout = None
Bar.hide()
Bar.set_valign(Gtk.Align.CENTER)
Bar.set_margin_start(10)
Bar.set_margin_end(10)
@ -21,6 +22,7 @@ def do_pulses():
if len(Threads) == 0:
Timeout = None
Bar.hide()
return GLib.SOURCE_REMOVE
return GLib.SOURCE_CONTINUE
@ -30,6 +32,7 @@ def start_pulsing(thread):
Threads.append(thread)
if Timeout == None:
Timeout = GLib.timeout_add(100, do_pulses)
Bar.show()
def initialize():
lib.thread.Start.register(start_pulsing)
@ -43,3 +46,4 @@ def reset():
if Timeout != None:
GLib.source_remove(Timeout)
Timeout = None
Bar.hide()

View File

@ -21,6 +21,7 @@ class TestUIPulser(unittest.TestCase):
self.assertIsInstance(pulser.Lock, type(threading.Lock()))
self.assertIsNone(pulser.Timeout)
self.assertFalse(pulser.Bar.get_visible())
self.assertEqual(pulser.Threads, [ ])
self.assertEqual(pulser.Bar.get_valign(), Gtk.Align.CENTER)
self.assertEqual(pulser.Bar.get_margin_start(), 10)
@ -37,6 +38,7 @@ class TestUIPulser(unittest.TestCase):
self.assertEqual(pulser.Threads, [ t1 ])
tid = pulser.Timeout
self.assertIsNotNone(tid)
self.assertTrue(pulser.Bar.get_visible())
pulser.start_pulsing(t2)
self.assertEqual(pulser.Threads, [ t1, t2 ])
@ -47,5 +49,6 @@ class TestUIPulser(unittest.TestCase):
pulser.do_pulses()
self.assertEqual(pulser.Threads, [ ])
self.assertIsNone(pulser.Timeout)
self.assertFalse(pulser.Bar.get_visible())
GLib.source_remove(tid)