diff --git a/bumblebee_status/modules/contrib/playerctl.py b/bumblebee_status/modules/contrib/playerctl.py index 56af426..7fef412 100755 --- a/bumblebee_status/modules/contrib/playerctl.py +++ b/bumblebee_status/modules/contrib/playerctl.py @@ -12,6 +12,7 @@ Parameters: Widget names are: playerctl.song, playerctl.prev, playerctl.pause, playerctl.next * playerctl.args: The arguments added to playerctl. You can check 'playerctl --help' or `its README `_. For example, it could be '-p vlc,%any'. + * playerctl.hide: Hide the widgets when no players are found. Defaults to "false". Parameters are inspired by the `spotify` module, many thanks to its developers! @@ -32,6 +33,8 @@ class Module(core.module.Module): self.background = True + self.__hide = util.format.asbool(self.parameter("hide", "false")); + self.__layout = util.format.aslist( self.parameter( "layout", "playerctl.prev, playerctl.song, playerctl.pause, playerctl.next" @@ -83,14 +86,20 @@ class Module(core.module.Module): if isinstance(callback_options, dict): core.input.register(widget, **callback_options) - def update(self): + def hidden(self): + return self.__hide and self.status() == None + + def status(self): try: playback_status = str(util.cli.execute(self.__cmd + "status 2>&1 || true", shell = True)).strip() if playback_status == "No players found": - playback_status = None + return None + return playback_status except Exception as e: logging.exception(e) - playback_status = None + return None + + def update(self): for widget in self.widgets(): if playback_status: if widget.name == "playerctl.pause": diff --git a/docs/modules.rst b/docs/modules.rst index ad4a307..24046a0 100644 --- a/docs/modules.rst +++ b/docs/modules.rst @@ -1095,6 +1095,7 @@ Parameters: Widget names are: playerctl.song, playerctl.prev, playerctl.pause, playerctl.next * playerctl.args: The arguments added to playerctl. You can check 'playerctl --help' or `its readme `_. For example, it could be '-p vlc,%any'. + * playerctl.hide: Hide the widgets when no players are found. Defaults to "false". Parameters are inspired by the `spotify` module, many thanks to its developers!