From 40a2eec8aec6c5de1f2a333a419ed4eef6b2162c Mon Sep 17 00:00:00 2001 From: David Laubersheimer Date: Sun, 1 Aug 2021 14:27:23 +0200 Subject: [PATCH 1/3] added scrolling to always have a fixed length --- .../player-mpris-tail/player-mpris-tail.py | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) mode change 100755 => 100644 polybar-scripts/player-mpris-tail/player-mpris-tail.py diff --git a/polybar-scripts/player-mpris-tail/player-mpris-tail.py b/polybar-scripts/player-mpris-tail/player-mpris-tail.py old mode 100755 new mode 100644 index 6d2cb2b1..726a3135 --- a/polybar-scripts/player-mpris-tail/player-mpris-tail.py +++ b/polybar-scripts/player-mpris-tail/player-mpris-tail.py @@ -474,14 +474,43 @@ 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 if status != _last_status: - print(status, **kwargs) - sys.stdout.flush() + if SCROLL_CHARACTER_LIMIT != 0 and len(status)>SCROLL_CHARACTER_LIMIT: + if timeoutReference != "": + GLib.source_remove(timeoutReference) + _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) +1 + printString += string[0: rolloverAmmount] + print(printString,**kwargs) + sys.stdout.flush() + if(currentScrollCharacter Date: Sun, 1 Aug 2021 14:41:15 +0200 Subject: [PATCH 2/3] added argumeents and an example to readme --- polybar-scripts/player-mpris-tail/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/polybar-scripts/player-mpris-tail/README.md b/polybar-scripts/player-mpris-tail/README.md index c6726091..2499c3ab 100644 --- a/polybar-scripts/player-mpris-tail/README.md +++ b/polybar-scripts/player-mpris-tail/README.md @@ -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 | `⏸` @@ -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 From a6e86bd9f8371cc25bb30e7cc0f3dbb8feddfc99 Mon Sep 17 00:00:00 2001 From: David Laubersheimer Date: Mon, 2 Aug 2021 13:41:22 +0200 Subject: [PATCH 3/3] fixed not updating if new text doesnt scroll --- polybar-scripts/player-mpris-tail/player-mpris-tail.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/polybar-scripts/player-mpris-tail/player-mpris-tail.py b/polybar-scripts/player-mpris-tail/player-mpris-tail.py index 726a3135..a25c6463 100644 --- a/polybar-scripts/player-mpris-tail/player-mpris-tail.py +++ b/polybar-scripts/player-mpris-tail/player-mpris-tail.py @@ -482,10 +482,12 @@ def __missing__(self, key): def _printFlush(status, **kwargs): global _last_status global SCROLL_CHARACTER_LIMIT + global timeoutReference if status != _last_status: + if timeoutReference != "": + GLib.source_remove(timeoutReference) + timeoutReference = "" if SCROLL_CHARACTER_LIMIT != 0 and len(status)>SCROLL_CHARACTER_LIMIT: - if timeoutReference != "": - GLib.source_remove(timeoutReference) _printScrolling(status +" ---", **kwargs) else: print(status, **kwargs) @@ -502,14 +504,14 @@ def _printScrolling(string, **kwargs): if SCROLL_CHARACTER_LIMIT + currentScrollCharacter > len(string): - rolloverAmmount = SCROLL_CHARACTER_LIMIT + currentScrollCharacter - len(string) +1 + rolloverAmmount = SCROLL_CHARACTER_LIMIT + currentScrollCharacter - len(string) printString += string[0: rolloverAmmount] print(printString,**kwargs) sys.stdout.flush() if(currentScrollCharacter