3 ms·
One solution is to use generators in Python. The new Asyncio framework makes it easier to think about concurrency in GUI applications, and it can be used to coo
by bayesianhorse 12y ago
One solution is to use generators in Python. The new Asyncio framework makes it easier to think about concurrency in GUI applications, and it can be used to cooperate with several GUI frameworks' event loops, like QT and Kivy, as well as websockets and other contexts.
It's not immediately obvious how to "yield from start_button()", but the solution is to have a FIFO command queue like in this article. The UI thread pushes commands to this queue and then the coroutine can act on the command.
This also simplifies changing the exact meaning of buttons/keys like "back" depending on the context, and handling multi-step network tasks, like using external APIs, ssh commands to a server, file downloads and the like. Using a command queue in Asyncio makes UI actions and IO events interchangeable.