Modified behaviour of bumblebee.output.scrollable to allow for custom scroll speed and toggling "bouncing" of text, and applied it to deadbeef and spotify

This commit is contained in:
WORD559 2018-12-28 21:27:38 +00:00
parent 4bb10d6ea4
commit 8ea9762472
3 changed files with 27 additions and 12 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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
widget.set("scrolling.start", start)
if width + start >= len(text):
start += scroll_speed if direction == "right" else -(scroll_speed)
if width + start > len(text) + (scroll_speed -1):
if bounce:
widget.set("scrolling.direction", "left")
if start <= 0:
else:
start = 0
elif start <= 0:
if bounce:
widget.set("scrolling.direction", "right")
else:
start = len(text)
widget.set("scrolling.start", start)
text = text[start:width+start]
return text