wxBusyCursor and wxSafeYield 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
entell
Earned some good credits
Earned some good credits
Posts: 117
Joined: Wed Apr 06, 2005 3:55 am

wxBusyCursor and wxSafeYield

Post by entell » Thu Jan 26, 2006 3:50 am

Code: Select all

	wxBusyCursor busy;

	for (int i=0; i<5000; i++)
	{
                wxSleep(2);
		wxSafeYield();
	}

This is a simplistic code to get my point across. I have other code where wxSleep() is, but what it does doesn't matter for my question.

In this code, if I take out wxSafeYield(), the mouse pointer changes to an hourglass. If I leave it as it is, the mouse pointer does not change..

Why is that? Is there a way to have both?

Is this even safe to do -calling wxSafeYield() inside a for loop?

By the way, replacing wxSafeYield() with wxYield() does work, but I don't want to use it since it doesn't disable the windows.

entell
Earned some good credits
Earned some good credits
Posts: 117
Joined: Wed Apr 06, 2005 3:55 am

Post by entell » Thu Jan 26, 2006 4:06 am

I found this online but there is no answer in that thread either.

http://lists.wxwidgets.org/archive/wx-u ... 62737.html

Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

Post by Bundy » Thu Jan 26, 2006 11:09 am

I had this same proble and I had to use

wxWindowDisabler disable;

instead of

::wxSafeYield();

Aha, I have problem with wxBusyCursor on linux so I create my own class

Code: Select all

#ifndef WXWAITCURSOR_HPP
#define WXWAITCURSOR_HPP

#include <wx/cursor.h>
#include <wx/window.h>

class wxWaitCursor
{
public:
	wxWaitCursor()
	{
		wxSetCursor(*wxHOURGLASS_CURSOR);
    }
    ~wxWaitCursor()
    {
		wxSetCursor(wxNullCursor);
    }
};

#endif

and when I need to disable window because some operations take some time I pu before this operations:

Code: Select all

	wxWindowDisabler disable;
	wxWaitCursor wait;

Regards
Bundy
"Fate rewards prepared mind"

Quote from movie "Liberator 2"

entell
Earned some good credits
Earned some good credits
Posts: 117
Joined: Wed Apr 06, 2005 3:55 am

Post by entell » Thu Jan 26, 2006 5:14 pm

I see what you are saying. I was disecting wxSafeYield() in the source code, and saw wxWindowDisabler. Assuming this will take care of the mouse cursor problem, I think I still need to use wxYield to get around the "window freezing" problem when there is a long lasting operation, correct?

By the way, as long as the windows are disabled and there is no reentrency problem, there is nothing wrong with calling wxYield() multiple times (like in a while loop), correct?

entell
Earned some good credits
Earned some good credits
Posts: 117
Joined: Wed Apr 06, 2005 3:55 am

Update

Post by entell » Fri Jan 27, 2006 12:39 am

For some reason, as soon as the toplevel window (the one that is the parent of all the other controls) of the application is disabled, the mouse cursor goes back to the default "pointer" from the "hour-glass".

Using wxSafeYield(), wxWindowDisabler disable, and also Disable() all have the same effect!

entell
Earned some good credits
Earned some good credits
Posts: 117
Joined: Wed Apr 06, 2005 3:55 am

Post by entell » Fri Jan 27, 2006 2:43 am

Another frustrating point! If I use wxWindow::Update instead of Yield(), this works too, but this time, as soon as I re-enable the top window (and all the other children controls), the controls start processing any events that they received while they were disabled... I want any event received during the disabled time to be ignored. How do I do that??

entell
Earned some good credits
Earned some good credits
Posts: 117
Joined: Wed Apr 06, 2005 3:55 am

Post by entell » Fri Jan 27, 2006 3:47 pm

It looks like if I call Refresh() or Update() in the for loop instead of wxYield(), and call wxYield() right before I re-enable the controls, that takes care of all my problems.

I am also open to any other suggestions...

Post Reply