Adding text to a RichTextCtrl during a long-running process

I have an application which has several functions that are somewhat long-running (e.g. 10 to 15 seconds). The application has a console window that displays various messages. The console is a wx.richtext.RichTextCtrl. I would like to do something along the lines of:

Display message “Starting to do thing…”

Do thing

Display message “Done with thing”

but the messages don’t appear until the thing is all done. I tried putting “Do thing” and the final message in a separate function, called with wx.CallAfter, hoping this would give the first message a chance to appear, but that didn’t help. I could put “Do thing” in a different thread, but I don’t really want the user interface to be usable during thing, I only want the message to appear in the console.

Can anyone suggest a way to make this work?

Thanks,

Matthew

Hello,

···

On Nov 16, 2008, at 12:15 PM, Matthew Cahn wrote:

I have an application which has several functions that are somewhat long-running (e.g. 10 to 15 seconds). The application has a console window that displays various messages. The console is a wx.richtext.RichTextCtrl. I would like to do something along the lines of:

Display message "Starting to do thing…"

Do thing

Display message "Done with thing"

but the messages don't appear until the thing is all done. I tried putting "Do thing" and the final message in a separate function, called with wx.CallAfter, hoping this would give the first message a chance to appear, but that didn't help. I could put "Do thing" in a different thread, but I don't really want the user interface to be usable during thing, I only want the message to appear in the console.

Can anyone suggest a way to make this work?

Using threads would probably be the best way. But if you don't want to use them you could add a call to wx.YieldIfNeeded() after calling to add the text to the control. That will give the event loop a chance to process so the screen can be redrawn to show the text.

Cody