wxPython: TextCtrl delayed update when using TE_RICH(2)

Chris Mellon arkanes at gmail.com
Mon Feb 5 08:52:17 EST 2007


On 2/4/07, jean-michel bain-cornu <pythonnews at nospam.jmbc.fr> wrote:
> Hi,
> > def Execute(self, evt):
> >     print "Start query"
> >     time.sleep(5)
> >
> > The "Start query" message should show in the *messages* box when I
> > press the button. Instead, it shows only after the time.sleep(5)
> > delay.
> >
> > If I don't use the wx.TE_RICH / wx.TE_RICH2 style on *messages*, the
> > text shows before the time.sleep(5)
>
> 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.

There is a lot of information about this on the wxPython wiki and in
the archives of the wxpython-users ML.



More information about the Python-list mailing list