Page 1 of 1

wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Posted: Sat Aug 17, 2019 5:47 pm
by voyage
I have made a dialog with a wxChoice and I have connected the wxEVT_COMMAND_CHOICE_SELECTED event to this function:

Code: Select all

void Prova_wxwidgetsDialog::OnChoice1Select(wxCommandEvent& event)
{
   wxBusyCursor wait;
   usleep(20000000);
}
I expect that for 20 seconds the mouse cursor change to BusyCursor but it doesn't.
What is wrong with this piece of code, how can I change the cursor with a BusyCursor after a choice selected event?
I have tried the code under ubuntu with wxwidgets 3.0.4

Re: wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Posted: Sat Aug 17, 2019 8:26 pm
by Kvaz1r
It would be better if you provided reproducible example.

Does this code works for you?

Code: Select all

#include <wx/wx.h>

class MyFrame : public wxFrame
    {
    public:
        MyFrame(const wxString& title)   : wxFrame(NULL, wxID_ANY, title)
            {
			wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);

			wxString m_choiceChoices[] = { wxT("A"), wxT("B") };
			int m_choiceNChoices = sizeof(m_choiceChoices) / sizeof(wxString);
			m_choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceNChoices, m_choiceChoices, 0);
			m_choice->SetSelection(0);
			m_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED,
				[](wxCommandEvent& ev)
				{
					wxBusyCursor wait;
					wxSleep(5);
				});
			topSizer->Add(m_choice, 0, wxALL, 5);

			this->SetSizer(topSizer);
			this->Layout();
            }
	protected:
		wxChoice* m_choice;
    };

class MyApp : public wxApp
    {
    public:
        virtual bool OnInit() 
            {
            if ( !wxApp::OnInit() )
                return false;
            MyFrame *frame = new MyFrame("wxWidgets application");
            frame->Show(true);
            return true;
            }
    };

wxIMPLEMENT_APP(MyApp);

Re: wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Posted: Sun Aug 18, 2019 8:27 am
by voyage
I have tried your code and it doesn't work as expected too. The cursor doesn't change while during the execution of the commands in the choice select event

Re: wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Posted: Sun Aug 18, 2019 8:49 am
by doublemax
Add a "::wxYield();" after setting the cursor.

Re: wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Posted: Sun Aug 18, 2019 9:14 am
by voyage
Thank you, with Yield now works. I don't understand why with Button click event it's not necessary Yield while it is with choice selected event?