From 55f48d561877a11febc2e5cb09621d5519251c24 Mon Sep 17 00:00:00 2001 From: Pier-Angelo Gaetani Date: Fri, 15 Sep 2017 09:51:14 -0600 Subject: [PATCH 1/3] Added title module. --- bumblebee/modules/title.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 bumblebee/modules/title.py diff --git a/bumblebee/modules/title.py b/bumblebee/modules/title.py new file mode 100644 index 0000000..f062214 --- /dev/null +++ b/bumblebee/modules/title.py @@ -0,0 +1,46 @@ +# pylint: disable=C0111,R0903 + +"""Displays focused i3 window title. + +Requirements: + * i3ipc + +Parameters: + * title.max : Maximum character length for title before truncating. Defaults to 64. + * title.placeholder : Placeholder text to be placed if title was truncated. Defaults to "...". +""" + +try: + import i3ipc +except ImportError: + pass + +import bumblebee.util +import bumblebee.input +import bumblebee.output +import bumblebee.engine +import textwrap + +class Module(bumblebee.engine.Module): + """Window title module.""" + + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.focused_title) + ) + self._i3 = i3ipc.Connection() + self._full_title = self._i3.get_tree().find_focused().name + + def focused_title(self, widget): + """Truncates and returns proper-length title.""" + return textwrap.shorten( + self._full_title, + width=float(self.parameter("max", 64)), + placeholder=self.parameter("placeholder", "...") + ) + + def update(self, widgets): + """Update current title.""" + self._full_title = self._i3.get_tree().find_focused().name + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 8bba1d1e0dd6160ae1084e49cee6a82fe1f80211 Mon Sep 17 00:00:00 2001 From: Pier-Angelo Gaetani Date: Fri, 15 Sep 2017 10:03:58 -0600 Subject: [PATCH 2/3] [module/title] Requirement update in README.md + linting --- README.md | 1 + bumblebee/modules/title.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c8b6c6..001cb69 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ Modules and commandline utilities are only required for modules, the core itself * requests (for the modules 'weather', 'github', 'getcrypto', 'stock') * power (for the module 'battery') * dbus (for the module 'spotify') +* i3rpc (for the module 'title') # Required commandline utilities diff --git a/bumblebee/modules/title.py b/bumblebee/modules/title.py index f062214..0bf0589 100644 --- a/bumblebee/modules/title.py +++ b/bumblebee/modules/title.py @@ -15,23 +15,25 @@ try: except ImportError: pass +import textwrap import bumblebee.util import bumblebee.input import bumblebee.output import bumblebee.engine -import textwrap class Module(bumblebee.engine.Module): """Window title module.""" def __init__(self, engine, config): - super(Module, self).__init__(engine, config, + super(Module, self).__init__( + engine, + config, bumblebee.output.Widget(full_text=self.focused_title) ) self._i3 = i3ipc.Connection() self._full_title = self._i3.get_tree().find_focused().name - def focused_title(self, widget): + def focused_title(self): """Truncates and returns proper-length title.""" return textwrap.shorten( self._full_title, From ad1832a57d145f61737c784de0d8971ba2a5671b Mon Sep 17 00:00:00 2001 From: Pier-Angelo Gaetani Date: Fri, 15 Sep 2017 10:36:20 -0600 Subject: [PATCH 3/3] [module/title] Added pip dependency to travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0e198ad..61e1ff9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ python: - "3.5" - "3.6" install: + - pip install i3ipc - pip install psutil - pip install netifaces - pip install -U coverage==4.3