diff --git a/README.md b/README.md index 9adb18b..3822e52 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Test Coverage](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/badges/coverage.svg)](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/coverage) [![Issue Count](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/badges/issue_count.svg)](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status) -**Many, many thanks to all contributors! As of now, 22 of the modules are from various contributors (!), and only 16 from myself.** +**Many, many thanks to all contributors! As of now, 24 of the modules are from various contributors (!), and only 16 from myself.** bumblebee-status is a modular, theme-able status line generator for the [i3 window manager](https://i3wm.org/). diff --git a/bumblebee/modules/shortcut.py b/bumblebee/modules/shortcut.py new file mode 100644 index 0000000..2ec6ab3 --- /dev/null +++ b/bumblebee/modules/shortcut.py @@ -0,0 +1,70 @@ +# pylint: disable=C0112,R0903 + +"""Shows a widget per user-defined shortcut and allows to define the behaviour +when clicking on it. + +For more than one shortcut, the commands and labels are strings separated by +a demiliter (; semicolon by default). + +For example in order to create two shortcuts labeled A and B with commands +cmdA and cmdB you could do: + + ./bumblebee-status -m shortcut -p shortcut.cmd="ls;ps" shortcut.label="A;B" + +Parameters: + * shortcut.cmds : List of commands to execute + * shortcut.labels: List of widgets' labels (text) + * shortcut.delim : Commands and labels delimiter (; semicolon by default) +""" + +import logging +import bumblebee.engine +import bumblebee.output +import bumblebee.input + +LINK = "https://github.com/tobi-wan-kenobi/bumblebee-status/wiki" +LABEL = "Click me" + +class Module(bumblebee.engine.Module): + """ Shortcut module.""" + + def __init__(self, engine, config): + widgets = [] + self._engine = engine + super(Module, self).__init__(engine, config, widgets) + + self._labels = self.parameter("labels", "{}".format(LABEL)) + self._cmds = self.parameter("cmds", "firefox {}".format(LINK)) + self._delim = self.parameter("delim", ";") + + self.update_widgets(widgets) + + def update_widgets(self, widgets): + """ Creates a set of widget per user define shortcut.""" + + cmds = self._cmds.split(self._delim) + labels = self._labels.split(self._delim) + + # to be on the safe side create as many widgets as there are data (cmds or labels) + num_shortcuts = min(len(cmds), len(labels)) + + # report possible problem as a warning + if (len(cmds) is not len(labels)): + logging.warning("shortcut: the number of commands does not match "\ + "the number of provided labels.") + logging.warning("cmds : %s, labels : %s", cmds, labels) + + for idx in range(0, num_shortcuts): + cmd = cmds[idx] + label = labels[idx] + + widget = bumblebee.output.Widget(full_text=label) + self._engine.input.register_callback(widget, button=bumblebee.input.LEFT_MOUSE, cmd=cmd) + + widgets.append(widget) + + def update(self, widgets): + if len(widgets) <= 0: + self.update_widgets(widgets) + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/modules/uptime.py b/bumblebee/modules/uptime.py new file mode 100644 index 0000000..34e4085 --- /dev/null +++ b/bumblebee/modules/uptime.py @@ -0,0 +1,30 @@ +# pylint: disable=C0111,R0903 + +"""Displays the system uptime.""" + +# Use absolute_import because there's already a datatime module +# in the same directory +from __future__ import absolute_import + +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +from datetime import timedelta + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.output) + ) + self._uptime = "" + + def output(self, _): + return "{}".format(self._uptime) + + def update(self, widgets): + with open('/proc/uptime', 'r') as f: + uptime_seconds = int(float(f.readline().split()[0])) + self._uptime = timedelta(seconds = uptime_seconds) + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/screenshots/shortcut.png b/screenshots/shortcut.png new file mode 100644 index 0000000..96bce8c Binary files /dev/null and b/screenshots/shortcut.png differ diff --git a/screenshots/uptime.png b/screenshots/uptime.png new file mode 100644 index 0000000..489b212 Binary files /dev/null and b/screenshots/uptime.png differ diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index ca7be0e..347fcfd 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -86,5 +86,8 @@ }, "spotify": { "prefix": "" + }, + "uptime": { + "prefix": "uptime" } } diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 4628828..f8bd8cc 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -16,7 +16,8 @@ "layout": { "prefix": "" }, "layout-xkb": { "prefix": "" }, "todo": { "empty": {"prefix": "" }, - "items": {"prefix": "" } + "items": {"prefix": "" }, + "uptime": {"prefix": "" } }, "cmus": {