[modules/title] Python < 3.4 compatibility

Replace textwrap.shorten() with custom implementation, since it is only
available since Python 3.4. While at it, catch i3 exceptions in order to
make unit tests (hopefully) run through.

Also, Updated README.md

see #174
This commit is contained in:
Tobias Witek 2017-09-15 20:00:57 +02:00
parent 776824323b
commit ecbde508d2
3 changed files with 8 additions and 9 deletions

View file

@ -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) [![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) [![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, 21 of the modules are from various contributors (!), and only 16 from myself.** **Many, many thanks to all contributors! As of now, 22 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/). bumblebee-status is a modular, theme-able status line generator for the [i3 window manager](https://i3wm.org/).

View file

@ -15,7 +15,6 @@ try:
except ImportError: except ImportError:
pass pass
import textwrap
import bumblebee.util import bumblebee.util
import bumblebee.input import bumblebee.input
import bumblebee.output import bumblebee.output
@ -33,13 +32,13 @@ class Module(bumblebee.engine.Module):
self._i3 = i3ipc.Connection() self._i3 = i3ipc.Connection()
self._full_title = self._i3.get_tree().find_focused().name self._full_title = self._i3.get_tree().find_focused().name
def focused_title(self): def focused_title(self, widget):
"""Truncates and returns proper-length title.""" title = self._full_title[0:self.parameter("max", 64)]
return textwrap.shorten( if title != self._full_title:
self._full_title, title = self._full_title[0:self.parameter("max", 64) - 3]
width=float(self.parameter("max", 64)), title = "{}...".format(title)
placeholder=self.parameter("placeholder", "...")
) return title
def update(self, widgets): def update(self, widgets):
"""Update current title.""" """Update current title."""

BIN
screenshots/title.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB