From 2890f942f395b243da957661d5dd4be61466871a Mon Sep 17 00:00:00 2001 From: enkore Date: Tue, 2 Feb 2016 16:01:28 +0100 Subject: [PATCH] configuration.rst: update example callbacks --- docs/configuration.rst | 14 +++++++++++++- i3pystatus/core/util.py | 3 +-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 75485ae..0247b8c 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -321,12 +321,21 @@ amount of percent to add/subtract from the current volume. .. rubric:: Python callbacks -These refer to to any callable Python object (most likely a function). +These refer to to any callable Python object (most likely a +function). To external Python callbacks that are not part of the +module the ``self`` parameter is not passed by default. This allows to +use many library functions with no additional wrapper. + +If ``self`` is needed to access the calling module, the +:py:func:`.get_module` decorator can be used on the callback: .. code:: python + from i3pystatus import get_module + # Note that the 'self' parameter is required and gives access to all # variables of the module. + @get_module def change_text(self): self.output["full_text"] = "Clicked" @@ -341,6 +350,9 @@ You can also create callbacks with parameters. .. code:: python + from i3pystatus import get_module + + @get_module def change_text(self, text="Hello world!", color="#ffffff"): self.output["full_text"] = text self.output["color"] = color diff --git a/i3pystatus/core/util.py b/i3pystatus/core/util.py index c5169f4..a3c40bd 100644 --- a/i3pystatus/core/util.py +++ b/i3pystatus/core/util.py @@ -567,8 +567,7 @@ def get_module(function): .. code:: python - from i3pystatus import Status - from i3pystatus.core.util import get_module + from i3pystatus import Status, get_module from i3pystatus.core.command import execute status = Status(...) # other modules etc.