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:
parent
4bb10d6ea4
commit
8ea9762472
3 changed files with 27 additions and 12 deletions
|
@ -2,13 +2,10 @@
|
||||||
|
|
||||||
"""Displays the current song being played in DeaDBeeF and
|
"""Displays the current song being played in DeaDBeeF and
|
||||||
provides some media control bindings.
|
provides some media control bindings.
|
||||||
|
|
||||||
Left click toggles pause, scroll up skips the current song,
|
Left click toggles pause, scroll up skips the current song,
|
||||||
scroll down returns to the previous song.
|
scroll down returns to the previous song.
|
||||||
|
|
||||||
Requires the following library:
|
Requires the following library:
|
||||||
* subprocess
|
* subprocess
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* deadbeef.format: Format string (defaults to "{artist} - {title}")
|
* deadbeef.format: Format string (defaults to "{artist} - {title}")
|
||||||
Available values are: {artist}, {title}, {album}, {length},
|
Available values are: {artist}, {title}, {album}, {length},
|
||||||
|
@ -17,7 +14,6 @@ Parameters:
|
||||||
* deadbeef.previous: Change binding for previous song (default is left click)
|
* deadbeef.previous: Change binding for previous song (default is left click)
|
||||||
* deadbeef.next: Change binding for next song (default is right click)
|
* deadbeef.next: Change binding for next song (default is right click)
|
||||||
* deadbeef.pause: Change binding for toggling pause (default is middle click)
|
* deadbeef.pause: Change binding for toggling pause (default is middle click)
|
||||||
|
|
||||||
Available options for deadbeef.previous, deadbeef.next and deadbeef.pause are:
|
Available options for deadbeef.previous, deadbeef.next and deadbeef.pause are:
|
||||||
LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK, SCROLL_UP, SCROLL_DOWN
|
LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK, SCROLL_UP, SCROLL_DOWN
|
||||||
"""
|
"""
|
||||||
|
@ -26,6 +22,8 @@ import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
import bumblebee.engine
|
import bumblebee.engine
|
||||||
|
|
||||||
|
from bumblebee.output import scrollable
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import subprocess
|
import subprocess
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -59,6 +57,7 @@ class Module(bumblebee.engine.Module):
|
||||||
engine.input.register_callback(self, button=buttons[pause_button],
|
engine.input.register_callback(self, button=buttons[pause_button],
|
||||||
cmd=cmd + "--play-pause")
|
cmd=cmd + "--play-pause")
|
||||||
|
|
||||||
|
@scrollable
|
||||||
def deadbeef(self, widget):
|
def deadbeef(self, widget):
|
||||||
return str(self._song)
|
return str(self._song)
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
# pylint: disable=C0111,R0903
|
# pylint: disable=C0111,R0903
|
||||||
|
|
||||||
"""Displays the current song being played
|
"""Displays the current song being played
|
||||||
|
|
||||||
Requires the following library:
|
Requires the following library:
|
||||||
* python-dbus
|
* python-dbus
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* spotify.format: Format string (defaults to "{artist} - {title}")
|
* spotify.format: Format string (defaults to "{artist} - {title}")
|
||||||
Available values are: {album}, {title}, {artist}, {trackNumber}, {playbackStatus}
|
Available values are: {album}, {title}, {artist}, {trackNumber}, {playbackStatus}
|
||||||
* spotify.previous: Change binding for previous song (default is left click)
|
* spotify.previous: Change binding for previous song (default is left click)
|
||||||
* spotify.next: Change binding for next song (default is right click)
|
* spotify.next: Change binding for next song (default is right click)
|
||||||
* spotify.pause: Change binding for toggling pause (default is middle click)
|
* spotify.pause: Change binding for toggling pause (default is middle click)
|
||||||
|
|
||||||
Available options for spotify.previous, spotify.next and spotify.pause are:
|
Available options for spotify.previous, spotify.next and spotify.pause are:
|
||||||
LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK, SCROLL_UP, SCROLL_DOWN
|
LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK, SCROLL_UP, SCROLL_DOWN
|
||||||
"""
|
"""
|
||||||
|
@ -20,6 +17,8 @@ import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
import bumblebee.engine
|
import bumblebee.engine
|
||||||
|
|
||||||
|
from bumblebee.output import scrollable
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dbus
|
import dbus
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -53,6 +52,7 @@ class Module(bumblebee.engine.Module):
|
||||||
engine.input.register_callback(self, button=buttons[pause_button],
|
engine.input.register_callback(self, button=buttons[pause_button],
|
||||||
cmd=cmd + "PlayPause")
|
cmd=cmd + "PlayPause")
|
||||||
|
|
||||||
|
@scrollable
|
||||||
def spotify(self, widget):
|
def spotify(self, widget):
|
||||||
return str(self._song)
|
return str(self._song)
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,30 @@ def scrollable(func):
|
||||||
if len(text) <= width:
|
if len(text) <= width:
|
||||||
return text
|
return text
|
||||||
# we need to shorten
|
# 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)
|
start = widget.get("scrolling.start", -1)
|
||||||
direction = widget.get("scrolling.direction", "right")
|
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)
|
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]
|
text = text[start:width+start]
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
Loading…
Reference in a new issue