enkore / i3pystatus

A complete replacement for i3status
https://i3pystatus.readthedocs.io/
MIT License
445 stars 188 forks source link

Generic update in background #315

Open teto opened 8 years ago

teto commented 8 years ago

Hi, I am very happy with how https://github.com/enkore/i3pystatus/issues/311 works and I consider extending this to all modules, ie, display an "in progress" message upon background tasks:

In order for the module to know to display this "In progress" message whiule waiting for the job to finish, you need to give the module a hint. It could be via checking the callback against a specifc type ? on_leftclick=BackgroundCallback () or on_leftclick=["background_command", ]

What do you think ?

enkore commented 8 years ago

When executing commands as callbacks it could remember the PIDs and check / use an alternate formatter while any of these PIDs are active.

teto commented 8 years ago

Here is one usecase with 2 callbacks: 1/ right click: run offlineimap to check if new mail => background task => Want "In progress" formatter 2/ left click: launch "mutt" or "thunderbird". I want the formatter to remain as is. If acting on PID, you have no way to distinguish between the 2 (i.e., changing formatter or not) ?

enkore commented 8 years ago

I see. We could add a helper function that does the formatter switch until a PID dies. That way a callback could be formulated like this:

@get_module
def callback(self):
    pid = run_command()
    self.busy_on_pid(pid)

This could be shipped as a function to use as callback, used like this then

status.register(...
    on_leftclick=busy_execute("command")
)

(Better names are in order)