mpd and title

This commit is contained in:
Dhananjay Tanpure 2022-03-07 08:50:30 +05:30
parent 8867f4f188
commit e5cdabcc0f
No known key found for this signature in database
GPG key ID: 4CCF71A10B0E84B6
2 changed files with 14 additions and 1 deletions

View file

@ -94,6 +94,12 @@ class Module(core.module.Module):
"cmd": "mpc toggle" + self._hostcmd,
}
widget.full_text(self.description)
elif widget_name == "mpd.toggle":
widget_map[widget] = {
"button": core.input.LEFT_MOUSE,
"cmd": "mpc toggle" + self._hostcmd,
}
widget.full_text(self.toggle)
elif widget_name == "mpd.next":
widget_map[widget] = {
"button": core.input.LEFT_MOUSE,
@ -127,6 +133,9 @@ class Module(core.module.Module):
def description(self, widget):
return string.Formatter().vformat(self._fmt, (), self._tags)
def toggle(self, widget):
return str(util.cli.execute("mpc status %currenttime%/%totaltime%", ignore_errors=True)).strip()
def update(self):
self._load_song()

View file

@ -9,6 +9,7 @@ Parameters:
* title.max : Maximum character length for title before truncating. Defaults to 64.
* title.placeholder : Placeholder text to be placed if title was truncated. Defaults to '...'.
* title.scroll : Boolean flag for scrolling title. Defaults to False
* title.short : Boolean flag for short title. Defaults to False
contributed by `UltimatePancake <https://github.com/UltimatePancake>`_ - many thanks!
@ -35,6 +36,7 @@ class Module(core.module.Module):
# parsing of parameters
self.__scroll = util.format.asbool(self.parameter("scroll", False))
self.__short = util.format.asbool(self.parameter("short", False))
self.__max = int(self.parameter("max", 64))
self.__placeholder = self.parameter("placeholder", "...")
self.__title = ""
@ -66,7 +68,9 @@ class Module(core.module.Module):
def __pollTitle(self):
"""Updating current title."""
try:
self.__full_title = self.__i3.get_tree().find_focused().name
focused = self.__i3.get_tree().find_focused().name
self.__full_title = focused.split(
"-")[-1].strip() if self.__short else focused
except:
self.__full_title = no_title
if self.__full_title is None: