[modules/datetime] Re-enable datetime module
Add datetime module + aliases date and time. see #23
This commit is contained in:
parent
2fa8d7b778
commit
f40418475f
7 changed files with 51 additions and 4 deletions
|
@ -22,6 +22,10 @@ class Module(object):
|
|||
"""Return the widgets to draw for this module"""
|
||||
return self._widgets
|
||||
|
||||
def update(self, widgets):
|
||||
"""By default, update() is a NOP"""
|
||||
pass
|
||||
|
||||
class Engine(object):
|
||||
"""Engine for driving the application
|
||||
|
||||
|
|
1
bumblebee/modules/date.py
Symbolic link
1
bumblebee/modules/date.py
Symbolic link
|
@ -0,0 +1 @@
|
|||
datetime.py
|
31
bumblebee/modules/datetime.py
Normal file
31
bumblebee/modules/datetime.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
|
||||
"""Displays the current time, using the optional format string as input for strftime."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import datetime
|
||||
import bumblebee.engine
|
||||
|
||||
def default_format(module):
|
||||
default = "%x %X"
|
||||
if module == "date":
|
||||
default = "%x"
|
||||
if module == "time":
|
||||
default = "%X"
|
||||
return default
|
||||
|
||||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine):
|
||||
super(Module, self).__init__(engine,
|
||||
bumblebee.output.Widget(full_text=self.get_time)
|
||||
)
|
||||
module = self.__module__.split(".")[-1]
|
||||
|
||||
self._fmt = default_format(module)
|
||||
|
||||
# self._fmt = self._config.parameter("format", default_format(module))
|
||||
|
||||
def get_time(self):
|
||||
return datetime.datetime.now().strftime(self._fmt)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
1
bumblebee/modules/time.py
Symbolic link
1
bumblebee/modules/time.py
Symbolic link
|
@ -0,0 +1 @@
|
|||
datetime.py
|
|
@ -12,9 +12,14 @@ class Widget(object):
|
|||
self._module = None
|
||||
|
||||
def set_module(self, module):
|
||||
"""Set the module that spawned this widget
|
||||
|
||||
This is done outside the constructor to avoid having to
|
||||
pass in the module name in every concrete module implementation"""
|
||||
self._module = module.name
|
||||
|
||||
def module(self):
|
||||
"""Return the name of the module that spawned this widget"""
|
||||
return self._module
|
||||
|
||||
def full_text(self):
|
||||
|
|
|
@ -31,10 +31,12 @@ class Theme(object):
|
|||
return self._get(widget, "suffix", None)
|
||||
|
||||
def loads(self, data):
|
||||
"""Initialize the theme from a JSON string"""
|
||||
theme = json.loads(data)
|
||||
self._init(theme)
|
||||
|
||||
def _load_icons(self, name):
|
||||
"""Load icons for a theme"""
|
||||
path = "{}/icons/".format(theme_path())
|
||||
return self.load(name, path=path)
|
||||
|
||||
|
@ -52,7 +54,7 @@ class Theme(object):
|
|||
raise bumblebee.error.ThemeLoadError("no such theme: {}".format(name))
|
||||
|
||||
def _get(self, widget, name, default=None):
|
||||
|
||||
"""Return the config value 'name' for 'widget'"""
|
||||
module_theme = self._theme.get(widget.module(), {})
|
||||
|
||||
padding = None
|
||||
|
@ -71,6 +73,7 @@ class Theme(object):
|
|||
# http://blog.impressiver.com/post/31434674390/deep-merge-multiple-python-dicts
|
||||
# nicely done :)
|
||||
def _merge(self, target, *args):
|
||||
"""Merge two arbitrarily nested data structures"""
|
||||
if len(args) > 1:
|
||||
for item in args:
|
||||
self._merge(item)
|
||||
|
|
|
@ -44,7 +44,7 @@ class TestI3BarOutput(unittest.TestCase):
|
|||
self.output.flush()
|
||||
result = json.loads(stdout.getvalue())
|
||||
for res in result:
|
||||
self.assertEquals(res["full_text"], widget.full_text())
|
||||
self.assertEquals(res["full_text"], self.someWidget.full_text())
|
||||
|
||||
@mock.patch("sys.stdout", new_callable=StringIO)
|
||||
def test_begin(self, stdout):
|
||||
|
@ -84,7 +84,9 @@ class TestI3BarOutput(unittest.TestCase):
|
|||
self.output.flush()
|
||||
result = json.loads(stdout.getvalue())[0]
|
||||
self.assertEquals(result["full_text"], "{}{}{}".format(
|
||||
self.theme.prefix(self.someWidget), self.someWidget.full_text(), self.theme.suffix(self.someWidget))
|
||||
)
|
||||
self.theme.prefix(self.someWidget),
|
||||
self.someWidget.full_text(),
|
||||
self.theme.suffix(self.someWidget)
|
||||
))
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Reference in a new issue