From 8ea97624728572e06f49a7b0a0250e72fd271a84 Mon Sep 17 00:00:00 2001 From: WORD559 Date: Fri, 28 Dec 2018 21:27:38 +0000 Subject: [PATCH] Modified behaviour of bumblebee.output.scrollable to allow for custom scroll speed and toggling "bouncing" of text, and applied it to deadbeef and spotify --- bumblebee/modules/deadbeef.py | 7 +++---- bumblebee/modules/spotify.py | 6 +++--- bumblebee/output.py | 26 +++++++++++++++++++++----- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/bumblebee/modules/deadbeef.py b/bumblebee/modules/deadbeef.py index 69c72ff..2dce7fd 100644 --- a/bumblebee/modules/deadbeef.py +++ b/bumblebee/modules/deadbeef.py @@ -2,13 +2,10 @@ """Displays the current song being played in DeaDBeeF and provides some media control bindings. - Left click toggles pause, scroll up skips the current song, scroll down returns to the previous song. - Requires the following library: * subprocess - Parameters: * deadbeef.format: Format string (defaults to "{artist} - {title}") Available values are: {artist}, {title}, {album}, {length}, @@ -17,7 +14,6 @@ Parameters: * deadbeef.previous: Change binding for previous song (default is left click) * deadbeef.next: Change binding for next song (default is right click) * deadbeef.pause: Change binding for toggling pause (default is middle click) - Available options for deadbeef.previous, deadbeef.next and deadbeef.pause are: LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK, SCROLL_UP, SCROLL_DOWN """ @@ -26,6 +22,8 @@ import bumblebee.input import bumblebee.output import bumblebee.engine +from bumblebee.output import scrollable + try: import subprocess except ImportError: @@ -59,6 +57,7 @@ class Module(bumblebee.engine.Module): engine.input.register_callback(self, button=buttons[pause_button], cmd=cmd + "--play-pause") + @scrollable def deadbeef(self, widget): return str(self._song) diff --git a/bumblebee/modules/spotify.py b/bumblebee/modules/spotify.py index dad0c26..da09ddc 100644 --- a/bumblebee/modules/spotify.py +++ b/bumblebee/modules/spotify.py @@ -1,17 +1,14 @@ # 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 """ @@ -20,6 +17,8 @@ import bumblebee.input import bumblebee.output import bumblebee.engine +from bumblebee.output import scrollable + try: import dbus except ImportError: @@ -53,6 +52,7 @@ class Module(bumblebee.engine.Module): engine.input.register_callback(self, button=buttons[pause_button], cmd=cmd + "PlayPause") + @scrollable def spotify(self, widget): return str(self._song) diff --git a/bumblebee/output.py b/bumblebee/output.py index f299f3e..35c1895 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -17,14 +17,30 @@ def scrollable(func): if len(text) <= width: return text # we need to shorten + + try: + bounce = int(module.parameter("scrolling.bounce", 1)) + except ValueError: + bounce = 1 + try: + scroll_speed = int(module.parameter("scrolling.speed", 1)) + except ValueError: + scroll_speed = 1 start = widget.get("scrolling.start", -1) direction = widget.get("scrolling.direction", "right") - start += 1 if direction == "right" else -1 + start += scroll_speed if direction == "right" else -(scroll_speed) + + if width + start > len(text) + (scroll_speed -1): + if bounce: + widget.set("scrolling.direction", "left") + else: + start = 0 + elif start <= 0: + if bounce: + widget.set("scrolling.direction", "right") + else: + start = len(text) widget.set("scrolling.start", start) - if width + start >= len(text): - widget.set("scrolling.direction", "left") - if start <= 0: - widget.set("scrolling.direction", "right") text = text[start:width+start] return text