wxPython fast and slow

iu2 israelu at elbit.co.il
Mon Mar 9 10:02:36 CET 2009

On Mar 9, 4:18 am, David Bolen <db3l.... at gmail.com> wrote:
> iu2 <isra... at elbit.co.il> writes:
> Then even a time.sleep() or plain loop isn't sufficient since each may
> have additional latencies depending on load.  You will probably need
> to query a system clock of some type to verify when your interval has
> passed.

> You might also try an idle event, implementing your own timer (using
> whatever call gives you the best resolution on your platform), and
> just ignoring idle events that occur more frequently than the timing
> you want.  Just remember to always request a new event.  You could do
> the same thing with CallAfter as well, just reschedule a new one if
> the current one is faster than your preferred interval.
> -- David

Thanks, I need to give it a try.

> Except that CallAfter passed control back through the event loop which is
> crucial for your GUI to appear responsive in other ways.

A question about CallAfter: As I understand, this function is intended
to be used from within threads, where it queues the operation to be
performed in the GUI queue.
But in this example there are no other threads except for the GUI
thread itself, from which CallAfter is called.
How does it work in this situation? Does it queue the opreation for
some idle time or does it perform it right away?
I thought that it probably performs it immediately in this case so it
is exactly like calling the operation directly.

And another question, if I may, I used to make tight loops in windows
API, planting inside them a command that processes messages from the
GUI queue and returns when no more messages exists. Something like

loop {

The loop ran quickly and the GUI remained responsive during the loop.
I did it on window API using a function I defined similar to this one:

void ProcessMessages()
  while (PeekMessage(....)) {

This technique is not good for long loops, where the user may activate
other long GUI opreations during the tight loop and make a mess.
But it carries out the job well where during the time of the loop the
user may only access to certain features, such as pressing a button to
cancel the operation, operating the menu to exit the program, etc.
This scheme saves some state-machine code that is required when using
event-based programming.

Does wxPython have something like ProcessMessages?


More information about the Python-list mailing list