Page 1 of 1

WxPanel from thread

Posted: Wed Feb 21, 2018 7:17 pm
by Nico
Hello,

I have a wxPanel that takes a while to load, because the content of the panel depends on a configuration file that is parsed in the constructor. To avoid annoying users, I want to create this wxPanel in a worker thread. Once the panel is created I would like to it to be added into a wxNotebook in the main thread.

I tried the straight forward approach of calling notebook->AddPage() from the thread, but that fails. I then found a post in which it was explained that wxWidgets objects can not be added from another thread than the main thread. There it was suggested to create a (costume) event to transfer the data to the main thread and then display it there.
So now I am looking for a way to create the wxPanel in a helper thread and send it to the main thread as payload of an event. The event handler should then add it to the wxNotebook.

My question: can I send a complete wxPanel as payload of an event and if so, how should this be done?

I already managed to create an event in a separate thread and have the corresponding event handler update the screen accordingly, but how can I add the payload and what are the limitations?

Thanks in advance, Nico

Re: WxPanel from thread

Posted: Wed Feb 21, 2018 9:23 pm
by doublemax
My question: can I send a complete wxPanel as payload of an event and if so, how should this be done?
Don't create a wxPanel (or any GUI element for that matter) in a worker thread.
I have a wxPanel that takes a while to load, because the content of the panel depends on a configuration file that is parsed in the constructor.
What's taking so long here and how long does it take? The parsing of the configuration file? The creation of the individual children?

If the parsing takes so long, do the parsing in a worker thread, collect all the information in a suitable data structure and send that to the main thread through an event.

If the creation of the children takes so long, how many are there? Even creating a very complex GUI shouldn't take longer than half a second, i would say that's an acceptable waiting time. If it takes up to 2 seconds, just display a busy cursor. If it takes longer, you may have to think about whether your user interface is reasonable.

Re: WxPanel from thread

Posted: Thu Feb 22, 2018 8:22 pm
by Nico
Thank you, that is a completely different approach for solving the problem. In fact I don't think the GUI is all that complex, so you are right the majority of the time will be spend loading and processing the configuration files. In my mind this was directly connected to the GUI being loaded and in my current implementation it is, but it doesn't have to be.

Kind regards, Nico