[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:
parent
776824323b
commit
ecbde508d2
3 changed files with 8 additions and 9 deletions
|
@ -15,7 +15,6 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
import textwrap
|
||||
import bumblebee.util
|
||||
import bumblebee.input
|
||||
import bumblebee.output
|
||||
|
@ -33,13 +32,13 @@ class Module(bumblebee.engine.Module):
|
|||
self._i3 = i3ipc.Connection()
|
||||
self._full_title = self._i3.get_tree().find_focused().name
|
||||
|
||||
def focused_title(self):
|
||||
"""Truncates and returns proper-length title."""
|
||||
return textwrap.shorten(
|
||||
self._full_title,
|
||||
width=float(self.parameter("max", 64)),
|
||||
placeholder=self.parameter("placeholder", "...")
|
||||
)
|
||||
def focused_title(self, widget):
|
||||
title = self._full_title[0:self.parameter("max", 64)]
|
||||
if title != self._full_title:
|
||||
title = self._full_title[0:self.parameter("max", 64) - 3]
|
||||
title = "{}...".format(title)
|
||||
|
||||
return title
|
||||
|
||||
def update(self, widgets):
|
||||
"""Update current title."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue