[output] Add waiting capability to output

Engine now calls wait on output for further data, is interrupted
on new data.
This commit is contained in:
Tobias Witek 2016-11-04 21:10:21 +01:00
parent d62258c89d
commit ea27ccb2c1
2 changed files with 10 additions and 8 deletions

View file

@ -4,7 +4,6 @@ import glob
import pkgutil import pkgutil
import textwrap import textwrap
import argparse import argparse
import threading
import importlib import importlib
import bumblebee.theme import bumblebee.theme
@ -101,8 +100,6 @@ class Engine:
print self._output.start() print self._output.start()
sys.stdout.flush() sys.stdout.flush()
refresh = threading.Condition()
refresh.acquire()
while True: while True:
# improve this # improve this
self._theme.reset() self._theme.reset()
@ -111,7 +108,7 @@ class Engine:
self._theme.next() self._theme.next()
print self._output.get() print self._output.get()
sys.stdout.flush() sys.stdout.flush()
refresh.wait(self._args.interval) self._output.wait(self._args.interval)
print self._output.stop() print self._output.stop()

View file

@ -1,13 +1,15 @@
import threading
class Output(object): class Output(object):
def __init__(self, args): def __init__(self, args):
self._callbacks = {} self._callbacks = {}
self._wait = threading.Condition()
self._wait.acquire()
def redraw(self): def redraw(self):
pass self._wait.acquire()
self._refresh.acquire() self._wait.notify()
self._refresh.notify() self._wait.release()
self._refresh.release()
def add_callback(self, cmd, button, module=None): def add_callback(self, cmd, button, module=None):
if module: if module:
@ -29,6 +31,9 @@ class Output(object):
), None) ), None)
return cb return cb
def wait(self, interval):
self._wait.wait(interval)
def start(self): def start(self):
pass pass