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

commit 449ddf3371fa052e4a665195b69e241dc4cbc337
parent f77a91d0e3b99446651957494b52233de68bc715
Author: mcol <mcol@posteo.net>
Date:   Sat, 29 Feb 2020 10:55:53 +0000

clean up following pylint's orders

Diffstat:
Mqtools/__init__.py | 4++--
Mqtools/amixer/amixer.py | 78++++++++++++++++++++++++++++++++++++++++++------------------------------------
Mqtools/mpc/mpc.py | 2+-
Mqtools/notification/notification.py | 46++++++++++++++++++++++------------------------
Mqtools/rofi_searx/searx.py | 7+++----
Msetup.cfg | 6+++++-
6 files changed, 75 insertions(+), 68 deletions(-)

diff --git a/qtools/__init__.py b/qtools/__init__.py @@ -3,13 +3,13 @@ Simple base classes that can be used for multiple plugins. """ +from random import randint + import gi gi.require_version('Notify', '0.7') from gi.repository import Notify -from random import randint from xcffib.xproto import StackMode - from libqtile import configurable, pangocffi, window from libqtile.lazy import lazy from libqtile.drawer import Drawer diff --git a/qtools/amixer/amixer.py b/qtools/amixer/amixer.py @@ -44,58 +44,64 @@ class Volume(Notifier): self.mute_master = False def increase(self, qtile=None): - stdout = self._run(['set', self.mixer, f'{self.interval}%+']) - volume = self._get_volume(stdout) + stdout = _run(['set', self.mixer, f'{self.interval}%+']) + volume = _get_volume(stdout) self.show(self.interval * round(volume / self.interval)) def decrease(self, qtile=None): - stdout = self._run(['set', self.mixer, f'{self.interval}%-']) - volume = self._get_volume(stdout) + stdout = _run(['set', self.mixer, f'{self.interval}%-']) + volume = _get_volume(stdout) self.show(self.interval * round(volume / self.interval)) def toggle(self, qtile=None): - stdout = self._run(['set', 'Master' if self.mute_master else self.mixer, 'toggle']) - if self._get_mute(stdout): + stdout = _run( + ['set', 'Master' if self.mute_master else self.mixer, 'toggle'] + ) + if _get_mute(stdout): self.show('Muted') else: if self.mute_master: - stdout = self._run(['get', self.mixer]) - volume = self._get_volume(stdout) + stdout = _run(['get', self.mixer]) + volume = _get_volume(stdout) self.show(self.interval * round(volume / self.interval)) def mute(self, qtile=None): - self._run(['set', 'Master' if self.mute_master else self.mixer, 'mute']) + _run(['set', 'Master' if self.mute_master else self.mixer, 'mute']) self.show('Muted') def unmute(self, qtile=None): - stdout = self._run( - ['set', 'Master' if self.mute_master else self.mixer, 'unmute'] - ) - volume = self._get_volume(self._run(['get', self.mixer])) + _run(['set', 'Master' if self.mute_master else self.mixer, 'unmute']) + volume = _get_volume(_run(['get', self.mixer])) self.show(self.interval * round(volume / self.interval)) - def _get_mute(self, stdout): - if len(stdout) == 5: - if stdout[4].decode().split()[5][1:-1] == 'on': - return False - else: - return True - logger.warning('Output from amixer needs decoding') - def _get_volume(self, stdout): - if len(stdout) == 5: - return int(stdout[4].decode().split()[3][1:-2]) - if len(stdout) == 7: - return int(stdout[5].decode().split()[4][1:-2]) +def _get_mute(stdout): + if len(stdout) == 5: + if stdout[4].decode().split()[5][1:-1] == 'on': + muted = False + else: + muted = True + else: + muted = False logger.warning('Output from amixer needs decoding') - - def _run(self, args): - cmd = ['amixer'] - cmd.extend(args) - try: - output = subprocess.run(cmd, stdout=subprocess.PIPE) - stdout = output.stdout.splitlines() - except subprocess.CalledProcessError as err: - logger.error(err.output.decode()) - return - return stdout + return muted + +def _get_volume(stdout): + if (stdlen:=len(stdout)) == 5: + vol = int(stdout[4].decode().split()[3][1:-2]) + elif stdlen == 7: + vol = int(stdout[5].decode().split()[4][1:-2]) + else: + logger.warning('Output from amixer needs decoding') + vol = 0 + return vol + +def _run(args): + cmd = ['amixer'] + cmd.extend(args) + try: + output = subprocess.run(cmd, stdout=subprocess.PIPE, check=False) + except subprocess.CalledProcessError as err: + logger.error(err.output.decode()) + return '' + return output.stdout.splitlines() diff --git a/qtools/mpc/mpc.py b/qtools/mpc/mpc.py @@ -13,7 +13,7 @@ Example usage: }.items()]) """ -# pylint: disable=no-member +# pylint: disable=no-member,redefined-builtin from functools import wraps diff --git a/qtools/notification/notification.py b/qtools/notification/notification.py @@ -153,24 +153,24 @@ class Server(configurable.Configurable): if self.border_width: self.border = [self.qtile.color_pixel(c) for c in self.border] - self._popup_config = {} + popup_config = {} for opt in Popup.defaults: key = opt[0] if hasattr(self, key): value = getattr(self, key) if isinstance(value, (tuple, list)): - self._popup_config[key] = value[1] + popup_config[key] = value[1] else: - self._popup_config[key] = value + popup_config[key] = value for win in range(self.max_windows): - popup = Popup(self.qtile, **self._popup_config) + popup = Popup(self.qtile, **popup_config) popup.win.handle_ButtonPress = self._buttonpress(popup) popup.replaces_id = None self._hidden.append(popup) self._positions.append( (self.x, self.y + win * (self.height + 2 * self.border_width + - self.gap)) + self.gap)) ) notifier.register(self._notify, Server.capabilities) @@ -325,26 +325,24 @@ class Server(configurable.Configurable): shown.place() def _load_icon(self, notif): - if notif.app_icon: - if notif.app_icon in self._icons: - return self._icons.get(notif.app_icon) - else: - try: - img = images.Img.from_path(notif.app_icon) - if img.width > img.height: - img.resize(width=self.icon_size) - else: - img.resize(height=self.icon_size) - surface, _ = images._decode_to_image_surface( - img.bytes_img, img.width, img.height - ) - self._icons[notif.app_icon] = surface, surface.get_height() - except (FileNotFoundError, images.LoadingError, IsADirectoryError) as e: - logger.exception(e) - self._icons[notif.app_icon] = None - return self._icons[notif.app_icon] - else: + if not notif.app_icon: return None + if notif.app_icon in self._icons: + return self._icons.get(notif.app_icon) + try: + img = images.Img.from_path(notif.app_icon) + if img.width > img.height: + img.resize(width=self.icon_size) + else: + img.resize(height=self.icon_size) + surface, _ = images._decode_to_image_surface( + img.bytes_img, img.width, img.height + ) + self._icons[notif.app_icon] = surface, surface.get_height() + except (FileNotFoundError, images.LoadingError, IsADirectoryError) as e: + logger.exception(e) + self._icons[notif.app_icon] = None + return self._icons[notif.app_icon] def close(self, qtile=None): """ diff --git a/qtools/rofi_searx/searx.py b/qtools/rofi_searx/searx.py @@ -45,7 +45,8 @@ class Searx(Notifier): ('prompt', 'Search the web', 'Prompt displayed by rofi.'), ('theme', None, 'rofi theme to use.'), ('launcher', 'tor-browser --allow-remote {url}', 'Command used to open web ' - 'browser. Requires {url} to place the search url.'), + 'browser. Requires {url} to ' + 'place the search url.'), ('notify_on_remove', True, 'Whether to make a notification when removing a ' 'searx instance.'), ] @@ -66,9 +67,7 @@ class Searx(Notifier): def search(self, qtile=None): output = subprocess.run( - self.command, - stdout=subprocess.PIPE, - universal_newlines=True, + self.command, stdout=subprocess.PIPE, universal_newlines=True, check=False ) if output.stdout and not output.returncode: if self.instances_file: diff --git a/setup.cfg b/setup.cfg @@ -10,5 +10,9 @@ disable = unused-argument, missing-function-doctring, missing-module-doctring, - access-member-before-definition + access-member-before-definition, + no-name-in-module, + c-extension-no-member max-line-length = 88 +max-attributes = 14 +max-args = 10