Unwanted/unexpected event: what should i look for? 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
User avatar
Parduz
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Unwanted/unexpected event: what should i look for?

Post by Parduz » Fri Feb 07, 2020 10:22 am

I understand that this will be a difficult question, as my project is pretty big and i cannot share it here... still i think it worth a try:

My UI app is a "kiosk" app that runs on a BeagleBone Black with a touchscreen and a custom keyboard. It is "based" on wxSimpleBooks: on the main wxFrame i have a main wxSimpleBook that right now have 15 pages, most of them containing another wxSimpleBook for subpages.
Knowing on what page you are is very important (to know what to do with the "ENTER" or "F1" keys press, as example).

So i have pagechanging and pagechanged events sets for almost each of my wxSimpleBooks, the main one saves the current page in a currentpage global variable.

My problem is that now another wxSimpleBook fires the same event of the main one, messing with the currentpage !

m_MainPages is the "main" wxSimpleBook, m_pFirmwareUpdate is another wxSimpleBook contained in m_MainPages 9th page.
I tried to "log" what's happening, so this is the relevant code:

Code: Select all

//[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void GUI_MainForm::OnMainPagesPageChanged(wxNotebookEvent& event)
{
	int op = event.GetOldSelection();
	int np = event.GetSelection();
	wxObject*	evobj = event.GetEventObject();
	wxWindow*	evwin = dynamic_cast<wxWindow*>(evobj);
	cout << __FUNCTION__ << " from " << evwin->GetName() << ": " << op << " => " << np << endl;
}
//[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void GUI_MainForm::OnMainPagesPageChanging(wxNotebookEvent& event)
{
	int op = event.GetOldSelection();
	int np = event.GetSelection();
	wxObject*	evobj = event.GetEventObject();
	wxWindow*	evwin = dynamic_cast<wxWindow*>(evobj);
	cout << __FUNCTION__ << " from " << evwin->GetName() << ": " << op << " => " << np << endl;
	event.Skip();
}
//[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void GUI_MainForm::OnFirmwaresSubpagesPageChanged(wxNotebookEvent& event)
{
	cout << __FUNCTION__ << endl;
	event.Skip();
}
//[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
void GUI_MainForm::OnFirmwaresSubpagesPageChanging(wxNotebookEvent& event)
{
	cout << __FUNCTION__ << endl;
	event.Skip();
}
//[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]

This is the output:
Going to the 9th page:
OnMainPagesPageChanging from m_MainPages: 2 => 9
OnMainPagesPageChanged from m_MainPages: 2 => 9
While there, changing the subpage:
OnFirmwaresSubpagesPageChanging (OK)
OnMainPagesPageChanging from m_FirmwaresSubPages: 0 => 2 (WHY?)
OnFirmwaresSubpagesPageChanged (OK)
OnMainPagesPageChanged from m_FirmwaresSubPages: 0 => 2 (WHY?)
I don't get why i have the OnMain... event fired: i've build the app with wxCrafter and these are the only relevant lines of even binding:

Code: Select all

    m_MainPages->Connect(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler(fMainForm::OnMainPagesPageChanged), NULL, this);
    m_MainPages->Connect(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxNotebookEventHandler(fMainForm::OnMainPagesPageChanging), NULL, this);
    m_FirmwaresSubPages->Connect(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler(fMainForm::OnFirmwaresSubpagesPageChanged), NULL, this);
    m_FirmwaresSubPages->Connect(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxNotebookEventHandler(fMainForm::OnFirmwaresSubpagesPageChanging), NULL, this);
What should i look for? what should i debug, or check or .... ?
I'm pretty lost.


(this is how the app is built, if this helps):
app build.png

User avatar
doublemax
Moderator
Moderator
Posts: 15164
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Unwanted/unexpected event: what should i look for?

Post by doublemax » Fri Feb 07, 2020 10:43 am

Remove the "event.Skip();". Unless you put them there for a purpose. That line makes the event propagate upwards in the window hierarchy.

You hardly ever Skip() wxCommandEvents.
Use the source, Luke!

User avatar
Parduz
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: Unwanted/unexpected event: what should i look for?

Post by Parduz » Fri Feb 07, 2020 1:24 pm

doh!

Thanks #-o

Post Reply