enkore/i3pystatus — pull request #137 by teto (2014-10-28 22:13:44+00:00)
Title: [RFC] Custom callback on clicks

This is not meant as a PR yet, but more as a request for comments, on how to tackle the following problem. As such it's not pep8 compliant or clean.

i3pystatus introduces click supports with on_leftclick()/on_rightclick() members but their behavior is hardcoded. I believe it would be more interesting to still provide a default behavior, but allow to easily override it.

There could be several way to do it such as doing:
"""
clock=status.register("clock", ...)
clock.on_leftclick = (myCallback)
"""
but as the i3pystatus examples (thus users) don't get the value returned by status.register, I've preferred to set the callbacks as additionnal settings. i3pystatus does not take into account its parent settings so I've implemented settings inheritance (could be done in a more backward compatible way I guess since I changed the flatten_settings() prototype ) so that on_lclick callback is implemented in "Module" and inherited by all other modules.
I provide a "Command" wrapper that is able to call a module member function or launch an external script ( i3pystatus needs a generic function to launch subprocesses since it is used in several places). Ideally it could also execute a user python function.

Here is an example of how to use the current interface.
"""
[...legacy status configuration...]

from i3pystatus.core.command import Command

clock=status.register("clock", format=[
"%a %-d %b %X toto",
("%a %-d %b %X",'Europe/Paris'),
],
# will execute an external process
on_lclick=Command("notify-send 'hello world'")
# call member function
,on_rclick=Command("next_format",3)
)
""""

Nb: I noticed some similarities between powerline and i3pystatus, maybe there could be some convergence between the 2 ?