OnIdle Event is sent multiple times Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Gnawer
Experienced Solver
Experienced Solver
Posts: 61
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

OnIdle Event is sent multiple times

Post by Gnawer » Sat Feb 10, 2007 6:02 pm

I have a simple dialog based application (like that from wxWidgets-Tutorial).
I have defined a OnIdle Event. When receiving the idle event I want to set a dialog textctrl to the string "idle".
When the user presses a button, the text is replaced by "working".

So far, so good. But I have never expected to receicve a endless amount of idle events, so that the "idle" text is really flickering.
What is the reason for this behaviour?
Best regards
Gnawer

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Sat Feb 10, 2007 6:50 pm

Remember that paint events are only sent when the window actually needs painting while idle events are sent all the time 8).

You could try using a wxStopWatch and draw it at a defined interval :).
[Mostly retired moderator, still check in to clean up some stuff]

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Sun Feb 11, 2007 9:30 am

OnIdle is exactly what it says. There are no events in the event queue so this event is sent every check to do e.g. low level processing. OnIdle events are useful for e.g. updating a log window, or semi-process something in a worker routine because there are no other events that need to be processed and this way you evoid the "frozen" behaviour of a window, when the click events or paint events are not handled in a certain time

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Gnawer
Experienced Solver
Experienced Solver
Posts: 61
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

Post by Gnawer » Sun Feb 11, 2007 5:35 pm

Below is an extract from the wxWidgets Manual (wxIdleEvent):

"Note that, unless you do something specifically, the idle events are not sent if the system remains idle once it has become it, e.g. only a single idle event will be generated until something else resulting in more normal events happens and only then is the next idle event sent again.
...
If you need to ensure a continuous stream of idle events, you can either use RequestMore method in your handler or call wxWakeUpIdle periodically (for example from timer event), but note that both of these approaches (and especially the first one) increase the system load and so should be avoided if possible."

Therefore I expected 1 idle event. I wanna avoid the unneccessary system load, but how to do?
Best regards
Gnawer

DavidHart
Site Admin
Site Admin
Posts: 4081
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Sun Feb 11, 2007 6:06 pm

Hi,
"Note that, unless you do something specifically..."
But one of those 'somethings' is moving the mouse, which generates a stream of idle events. You certainly can't rely on there being only one.

What you can do is to use a bool, probably a member variable of your subclassed textctrl. Catch idle events, but in the handler only write to the textctrl if the bool isn't set, and then set it. At the end of your button-handler, when the 'working' is over, reset the bool.

Regards,

David

Gnawer
Experienced Solver
Experienced Solver
Posts: 61
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

Post by Gnawer » Tue Feb 13, 2007 12:17 pm

The events come in without moving the mouse.
But I understand the problem and will use a boolean.

Thanx! :)
Best regards
Gnawer

Post Reply