emmental/sidebar/pulser.py

54 lines
1.1 KiB
Python

# Copyright 2021 (c) Anna Schumaker.
from gi.repository import Gtk, GLib
import lib
import threading
Bar = Gtk.ProgressBar()
Threads = [ ]
Lock = threading.Lock()
Timeout = None
Bar.hide()
Bar.set_valign(Gtk.Align.CENTER)
Bar.set_hexpand(True)
Box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
Box.append(Gtk.Label.new(str=" "))
Box.append(Bar)
Box.append(Gtk.Label.new(str=" "))
def do_pulses():
global Timeout
Bar.pulse()
with Lock:
if not Threads[0].running():
Threads.pop(0)
if len(Threads) == 0:
Timeout = None
Bar.hide()
return GLib.SOURCE_REMOVE
return GLib.SOURCE_CONTINUE
def start_pulsing(thread):
global Timeout
with Lock:
Threads.append(thread)
if Timeout == None:
Timeout = GLib.timeout_add(100, do_pulses)
Bar.show()
def initialize():
lib.thread.Start.register(start_pulsing)
lib.bus.Start.register(start_pulsing)
initialize()
def reset():
global Timeout
with Lock:
Threads.clear()
if Timeout != None:
GLib.source_remove(Timeout)
Timeout = None
Bar.hide()