wxPython: TextCtrl delayed update when using TE_RICH(2)

jean-michel bain-cornu pythonnews at nospam.jmbc.fr
Mon Feb 5 10:53:59 EST 2007


>> For this kind of stuff, I'd try to put "self.out.WriteText(string)" in
>> some 'Idle' event, which avoid to fall in focus loops or other objects
>> events management problems not easy to solve.
>>
> 
> This doesn't have anything to do with focus loops or otherwise, it's
> because the OP isn't familiar with event based programming.
> 
> You're performing a long-running task which is preventing the event
> loop from processing, so your text isn't updating and your application
> is unresponsive. You need to rewrite your task - either do everything
> asynchronously, or use a threaded approach. If you use the thread
> approach, be sure to not call the updates directly, you can use the
> wx.CallAfter mechanism to call gui functions in a threadsafe manner.

So it is an event management problem.
The event loop is not yet finished when the program want to display 
something, potentially initiating a new event loop.

If you don't want to bother with threads, the idle event approach is not 
so bad. Put something to display in a buffer, and display it only one 
time the gui have nothing else to do.
I use it every time I can, and it's very safe and easy to do. 
Furthermore, you can still step into the program with a debugger, which 
can be tricky if the program uses threads (I'd say impossible, but I 
didn't try in fact).

Regards
jm



More information about the Python-list mailing list