diff --git a/py3status/modules/cmus.py b/py3status/modules/cmus.py index 11e3229a84..dc6f5b191a 100644 --- a/py3status/modules/cmus.py +++ b/py3status/modules/cmus.py @@ -16,6 +16,7 @@ *(default '[\?if=is_started [\?if=is_playing > ][\?if=is_paused \|\| ]' '[\?if=is_stopped .. ][[{artist}][\?soft - ][{title}]' '|\?show cmus: waiting for user input]]')* + replacements: specify a list/dict of string placeholders to modify (default None) sleep_timeout: sleep interval for this module. when cmus is not running, this interval will be used. this allows some flexible timing where one might want to refresh constantly with some placeholders... or to refresh @@ -100,6 +101,7 @@ class Py3status: r"[\?if=is_stopped .. ][[{artist}][\?soft - ][{title}]" r"|\?show cmus: waiting for user input]]" ) + replacements = None sleep_timeout = 20 def post_config_hook(self): @@ -109,6 +111,7 @@ def post_config_hook(self): self.color_stopped = self.py3.COLOR_STOPPED or self.py3.COLOR_BAD self.color_paused = self.py3.COLOR_PAUSED or self.py3.COLOR_DEGRADED self.color_playing = self.py3.COLOR_PLAYING or self.py3.COLOR_GOOD + self.replacements_init = self.py3.get_replacements_list(self.format) def _seconds_to_time(self, value): m, s = divmod(int(value), 60) @@ -165,14 +168,14 @@ def cmus(self): cached_until = self.sleep_timeout color = self.py3.COLOR_BAD - is_started, data = self._get_cmus_data() + is_started, cmus_data = self._get_cmus_data() if is_started: cached_until = self.cache_timeout - data = self._organize_data(data) - data = self._manipulate_data(data) + cmus_data = self._organize_data(cmus_data) + cmus_data = self._manipulate_data(cmus_data) - status = data.get("status") + status = cmus_data.get("status") if status == "playing": is_playing = True color = self.color_playing @@ -183,19 +186,23 @@ def cmus(self): is_stopped = True color = self.color_stopped + for x in self.replacements_init: + if x in cmus_data: + cmus_data[x] = self.py3.replace(cmus_data[x], x) + + cmus_data.update( + { + "is_paused": is_paused, + "is_playing": is_playing, + "is_started": is_started, + "is_stopped": is_stopped, + } + ) + return { "cached_until": self.py3.time_in(cached_until), "color": color, - "full_text": self.py3.safe_format( - self.format, - dict( - is_paused=is_paused, - is_playing=is_playing, - is_started=is_started, - is_stopped=is_stopped, - **data, - ), - ), + "full_text": self.py3.safe_format(self.format, cmus_data), } def on_click(self, event): diff --git a/py3status/modules/deadbeef.py b/py3status/modules/deadbeef.py index e20ddb9d17..50e1a0f38f 100644 --- a/py3status/modules/deadbeef.py +++ b/py3status/modules/deadbeef.py @@ -4,6 +4,7 @@ Configuration parameters: cache_timeout: refresh interval for this module (default 5) format: display format for this module (default '[{artist} - ][{title}]') + replacements: specify a list/dict of string placeholders to modify (default None) sleep_timeout: when deadbeef is not running, this interval will be used to allow faster refreshes with time-related placeholders and/or to refresh few times per minute rather than every few seconds @@ -58,6 +59,7 @@ class Py3status: # available configuration parameters cache_timeout = 5 format = "[{artist} - ][{title}]" + replacements = None sleep_timeout = 20 class Meta: @@ -89,6 +91,7 @@ def post_config_hook(self): self.color_paused = self.py3.COLOR_PAUSED or self.py3.COLOR_DEGRADED self.color_playing = self.py3.COLOR_PLAYING or self.py3.COLOR_GOOD self.color_stopped = self.py3.COLOR_STOPPED or self.py3.COLOR_BAD + self.replacements_init = self.py3.get_replacements_list(self.format) def _is_running(self): try: @@ -124,6 +127,10 @@ def deadbeef(self): else: color = self.color_paused + for x in self.replacements_init: + if x in beef_data: + beef_data[x] = self.py3.replace(beef_data[x], x) + return { "cached_until": self.py3.time_in(cached_until), "full_text": self.py3.safe_format(self.format, beef_data), diff --git a/py3status/modules/moc.py b/py3status/modules/moc.py index 585e962be1..21b53bdd96 100644 --- a/py3status/modules/moc.py +++ b/py3status/modules/moc.py @@ -14,6 +14,7 @@ format: display format for this module *(default '\?if=is_started [\?if=is_stopped \[\] moc|' '[\?if=is_paused \|\|][\?if=is_playing >] {title}]')* + replacements: specify a list/dict of string placeholders to modify (default None) sleep_timeout: when moc is not running, this interval will be used to allow one to refresh constantly with time placeholders and/or to refresh once every minute rather than every few seconds @@ -88,6 +89,7 @@ class Py3status: r"\?if=is_started [\?if=is_stopped \[\] moc|" r"[\?if=is_paused \|\|][\?if=is_playing >] {title}]" ) + replacements = None sleep_timeout = 20 def post_config_hook(self): @@ -97,6 +99,7 @@ def post_config_hook(self): self.color_stopped = self.py3.COLOR_STOPPED or self.py3.COLOR_BAD self.color_paused = self.py3.COLOR_PAUSED or self.py3.COLOR_DEGRADED self.color_playing = self.py3.COLOR_PLAYING or self.py3.COLOR_GOOD + self.replacements_init = self.py3.get_replacements_list(self.format) def _get_moc_data(self): try: @@ -133,19 +136,23 @@ def moc(self): is_stopped = True color = self.color_stopped + for x in self.replacements_init: + if x in moc_data: + moc_data[x] = self.py3.replace(moc_data[x], x) + + moc_data.update( + { + "is_paused": is_paused, + "is_playing": is_playing, + "is_started": is_started, + "is_stopped": is_stopped, + } + ) + return { "cached_until": self.py3.time_in(cached_until), "color": color, - "full_text": self.py3.safe_format( - self.format, - dict( - is_paused=is_paused, - is_playing=is_playing, - is_started=is_started, - is_stopped=is_stopped, - **data, - ), - ), + "full_text": self.py3.safe_format(self.format, moc_data), } def on_click(self, event):