Creating mac app with background process which updates the display.

36 views
Skip to first unread message

Issac Kelly

unread,
Oct 27, 2014, 3:28:39 PM10/27/14
to beewar...@googlegroups.com
Hello! Toga is fun, but I'm stuck.

I'm creating a table display to show (and later update) the state of some redis values.

I can make this happen once on startup, but I can't figure out where to put a thread or a loop to keep updating the values. 


Russell Keith-Magee

unread,
Oct 27, 2014, 9:29:34 PM10/27/14
to beewar...@googlegroups.com
Hi Issac,

At present, there isn't a "background update" mechanism such as the one you describe. However, you might be able to rig such an interface using the same internals used to handle button presses. 

When you press a button, it invokes a callback, but if that callback is a generator, the callback itself will be wrapped into a deferred task, and the value yielded will be used as a "sleep" interval between iterations. This means you can stimulate a long-running task in response to a button press, and regularly update the GUI thread.

The "it works right now" option would be to have a "start monitoring Redis" button in your GUI, with a generator callback that is essentially:

def update_redis_values(button):
    while True:
        update_gui()
        yield 1

This will update your GUI once per second once you press the button.

The "patches please" approach would be to formalise an API for running a background task as part of an app. If you look in the utils package for each of the platform backends (e.g., toga_cocoa.utils) you'll see the mechanism that does the callbacks; it shouldn't be that hard to turn that into a public API on toga.App.

Yours,
Russ Magee %-)
Reply all
Reply to author
Forward
0 new messages