From 8867f4f188141a07d3e6d8ee157472cf99a60129 Mon Sep 17 00:00:00 2001 From: Dhananjay Tanpure Date: Thu, 20 Jan 2022 21:06:17 +0000 Subject: [PATCH 1/2] added module for blugon --- bumblebee_status/modules/contrib/blugon.py | 97 ++++++++++++++++++++++ tests/modules/contrib/test_blugon.py | 2 + 2 files changed, 99 insertions(+) create mode 100644 bumblebee_status/modules/contrib/blugon.py create mode 100644 tests/modules/contrib/test_blugon.py diff --git a/bumblebee_status/modules/contrib/blugon.py b/bumblebee_status/modules/contrib/blugon.py new file mode 100644 index 0000000..4fa0079 --- /dev/null +++ b/bumblebee_status/modules/contrib/blugon.py @@ -0,0 +1,97 @@ +"""Displays temperature of blugon and Controls it. + +Use wheel up and down to change temperature, middle click to toggle and right click to reset temprature. + +Default Values: + * Minimum temperature: 1000 (red) + * Maximum temperature: 20000 (blue) + * Default temperature: 6600 + +Requires the following executable: + * blugon + +Parameters: + * blugon.step: The amount of increase/decrease on scroll (default: 200) + +contributed by `DTan13 ` +""" + +import core.module +import core.widget + +import util.cli +import util.format + +import os + + +class Module(core.module.Module): + def __init__(self, config, theme): + super().__init__(config, theme, core.widget.Widget(self.full_text)) + self.__state = True + self.__default = 6600 + self.__step = ( + util.format.asint(self.parameter("step")) if self.parameter("step") else 200 + ) + self.__max, self.__min = 20000, 1000 + + file = open(os.path.expanduser("~/.config/blugon/current")) + self.__current = int(float(file.read())) + + events = [ + { + "type": "toggle", + "action": self.toggle, + "button": core.input.MIDDLE_MOUSE, + }, + { + "type": "blue", + "action": self.blue, + "button": core.input.WHEEL_UP, + }, + { + "type": "red", + "action": self.red, + "button": core.input.WHEEL_DOWN, + }, + { + "type": "reset", + "action": self.reset, + "button": core.input.RIGHT_MOUSE, + }, + ] + + for event in events: + core.input.register(self, button=event["button"], cmd=event["action"]) + + def set_temp(self): + temp = self.__current if self.__state else self.__default + util.cli.execute("blugon --setcurrent={}".format(temp)) + + def full_text(self, widget): + return self.__current if self.__state else self.__default + + def state(self, widget): + if not self.__state: + return ["critical"] + + def toggle(self, event): + self.__state = not self.__state + self.set_temp() + + def reset(self, event): + self.__current = 6600 + self.set_temp() + + def blue(self, event): + if self.__state and (self.__current < self.__max): + self.__current += self.__step + self.set_temp() + + def red(self, event): + if self.__state and (self.__current > self.__min): + self.__current -= self.__step + self.set_temp() + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/modules/contrib/test_blugon.py b/tests/modules/contrib/test_blugon.py new file mode 100644 index 0000000..6c9dd9b --- /dev/null +++ b/tests/modules/contrib/test_blugon.py @@ -0,0 +1,2 @@ +def test_load_module(): + __import__("modules.contrib.zpool") From e5cdabcc0f9fb972828cf88739072130bf2f545a Mon Sep 17 00:00:00 2001 From: Dhananjay Tanpure Date: Mon, 7 Mar 2022 08:50:30 +0530 Subject: [PATCH 2/2] mpd and title --- bumblebee_status/modules/contrib/mpd.py | 9 +++++++++ bumblebee_status/modules/contrib/title.py | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bumblebee_status/modules/contrib/mpd.py b/bumblebee_status/modules/contrib/mpd.py index 3efffff..92568d1 100644 --- a/bumblebee_status/modules/contrib/mpd.py +++ b/bumblebee_status/modules/contrib/mpd.py @@ -94,6 +94,12 @@ class Module(core.module.Module): "cmd": "mpc toggle" + self._hostcmd, } widget.full_text(self.description) + elif widget_name == "mpd.toggle": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": "mpc toggle" + self._hostcmd, + } + widget.full_text(self.toggle) elif widget_name == "mpd.next": widget_map[widget] = { "button": core.input.LEFT_MOUSE, @@ -127,6 +133,9 @@ class Module(core.module.Module): def description(self, widget): return string.Formatter().vformat(self._fmt, (), self._tags) + def toggle(self, widget): + return str(util.cli.execute("mpc status %currenttime%/%totaltime%", ignore_errors=True)).strip() + def update(self): self._load_song() diff --git a/bumblebee_status/modules/contrib/title.py b/bumblebee_status/modules/contrib/title.py index 33af47a..055369e 100644 --- a/bumblebee_status/modules/contrib/title.py +++ b/bumblebee_status/modules/contrib/title.py @@ -9,6 +9,7 @@ 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 '...'. * title.scroll : Boolean flag for scrolling title. Defaults to False + * title.short : Boolean flag for short title. Defaults to False contributed by `UltimatePancake `_ - many thanks! @@ -35,6 +36,7 @@ class Module(core.module.Module): # parsing of parameters self.__scroll = util.format.asbool(self.parameter("scroll", False)) + self.__short = util.format.asbool(self.parameter("short", False)) self.__max = int(self.parameter("max", 64)) self.__placeholder = self.parameter("placeholder", "...") self.__title = "" @@ -66,7 +68,9 @@ class Module(core.module.Module): def __pollTitle(self): """Updating current title.""" try: - self.__full_title = self.__i3.get_tree().find_focused().name + focused = self.__i3.get_tree().find_focused().name + self.__full_title = focused.split( + "-")[-1].strip() if self.__short else focused except: self.__full_title = no_title if self.__full_title is None: