Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

player-mpris-tail: added scrolling to always have a fixed length text but still show the whole Title/Artist #340

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions polybar-scripts/player-mpris-tail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Argument | Description | Default
-b, --blacklist | Blacklist / Ignore the given player
-w, --whitelist | Whitelist / Permit the given player
-f, --format | Use the given `format` string | `{icon} {artist} - {title}`
-s, --scroll | set when to start scrolling, 0 means no scrolling | 0
--scroll-speed | delay in ms until the next character is shown. | 250
--truncate-text | Use the given string as the end of truncated text | `…`
--icon-playing | Use the given text as the playing icon | `⏵`
--icon-paused | Use the given text as the paused icon | `⏸`
Expand Down Expand Up @@ -110,6 +112,16 @@ tail = true

Example: `⏵ Artist - Title`

### Basic output that starts to scroll if the output is longer than 30 characters

```ini
[module/player-mpris-tail]
type = custom/script
exec = ~/polybar-scripts/player-mpris-tail.py -f '{icon} {artist} - {title}' --scroll=30 --scroll-speed=300
tail = true
```

Example: `tist - Title --- A`

### Basic output and mouse controls

Expand Down
39 changes: 37 additions & 2 deletions polybar-scripts/player-mpris-tail/player-mpris-tail.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,45 @@ def __missing__(self, key):
Seems to assure print() actually prints when no terminal is connected
"""

SCROLL_CHARACTER_LIMIT = 30
currentScrollCharacter = 0
timeoutReference = ""
SCROLL_SPEED = 250
_last_status = ''
def _printFlush(status, **kwargs):
global _last_status
global SCROLL_CHARACTER_LIMIT
global timeoutReference
if status != _last_status:
print(status, **kwargs)
sys.stdout.flush()
if timeoutReference != "":
GLib.source_remove(timeoutReference)
timeoutReference = ""
if SCROLL_CHARACTER_LIMIT != 0 and len(status)>SCROLL_CHARACTER_LIMIT:
_printScrolling(status +" ---", **kwargs)
else:
print(status, **kwargs)
sys.stdout.flush()

_last_status = status

def _printScrolling(string, **kwargs):
global SCROLL_CHARACTER_LIMIT
global currentScrollCharacter
global SCROLL_SPEED
global timeoutReference
printString = string[currentScrollCharacter:currentScrollCharacter+SCROLL_CHARACTER_LIMIT]

if SCROLL_CHARACTER_LIMIT + currentScrollCharacter > len(string):

rolloverAmmount = SCROLL_CHARACTER_LIMIT + currentScrollCharacter - len(string)
printString += string[0: rolloverAmmount]
print(printString,**kwargs)
sys.stdout.flush()
if(currentScrollCharacter<len(string)-1):
currentScrollCharacter += 1
else:
currentScrollCharacter =0
timeoutReference = GLib.timeout_add(SCROLL_SPEED, _printScrolling,string)


parser = argparse.ArgumentParser()
Expand All @@ -498,6 +529,8 @@ def _printFlush(status, **kwargs):
metavar="BUS_NAME",
default=[])
parser.add_argument('-f', '--format', default='{icon} {:artist:{artist} - :}{:title:{title}:}{:-title:{filename}:}')
parser.add_argument('-s', '--scroll', default='0',help="when the text is to long scroll trough it. Set to the number of characters that get shown")
parser.add_argument('--scroll-speed', default='250',help="delay in ms until the next character is shown.")
parser.add_argument('--truncate-text', default='…')
parser.add_argument('--icon-playing', default='⏵')
parser.add_argument('--icon-paused', default='⏸')
Expand All @@ -509,6 +542,8 @@ def _printFlush(status, **kwargs):
NEEDS_POSITION = "{position}" in FORMAT_STRING

TRUNCATE_STRING = args.truncate_text
SCROLL_CHARACTER_LIMIT = int(args.scroll)
SCROLL_SPEED = int(args.scroll_speed)
ICON_PLAYING = args.icon_playing
ICON_PAUSED = args.icon_paused
ICON_STOPPED = args.icon_stopped
Expand Down