From f67ef9d64a5d71c4cbad5cb5a28471e943814bc4 Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Sun, 21 Jun 2020 10:28:37 -0700 Subject: [PATCH 01/10] add spotify-buttons --- .../modules/contrib/spotify-buttons.py | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 bumblebee_status/modules/contrib/spotify-buttons.py diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py new file mode 100644 index 0000000..46c5e7a --- /dev/null +++ b/bumblebee_status/modules/contrib/spotify-buttons.py @@ -0,0 +1,93 @@ +import sys +import dbus + +import core.module +import core.widget +import core.input +import core.decorators +"""Displays the current song being played + +Requires the following library: + * python-dbus + +Parameters: + * spotify-buttons.format: Format string (defaults to '{artist} - {title}') + Available values are: {album}, {title}, {artist}, {trackNumber}, {playbackStatus} + * spotify-buttons.layout: +""" + +class Module(core.module.Module): + def __init__(self, config, theme): + super().__init__(config, theme, core.widget.Widget(self.spotify)) + + self.__layout = self.parameter("layout", "spotify-buttons.prev spotify-buttons.pause spotify-buttons.next") + + self.__song = "" + self.__format = self.parameter("format", "{artist} - {title}") + prev_button = self.parameter("previous", "LEFT_CLICK") + next_button = self.parameter("next", "RIGHT_CLICK") + pause_button = self.parameter("pause", "MIDDLE_CLICK") + + cmd = "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \ + /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." + #core.input.register(self, button=buttons[prev_button], cmd=cmd + "Previous") + #core.input.register(self, button=buttons[next_button], cmd=cmd + "Next") + #core.input.register(self, button=buttons[pause_button], cmd=cmd + "PlayPause") + + widget_map = {} + for widget in self.__layout.split(): + widget = self.add_widget(name = widget_name) + if widget_name = "spotify-buttons.prev": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": cmd + "Previous", + } + elif widget_name = "spotify-buttons.pause": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": cmd + "PlayPause", + } + elif widget_name = "spotify-buttons.next": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": cmd + "Next", + } + + @core.decorators.scrollable + def spotify(self, widget): + return self.string_song + + def hidden(self): + return self.string_song == "" + + def update(self): + try: + bus = dbus.SessionBus() + spotify = bus.get_object( + "org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2" + ) + spotify_iface = dbus.Interface(spotify, "org.freedesktop.DBus.Properties") + props = spotify_iface.Get("org.mpris.MediaPlayer2.Player", "Metadata") + playback_status = str( + spotify_iface.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus") + ) + self.__song = self.__format.format( + album=str(props.get("xesam:album")), + title=str(props.get("xesam:title")), + artist=",".join(props.get("xesam:artist")), + trackNumber=str(props.get("xesam:trackNumber")), + playbackStatus="\u25B6" + if playback_status == "Playing" + else "\u258D\u258D" + if playback_status == "Paused" + else "", + ) + + except Exception: + self.__song = "" + + @property + def string_song(self): + if sys.version_info.major < 3: + return unicode(self.__song) + return str(self.__song) From ca62f689067248b99afd93f03d80b71480aed6d5 Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Sun, 21 Jun 2020 12:31:11 -0700 Subject: [PATCH 02/10] create + map widgets for buttons --- bumblebee_status/modules/contrib/spotify-buttons.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py index 46c5e7a..36f126c 100644 --- a/bumblebee_status/modules/contrib/spotify-buttons.py +++ b/bumblebee_status/modules/contrib/spotify-buttons.py @@ -30,28 +30,27 @@ class Module(core.module.Module): cmd = "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \ /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." - #core.input.register(self, button=buttons[prev_button], cmd=cmd + "Previous") - #core.input.register(self, button=buttons[next_button], cmd=cmd + "Next") - #core.input.register(self, button=buttons[pause_button], cmd=cmd + "PlayPause") widget_map = {} - for widget in self.__layout.split(): + for widget_name in self.__layout.split(): widget = self.add_widget(name = widget_name) - if widget_name = "spotify-buttons.prev": + if widget_name == "spotify-buttons.prev": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": cmd + "Previous", } - elif widget_name = "spotify-buttons.pause": + elif widget_name == "spotify-buttons.pause": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": cmd + "PlayPause", } - elif widget_name = "spotify-buttons.next": + elif widget_name == "spotify-buttons.next": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": cmd + "Next", } + for widget, callback_options in widget_map.items(): + core.input.register(widget, **callback_options) @core.decorators.scrollable def spotify(self, widget): From 2eee4c390cf2e411543acba013c8f438b5f9dae9 Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Wed, 24 Jun 2020 12:14:26 -0700 Subject: [PATCH 03/10] put text on buttons --- .../modules/contrib/spotify-buttons.py | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py index 36f126c..95be303 100644 --- a/bumblebee_status/modules/contrib/spotify-buttons.py +++ b/bumblebee_status/modules/contrib/spotify-buttons.py @@ -5,62 +5,35 @@ import core.module import core.widget import core.input import core.decorators -"""Displays the current song being played +"""Displays the current song being played and allows pausing, skipping ahead, and skipping back. Requires the following library: * python-dbus Parameters: * spotify-buttons.format: Format string (defaults to '{artist} - {title}') - Available values are: {album}, {title}, {artist}, {trackNumber}, {playbackStatus} - * spotify-buttons.layout: + Available values are: {album}, {title}, {artist}, {trackNumber} """ class Module(core.module.Module): def __init__(self, config, theme): - super().__init__(config, theme, core.widget.Widget(self.spotify)) + super().__init__(config, theme, []) - self.__layout = self.parameter("layout", "spotify-buttons.prev spotify-buttons.pause spotify-buttons.next") + self.__layout = self.parameter("layout", "spotify-buttons.song spotify-buttons.prev spotify-buttons.pause spotify-buttons.next") self.__song = "" + self.__pause = "" self.__format = self.parameter("format", "{artist} - {title}") - prev_button = self.parameter("previous", "LEFT_CLICK") - next_button = self.parameter("next", "RIGHT_CLICK") - pause_button = self.parameter("pause", "MIDDLE_CLICK") - cmd = "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \ + self.__cmd = "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \ /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." - widget_map = {} - for widget_name in self.__layout.split(): - widget = self.add_widget(name = widget_name) - if widget_name == "spotify-buttons.prev": - widget_map[widget] = { - "button": core.input.LEFT_MOUSE, - "cmd": cmd + "Previous", - } - elif widget_name == "spotify-buttons.pause": - widget_map[widget] = { - "button": core.input.LEFT_MOUSE, - "cmd": cmd + "PlayPause", - } - elif widget_name == "spotify-buttons.next": - widget_map[widget] = { - "button": core.input.LEFT_MOUSE, - "cmd": cmd + "Next", - } - for widget, callback_options in widget_map.items(): - core.input.register(widget, **callback_options) - - @core.decorators.scrollable - def spotify(self, widget): - return self.string_song - def hidden(self): return self.string_song == "" def update(self): try: + self.clear_widgets() bus = dbus.SessionBus() spotify = bus.get_object( "org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2" @@ -70,17 +43,46 @@ class Module(core.module.Module): playback_status = str( spotify_iface.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus") ) + if playback_status == "Playing": + self.__pause = "\u25B6" + else: + self.__pause = "\u258D\u258D" self.__song = self.__format.format( album=str(props.get("xesam:album")), title=str(props.get("xesam:title")), artist=",".join(props.get("xesam:artist")), trackNumber=str(props.get("xesam:trackNumber")), - playbackStatus="\u25B6" - if playback_status == "Playing" - else "\u258D\u258D" - if playback_status == "Paused" - else "", ) + #this feels like a stupid way to do this but its all i can think of + widget_map = {} + for widget_name in self.__layout.split(): + widget = self.add_widget(name = widget_name) + if widget_name == "spotify-buttons.prev": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": self.__cmd + "Previous", + } + widget.full_text("\u258F\u25C0") + elif widget_name == "spotify-buttons.pause": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": self.__cmd + "PlayPause", + } + widget.full_text(self.__pause) + elif widget_name == "spotify-buttons.next": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": self.__cmd + "Next", + } + widget.full_text("\u25B6\u2595") + elif widget_name == "spotify-buttons.song": + widget.full_text(self.__song) + else: + raise KeyError( + "The spotify-buttons module does not have a {widget_name!r} widget".format(widget_name=widget_name) + ) + for widget, callback_options in widget_map.items(): + core.input.register(widget, **callback_options) except Exception: self.__song = "" From 0c32d13e6f6a3df98d100d05ce3f3465e83c5d5b Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Wed, 24 Jun 2020 12:15:32 -0700 Subject: [PATCH 04/10] fix playback status --- bumblebee_status/modules/contrib/spotify-buttons.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py index 95be303..54b2437 100644 --- a/bumblebee_status/modules/contrib/spotify-buttons.py +++ b/bumblebee_status/modules/contrib/spotify-buttons.py @@ -44,9 +44,9 @@ class Module(core.module.Module): spotify_iface.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus") ) if playback_status == "Playing": - self.__pause = "\u25B6" - else: self.__pause = "\u258D\u258D" + else: + self.__pause = "\u25B6" self.__song = self.__format.format( album=str(props.get("xesam:album")), title=str(props.get("xesam:title")), From e1a97824586bc9713aa5edecb81d19a22e2faff4 Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Wed, 24 Jun 2020 12:18:28 -0700 Subject: [PATCH 05/10] modify comments --- bumblebee_status/modules/contrib/spotify-buttons.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py index 54b2437..88c8ae9 100644 --- a/bumblebee_status/modules/contrib/spotify-buttons.py +++ b/bumblebee_status/modules/contrib/spotify-buttons.py @@ -13,6 +13,8 @@ Requires the following library: Parameters: * spotify-buttons.format: Format string (defaults to '{artist} - {title}') Available values are: {album}, {title}, {artist}, {trackNumber} + * spotify-buttons.layout: Order in which widgets appear (defaults to song, previous, pause, next) + Widget names are: spotify-buttons.song, spotify-buttons.prev, spotify-buttons.pause, spotify-buttons.next """ class Module(core.module.Module): From 7215a11ffe9c1787aef6b5032d6a897956183fb2 Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Wed, 24 Jun 2020 12:22:03 -0700 Subject: [PATCH 06/10] black -t py34 --- .../modules/contrib/spotify-buttons.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py index 88c8ae9..26ec14c 100644 --- a/bumblebee_status/modules/contrib/spotify-buttons.py +++ b/bumblebee_status/modules/contrib/spotify-buttons.py @@ -5,6 +5,7 @@ import core.module import core.widget import core.input import core.decorators + """Displays the current song being played and allows pausing, skipping ahead, and skipping back. Requires the following library: @@ -17,11 +18,15 @@ Parameters: Widget names are: spotify-buttons.song, spotify-buttons.prev, spotify-buttons.pause, spotify-buttons.next """ + class Module(core.module.Module): def __init__(self, config, theme): super().__init__(config, theme, []) - self.__layout = self.parameter("layout", "spotify-buttons.song spotify-buttons.prev spotify-buttons.pause spotify-buttons.next") + self.__layout = self.parameter( + "layout", + "spotify-buttons.song spotify-buttons.prev spotify-buttons.pause spotify-buttons.next", + ) self.__song = "" self.__pause = "" @@ -55,34 +60,36 @@ class Module(core.module.Module): artist=",".join(props.get("xesam:artist")), trackNumber=str(props.get("xesam:trackNumber")), ) - #this feels like a stupid way to do this but its all i can think of + # this feels like a stupid way to do this but its all i can think of widget_map = {} for widget_name in self.__layout.split(): - widget = self.add_widget(name = widget_name) + widget = self.add_widget(name=widget_name) if widget_name == "spotify-buttons.prev": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": self.__cmd + "Previous", - } + } widget.full_text("\u258F\u25C0") elif widget_name == "spotify-buttons.pause": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": self.__cmd + "PlayPause", - } + } widget.full_text(self.__pause) elif widget_name == "spotify-buttons.next": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": self.__cmd + "Next", - } + } widget.full_text("\u25B6\u2595") elif widget_name == "spotify-buttons.song": widget.full_text(self.__song) else: raise KeyError( - "The spotify-buttons module does not have a {widget_name!r} widget".format(widget_name=widget_name) + "The spotify-buttons module does not have a {widget_name!r} widget".format( + widget_name=widget_name ) + ) for widget, callback_options in widget_map.items(): core.input.register(widget, **callback_options) From 4b54d1981c6f415bf4e2ced30f1a6c0ab3cb817c Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Wed, 24 Jun 2020 13:53:02 -0700 Subject: [PATCH 07/10] fix grammar --- bumblebee_status/modules/contrib/spotify-buttons.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py index 26ec14c..8adb6d2 100644 --- a/bumblebee_status/modules/contrib/spotify-buttons.py +++ b/bumblebee_status/modules/contrib/spotify-buttons.py @@ -60,7 +60,8 @@ class Module(core.module.Module): artist=",".join(props.get("xesam:artist")), trackNumber=str(props.get("xesam:trackNumber")), ) - # this feels like a stupid way to do this but its all i can think of + + #add widgets widget_map = {} for widget_name in self.__layout.split(): widget = self.add_widget(name=widget_name) From 6a8d8302818a716597e7e8d36f943e9912fae6f7 Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Thu, 25 Jun 2020 10:20:02 -0700 Subject: [PATCH 08/10] util.format.aslist() for layout --- bumblebee_status/modules/contrib/spotify-buttons.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py index 8adb6d2..be198b8 100644 --- a/bumblebee_status/modules/contrib/spotify-buttons.py +++ b/bumblebee_status/modules/contrib/spotify-buttons.py @@ -5,6 +5,7 @@ import core.module import core.widget import core.input import core.decorators +import util.format """Displays the current song being played and allows pausing, skipping ahead, and skipping back. @@ -25,7 +26,7 @@ class Module(core.module.Module): self.__layout = self.parameter( "layout", - "spotify-buttons.song spotify-buttons.prev spotify-buttons.pause spotify-buttons.next", + util.format.aslist("spotify-buttons.song,spotify-buttons.prev,spotify-buttons.pause,spotify-buttons.next"), ) self.__song = "" @@ -63,7 +64,7 @@ class Module(core.module.Module): #add widgets widget_map = {} - for widget_name in self.__layout.split(): + for widget_name in self.__layout: widget = self.add_widget(name=widget_name) if widget_name == "spotify-buttons.prev": widget_map[widget] = { From 057faa55777547ea0ac24394f900a8c1922b4af2 Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Thu, 25 Jun 2020 10:23:45 -0700 Subject: [PATCH 09/10] replace original spotify with buttons version --- .../modules/contrib/spotify-buttons.py | 105 ----------------- bumblebee_status/modules/contrib/spotify.py | 106 ++++++++++-------- 2 files changed, 58 insertions(+), 153 deletions(-) delete mode 100644 bumblebee_status/modules/contrib/spotify-buttons.py diff --git a/bumblebee_status/modules/contrib/spotify-buttons.py b/bumblebee_status/modules/contrib/spotify-buttons.py deleted file mode 100644 index be198b8..0000000 --- a/bumblebee_status/modules/contrib/spotify-buttons.py +++ /dev/null @@ -1,105 +0,0 @@ -import sys -import dbus - -import core.module -import core.widget -import core.input -import core.decorators -import util.format - -"""Displays the current song being played and allows pausing, skipping ahead, and skipping back. - -Requires the following library: - * python-dbus - -Parameters: - * spotify-buttons.format: Format string (defaults to '{artist} - {title}') - Available values are: {album}, {title}, {artist}, {trackNumber} - * spotify-buttons.layout: Order in which widgets appear (defaults to song, previous, pause, next) - Widget names are: spotify-buttons.song, spotify-buttons.prev, spotify-buttons.pause, spotify-buttons.next -""" - - -class Module(core.module.Module): - def __init__(self, config, theme): - super().__init__(config, theme, []) - - self.__layout = self.parameter( - "layout", - util.format.aslist("spotify-buttons.song,spotify-buttons.prev,spotify-buttons.pause,spotify-buttons.next"), - ) - - self.__song = "" - self.__pause = "" - self.__format = self.parameter("format", "{artist} - {title}") - - self.__cmd = "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \ - /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." - - def hidden(self): - return self.string_song == "" - - def update(self): - try: - self.clear_widgets() - bus = dbus.SessionBus() - spotify = bus.get_object( - "org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2" - ) - spotify_iface = dbus.Interface(spotify, "org.freedesktop.DBus.Properties") - props = spotify_iface.Get("org.mpris.MediaPlayer2.Player", "Metadata") - playback_status = str( - spotify_iface.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus") - ) - if playback_status == "Playing": - self.__pause = "\u258D\u258D" - else: - self.__pause = "\u25B6" - self.__song = self.__format.format( - album=str(props.get("xesam:album")), - title=str(props.get("xesam:title")), - artist=",".join(props.get("xesam:artist")), - trackNumber=str(props.get("xesam:trackNumber")), - ) - - #add widgets - widget_map = {} - for widget_name in self.__layout: - widget = self.add_widget(name=widget_name) - if widget_name == "spotify-buttons.prev": - widget_map[widget] = { - "button": core.input.LEFT_MOUSE, - "cmd": self.__cmd + "Previous", - } - widget.full_text("\u258F\u25C0") - elif widget_name == "spotify-buttons.pause": - widget_map[widget] = { - "button": core.input.LEFT_MOUSE, - "cmd": self.__cmd + "PlayPause", - } - widget.full_text(self.__pause) - elif widget_name == "spotify-buttons.next": - widget_map[widget] = { - "button": core.input.LEFT_MOUSE, - "cmd": self.__cmd + "Next", - } - widget.full_text("\u25B6\u2595") - elif widget_name == "spotify-buttons.song": - widget.full_text(self.__song) - else: - raise KeyError( - "The spotify-buttons module does not have a {widget_name!r} widget".format( - widget_name=widget_name - ) - ) - for widget, callback_options in widget_map.items(): - core.input.register(widget, **callback_options) - - except Exception: - self.__song = "" - - @property - def string_song(self): - if sys.version_info.major < 3: - return unicode(self.__song) - return str(self.__song) diff --git a/bumblebee_status/modules/contrib/spotify.py b/bumblebee_status/modules/contrib/spotify.py index dc371db..159f2ce 100644 --- a/bumblebee_status/modules/contrib/spotify.py +++ b/bumblebee_status/modules/contrib/spotify.py @@ -1,24 +1,3 @@ -# pylint: disable=C0111,R0903 - -"""Displays the current song being played - -Requires the following library: - * python-dbus - -Parameters: - * spotify.format: Format string (defaults to '{artist} - {title}') - Available values are: {album}, {title}, {artist}, {trackNumber}, {playbackStatus} - * spotify.previous: Change binding for previous song (default is left click) - * spotify.next: Change binding for next song (default is right click) - * spotify.pause: Change binding for toggling pause (default is middle click) - - Available options for spotify.previous, spotify.next and spotify.pause are: - LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK, SCROLL_UP, SCROLL_DOWN - - -contributed by `yvesh `_ - many thanks! -""" - import sys import dbus @@ -26,41 +5,43 @@ import core.module import core.widget import core.input import core.decorators +import util.format + +"""Displays the current song being played and allows pausing, skipping ahead, and skipping back. + +Requires the following library: + * python-dbus + +Parameters: + * spotify-buttons.format: Format string (defaults to '{artist} - {title}') + Available values are: {album}, {title}, {artist}, {trackNumber} + * spotify-buttons.layout: Order in which widgets appear (defaults to song, previous, pause, next) + Widget names are: spotify-buttons.song, spotify-buttons.prev, spotify-buttons.pause, spotify-buttons.next +""" class Module(core.module.Module): def __init__(self, config, theme): - super().__init__(config, theme, core.widget.Widget(self.spotify)) + super().__init__(config, theme, []) - buttons = { - "LEFT_CLICK": core.input.LEFT_MOUSE, - "RIGHT_CLICK": core.input.RIGHT_MOUSE, - "MIDDLE_CLICK": core.input.MIDDLE_MOUSE, - "SCROLL_UP": core.input.WHEEL_UP, - "SCROLL_DOWN": core.input.WHEEL_DOWN, - } + self.__layout = self.parameter( + "layout", + util.format.aslist("spotify-buttons.song,spotify-buttons.prev,spotify-buttons.pause,spotify-buttons.next"), + ) self.__song = "" + self.__pause = "" self.__format = self.parameter("format", "{artist} - {title}") - prev_button = self.parameter("previous", "LEFT_CLICK") - next_button = self.parameter("next", "RIGHT_CLICK") - pause_button = self.parameter("pause", "MIDDLE_CLICK") - cmd = "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \ + self.__cmd = "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \ /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." - core.input.register(self, button=buttons[prev_button], cmd=cmd + "Previous") - core.input.register(self, button=buttons[next_button], cmd=cmd + "Next") - core.input.register(self, button=buttons[pause_button], cmd=cmd + "PlayPause") - - @core.decorators.scrollable - def spotify(self, widget): - return self.string_song def hidden(self): return self.string_song == "" def update(self): try: + self.clear_widgets() bus = dbus.SessionBus() spotify = bus.get_object( "org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2" @@ -70,18 +51,50 @@ class Module(core.module.Module): playback_status = str( spotify_iface.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus") ) + if playback_status == "Playing": + self.__pause = "\u258D\u258D" + else: + self.__pause = "\u25B6" self.__song = self.__format.format( album=str(props.get("xesam:album")), title=str(props.get("xesam:title")), artist=",".join(props.get("xesam:artist")), trackNumber=str(props.get("xesam:trackNumber")), - playbackStatus="\u25B6" - if playback_status == "Playing" - else "\u258D\u258D" - if playback_status == "Paused" - else "", ) + #add widgets + widget_map = {} + for widget_name in self.__layout: + widget = self.add_widget(name=widget_name) + if widget_name == "spotify-buttons.prev": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": self.__cmd + "Previous", + } + widget.full_text("\u258F\u25C0") + elif widget_name == "spotify-buttons.pause": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": self.__cmd + "PlayPause", + } + widget.full_text(self.__pause) + elif widget_name == "spotify-buttons.next": + widget_map[widget] = { + "button": core.input.LEFT_MOUSE, + "cmd": self.__cmd + "Next", + } + widget.full_text("\u25B6\u2595") + elif widget_name == "spotify-buttons.song": + widget.full_text(self.__song) + else: + raise KeyError( + "The spotify module does not have a {widget_name!r} widget".format( + widget_name=widget_name + ) + ) + for widget, callback_options in widget_map.items(): + core.input.register(widget, **callback_options) + except Exception: self.__song = "" @@ -90,6 +103,3 @@ class Module(core.module.Module): if sys.version_info.major < 3: return unicode(self.__song) return str(self.__song) - - -# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 4cbe04f0b0c39921bfd57e873a99f4f364e08bb2 Mon Sep 17 00:00:00 2001 From: LtPeriwinkle Date: Thu, 25 Jun 2020 10:53:53 -0700 Subject: [PATCH 10/10] remove -buttons, move getting song out of update() --- bumblebee_status/modules/contrib/spotify.py | 56 +++++++++++---------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/bumblebee_status/modules/contrib/spotify.py b/bumblebee_status/modules/contrib/spotify.py index 159f2ce..66b67c9 100644 --- a/bumblebee_status/modules/contrib/spotify.py +++ b/bumblebee_status/modules/contrib/spotify.py @@ -13,10 +13,10 @@ Requires the following library: * python-dbus Parameters: - * spotify-buttons.format: Format string (defaults to '{artist} - {title}') + * spotify.format: Format string (defaults to '{artist} - {title}') Available values are: {album}, {title}, {artist}, {trackNumber} - * spotify-buttons.layout: Order in which widgets appear (defaults to song, previous, pause, next) - Widget names are: spotify-buttons.song, spotify-buttons.prev, spotify-buttons.pause, spotify-buttons.next + * spotify.layout: Comma-separated list to change order of widgets (defaults to song, previous, pause, next) + Widget names are: spotify.song, spotify.prev, spotify.pause, spotify.next """ @@ -26,7 +26,7 @@ class Module(core.module.Module): self.__layout = self.parameter( "layout", - util.format.aslist("spotify-buttons.song,spotify-buttons.prev,spotify-buttons.pause,spotify-buttons.next"), + util.format.aslist("spotify.song,spotify.prev,spotify.pause,spotify.next"), ) self.__song = "" @@ -39,52 +39,54 @@ class Module(core.module.Module): def hidden(self): return self.string_song == "" - def update(self): - try: - self.clear_widgets() - bus = dbus.SessionBus() - spotify = bus.get_object( - "org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2" - ) - spotify_iface = dbus.Interface(spotify, "org.freedesktop.DBus.Properties") - props = spotify_iface.Get("org.mpris.MediaPlayer2.Player", "Metadata") - playback_status = str( - spotify_iface.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus") - ) - if playback_status == "Playing": - self.__pause = "\u258D\u258D" - else: - self.__pause = "\u25B6" + def __get_song(self): + bus = dbus.SessionBus() + spotify = bus.get_object( + "org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2" + ) + spotify_iface = dbus.Interface(spotify, "org.freedesktop.DBus.Properties") + props = spotify_iface.Get("org.mpris.MediaPlayer2.Player", "Metadata") + playback_status = str( + spotify_iface.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus") + ) + if playback_status == "Playing": + self.__pause = "\u258D\u258D" + else: + self.__pause = "\u25B6" self.__song = self.__format.format( - album=str(props.get("xesam:album")), - title=str(props.get("xesam:title")), + album=str(props.get("xesam:album")), + title=str(props.get("xesam:title")), artist=",".join(props.get("xesam:artist")), trackNumber=str(props.get("xesam:trackNumber")), ) - #add widgets + def update(self): + try: + self.clear_widgets() + self.__get_song() + widget_map = {} for widget_name in self.__layout: widget = self.add_widget(name=widget_name) - if widget_name == "spotify-buttons.prev": + if widget_name == "spotify.prev": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": self.__cmd + "Previous", } widget.full_text("\u258F\u25C0") - elif widget_name == "spotify-buttons.pause": + elif widget_name == "spotify.pause": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": self.__cmd + "PlayPause", } widget.full_text(self.__pause) - elif widget_name == "spotify-buttons.next": + elif widget_name == "spotify.next": widget_map[widget] = { "button": core.input.LEFT_MOUSE, "cmd": self.__cmd + "Next", } widget.full_text("\u25B6\u2595") - elif widget_name == "spotify-buttons.song": + elif widget_name == "spotify.song": widget.full_text(self.__song) else: raise KeyError(