My collection of plugins for the Qtile window manager.
git clone https://mcol.xyz/code/qtools
Log | Files | Refs | README

commit 8dbf615a323b1de2242c2a6405f3209c4d7bcf5a
parent a199c440605e99bebad2262a7903ba220579d2d2
Author: mcol <mcol@posteo.net>
Date:   Sat, 11 Jan 2020 11:45:36 +0000

fix timeout and config setting

Diffstat:
M__init__.py | 29+++++++++++++++--------------
Mamixer/amixer.py | 5++++-
Mmpc/mpc.py | 3+--
3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/__init__.py b/__init__.py @@ -28,9 +28,12 @@ class Notifier(Configurable): Notifier._is_initted = True Notify.init('Qtile') - Configurable.__init__(self) + Configurable.__init__(self, **config) self.add_defaults(Notifier.defaults) - self._notifier = None + self.notifier = Notify.Notification.new( + config.get('summary', 'Notifier'), '' + ) + self.timeout = config.get('timeout', -1) def __getattr__(self, name): """ @@ -42,21 +45,19 @@ class Notifier(Configurable): return Configurable.__getattr__(self, name) @property - def notifier(self): - if self._notifier is None: - self._notifier = Notify.Notification.new(self.summary, '') - self._notifier.set_timeout(self.timeout) - return self._notifier + def timeout(self): + return self._timeout - def set_timeout(self, timeout): - self.notifier.set_timeout(timeout) - self.timeout = timeout + @timeout.setter + def timeout(self, value): + self.notifier.set_timeout(value) + self._timeout = value - def show(self): + def show(self, body): + if not isinstance(body, str): + body = str(body) + self.notifier.update(self.summary, body) self.notifier.show() def hide(self): self.notifier.hide() - - def update(self, body): - self.notifier.update(self.summary, body) diff --git a/amixer/amixer.py b/amixer/amixer.py @@ -22,6 +22,7 @@ from qtools import Notifier class Volume(Notifier): defaults = [ + ('summary', 'Volume', 'Notification summary.'), ('mixer', 'Master', 'ALSA mixer to control.'), ('interval', 5, 'Percentage interval to change volume by.'), ] @@ -62,6 +63,8 @@ class Volume(Notifier): if len(stdout) == 5: volume = int(stdout[4].decode().split()[3][1:-2]) - elif len(stdout) == 6: + elif len(stdout) == 7: volume = int(stdout[5].decode().split()[4][1:-2]) + else: + logger.warning('Output from amixer needs decoding') return volume diff --git a/mpc/mpc.py b/mpc/mpc.py @@ -30,8 +30,7 @@ def _client_func(func): self.client.connect() except ConnectionError: pass - self.update(func(self)) - self.show() + self.show(func(self)) self.client.disconnect() return _inner