I'm playing with MicroPython using asyncio coroutines to do some tasks
(e.g. scan a 4x4 keypad matrix and display stuff on a LCD).
I also tried my PyBoard this week for the first time...
I want to also be able to simulate my environment using wxPython Phoenix
to provide fake LCD and Keypad.
How can I use wxPython Phoenix with Python 3.5/3.7 asyncio
functionality, so that I can run the coroutines and also hand GUI events?
Your example would not work, as MainLoop() does only return once you close your wx application.
As of now, there's no asyncio / wx integration that I'm aware of.
The MainLoop is implemented in C++, so it's probably not trivial to add support.
I have been using Qamash for some small programs (i.e. the PyQt/asyncio integration). asyncio support would probably be the coolest and most important feature to add to wxPython, once Phoenix is released.
As workaround, you could use a separate thread for the asyncio main loop, but that's not as nice as native support.
Alternatively, you may try to run the asyncio loop from within an EVT_IDLE handler. If you try this, please post your results.
Instead of calling loop.run_forever you would need to call _run_once on each idle event. See the implementation of run_forever.
> How can I use wxPython Phoenix with Python 3.5/3.7 asyncio
Your example would not work, as MainLoop() does only return once
you
close your wx application.
As of now, there's no asyncio / wx integration that I'm aware of.
The MainLoop is implemented in C++, so it's probably not trivial
to add
support.
I have been using Qamash for some small programs (i.e. the
PyQt/asyncio
integration). asyncio support would probably be the coolest and
most
important feature to add to wxPython, once Phoenix is released.
As workaround, you could use a separate thread for the asyncio
main
loop, but that's not as nice as native support.
Alternatively, you may try to run the asyncio loop from within an
EVT_IDLE handler. If you try this, please post your results.
Instead of calling loop.run_forever you would need to call
_run_once on
each idle event. See the implementation of run_forever.
Dietmar
Thanks Dietmar,
OK. I think I'll try the EVT_IDLE approach to start with and see
how I go.
I figured there must have been some kind of async integration as
It has 4 gauges in a dialog. Gauge 1 is updated via wxTimer every
100ms. Gauges 2-4 are updated via asyncio coroutines/tasks, every
200ms, 300ms, 400ms respectively.
What is interesting is that gauges are not as synchronised as I
would expect. i.e. gauge 1 and 2 should end exactly the same
time, every 200ms, and gauge 4 should also end at the same time as
gauge 1 and 2 every 400ms, but they are out. It might be my count
reset logic is out by 1?
Brendan.
wxasync it a library for using python 3 asyncio (async/wait) with wxpython. It does GUI message polling every 5ms and runs the asyncio message loop the rest of the time.