This commit is contained in:
Bas van den Heuvel 2019-08-21 18:26:59 +02:00
parent 0c4326eb31
commit f9132bd7fd

View file

@ -12,12 +12,14 @@ import bumblebee.input
import bumblebee.output import bumblebee.output
import bumblebee.engine import bumblebee.engine
def is_terminated(): def is_terminated():
for thread in threading.enumerate(): for thread in threading.enumerate():
if thread.name == "MainThread" and not thread.is_alive(): if thread.name == "MainThread" and not thread.is_alive():
return True return True
return False return False
def get_redshift_value(widget): def get_redshift_value(widget):
while True: while True:
if is_terminated(): if is_terminated():
@ -52,6 +54,7 @@ def get_redshift_value(widget):
widget.set("state", "transition") widget.set("state", "transition")
widget.set("transition", " ".join(line.split(" ")[2:])) widget.set("transition", " ".join(line.split(" ")[2:]))
class Module(bumblebee.engine.Module): class Module(bumblebee.engine.Module):
def __init__(self, engine, config): def __init__(self, engine, config):
widget = bumblebee.output.Widget(full_text=self.text) widget = bumblebee.output.Widget(full_text=self.text)
@ -59,7 +62,8 @@ class Module(bumblebee.engine.Module):
self._text = "" self._text = ""
self._condition = threading.Condition() self._condition = threading.Condition()
widget.set("condition", self._condition) widget.set("condition", self._condition)
self._thread = threading.Thread(target=get_redshift_value, args=(widget,)) self._thread = threading.Thread(target=get_redshift_value,
args=(widget,))
self._thread.start() self._thread.start()
self._condition.acquire() self._condition.acquire()
self._condition.notify() self._condition.notify()