I've been working on a server-like wxPython program which uses PyRO
(Python Remote Objects), and I needed to repeatedly call the PyRO
service loop as the program runs.
I did not want to use a timer; ideally, it should have been called
within the main wx application loop (MainLoop()).
Trouble is, MainLoop() only returns when you quit the application, so
I had to replicate the MainLoop functionnality and insert the PyRO
service loop call within.
After some trial-and-error, I found that the following will do:
Run=1
while Run:
app.Yield()
app.ProcessIdle()
daemon.handleRequests(0)
("Yield". What an obvious method name for what it does - no wonder I
had to use trial and error...).
Of course, if anyone sees any pitfalls and has the proverbial "better
way to do it", I'm all ears.
Using Yield in this way will result in an error if any of the event handlers also need to call Yield (because nested yields are not allowed.)
Instead you can override MainLoop with your own implementation as shown in samples/mainloop/mainloop.py or you can decouple things a bit more and run your PyRO daemon in another thread, using wx.CallAfter or some other means to safely pass info back to the GUI thread.
···
On 4/13/10 8:01 AM, Marc Dufour wrote:
I've been working on a server-like wxPython program which uses PyRO
(Python Remote Objects), and I needed to repeatedly call the PyRO
service loop as the program runs.
I did not want to use a timer; ideally, it should have been called
within the main wx application loop (MainLoop()).
Trouble is, MainLoop() only returns when you quit the application, so
I had to replicate the MainLoop functionnality and insert the PyRO
service loop call within.
After some trial-and-error, I found that the following will do:
Run=1
while Run:
app.Yield()
app.ProcessIdle()
daemon.handleRequests(0)
("Yield". What an obvious method name for what it does - no wonder I
had to use trial and error...).
Of course, if anyone sees any pitfalls and has the proverbial "better
way to do it", I'm all ears.