From b6eb3ee8e675d0f3a77d20ccfca4db29aeb0398e Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sun, 4 Dec 2016 16:14:43 +0100 Subject: [PATCH] [output/i3bar] Add flush method flush() terminates a single iteration of widget drawing. see #23 --- bumblebee-status | 5 ++++- bumblebee/engine.py | 1 + bumblebee/modules/test.py | 3 +++ bumblebee/output.py | 5 +++++ runlint.sh | 2 +- tests/test_i3baroutput.py | 6 ++++++ 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bumblebee-status b/bumblebee-status index b048a61..4d1cfe6 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -3,11 +3,14 @@ import sys import bumblebee.engine import bumblebee.config +import bumblebee.output def main(): config = bumblebee.config.Config(sys.argv[1:]) + output = bumblebee.output.I3BarOutput() engine = bumblebee.engine.Engine( - config=config + config=config, + output=output, ) engine.run() diff --git a/bumblebee/engine.py b/bumblebee/engine.py index 746556b..ddf6396 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -52,6 +52,7 @@ class Engine(object): for module in self._modules: widgets += module.widgets() self._output.draw(widgets) + self._output.flush() self._output.stop() diff --git a/bumblebee/modules/test.py b/bumblebee/modules/test.py index 028f742..79c0ec9 100644 --- a/bumblebee/modules/test.py +++ b/bumblebee/modules/test.py @@ -8,4 +8,7 @@ class Module(bumblebee.engine.Module): def __init__(self, engine): super(Module, self).__init__(engine) + def widgets(self): + return [] + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/output.py b/bumblebee/output.py index 3c08671..96ebe0b 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -29,4 +29,9 @@ class I3BarOutput(object): }) sys.stdout.write(json.dumps(result)) + def flush(self): + """Flushes output""" + sys.stdout.write(",\n") + sys.stdout.flush() + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/runlint.sh b/runlint.sh index 022534d..0555628 100755 --- a/runlint.sh +++ b/runlint.sh @@ -1,3 +1,3 @@ #!/bin/sh -find . -name "*.py"|xargs pylint --disable=R0903 +find . -name "*.py"|xargs pylint --disable=R0903,R0201 diff --git a/tests/test_i3baroutput.py b/tests/test_i3baroutput.py index 0ab88b8..c8e01e0 100644 --- a/tests/test_i3baroutput.py +++ b/tests/test_i3baroutput.py @@ -41,4 +41,10 @@ class TestI3BarOutput(unittest.TestCase): for res in result: self.assertEquals(res["full_text"], self.someWidget.text()) + @mock.patch("sys.stdout", new_callable=StringIO) + def test_flush(self, stdout): + self.output.flush() + self.assertEquals(",\n", stdout.getvalue()) + + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4