I am trying to have my GUI as decoupled as possible form my implementation.
I want the GUI to run independently from the MainProgram.
But as I understand I still need the (MainFrame : wxFrame) to know about the object that will transfer events form the UI to the MainProgram.
Are there some sample examples about this?
Linking UI to external object.
Re: Linking UI to external object.
I'm not quite sure what you're looking for. In the most basic example you have a frame with a single button and an event handler for the button click. In the event handler you just call a method of your gui-less core.
Use the source, Luke!
-
- Earned a small fee
- Posts: 13
- Joined: Thu Jan 30, 2020 2:22 pm
- Location: France / Netherlands
Re: Linking UI to external object.
Hi Akneyzar,
please describe your problem more in detail. What implementation are you talking about ?
What is your platform ?
You can perfectly write a program which keeps the GUI processing completely separated from other processing. I suspect that you want to write your code with the "standard" C approach, with a main() function being the main "program" (what you call "implementation")
If it is the case, this is a very, very bad idea
You can not simply say to wxWidgets "please stay away of my main program". Any wxWidgets application need to be initialized in a specific way and if you want to follow another path, the application will either never start the GUI or will crash.
If you want to keep your "main" processing completely separated from the GUI, the best thing is use a thread. Write your "implementation" in a separate thread and let wxWidgets run in its own thread. The operating system will then do its work to have your thread appear as "running alone"
please describe your problem more in detail. What implementation are you talking about ?
What is your platform ?
You can perfectly write a program which keeps the GUI processing completely separated from other processing. I suspect that you want to write your code with the "standard" C approach, with a main() function being the main "program" (what you call "implementation")
If it is the case, this is a very, very bad idea
You can not simply say to wxWidgets "please stay away of my main program". Any wxWidgets application need to be initialized in a specific way and if you want to follow another path, the application will either never start the GUI or will crash.
If you want to keep your "main" processing completely separated from the GUI, the best thing is use a thread. Write your "implementation" in a separate thread and let wxWidgets run in its own thread. The operating system will then do its work to have your thread appear as "running alone"
-
- In need of some credit
- Posts: 5
- Joined: Wed Apr 21, 2021 2:51 pm
- Location: France, Switzerland
Re: Linking UI to external object.
The project is on Windows with C++. I am originally from embedded systems (C/Linux) so I might have to update my way of doing. I was used to have the UI run in another process and communicate to it through a socket.
My initial idea was to have the GUI in a thread launched by a 'WinMain' funcion (I already have something running), and have all the state machine and processing (camera feeds and image transformation) done in other threads.
So my first step was to integrate the UI with a StateMachine.
I added my StateMachine object as a parameter to myso that when an event happens the MainFrame could call the object function.
I had some difficulties doing so and my current idea is to have my MainFrame inherit wxFrame and StateMachine.
I was wondering if I'm on a complicated path.
I looked at the sample codes but I'm a bit lost as to which one could explain a good code architecture for a system rendering camera feeds.
My initial idea was to have the GUI in a thread launched by a 'WinMain' funcion (I already have something running), and have all the state machine and processing (camera feeds and image transformation) done in other threads.
So my first step was to integrate the UI with a StateMachine.
I added my StateMachine object as a parameter to my
Code: Select all
MainFrame() : wxFrame ()
I had some difficulties doing so and my current idea is to have my MainFrame inherit wxFrame and StateMachine.
Code: Select all
MainFrame : public wxFrame, public StateMachine.
I looked at the sample codes but I'm a bit lost as to which one could explain a good code architecture for a system rendering camera feeds.
Re: Linking UI to external object.
Sounds good.My initial idea was to have the GUI in a thread launched by a 'WinMain' funcion (I already have something running), and have all the state machine and processing (camera feeds and image transformation) done in other threads.
The same principle should work with different threads. Use the event system to send information from the worker thread(s) to the GUI thread, use wxMessageQueue in the other direction. (Events are always processed in the GUI thread, so you can't send an event to a secondary thread).I was used to have the UI run in another process and communicate to it through a socket.
https://docs.wxwidgets.org/trunk/classwx_thread.html
https://docs.wxwidgets.org/trunk/classw ... _01_4.html
Please give an example.I had some difficulties doing so...
Use the source, Luke!
-
- In need of some credit
- Posts: 5
- Joined: Wed Apr 21, 2021 2:51 pm
- Location: France, Switzerland
Re: Linking UI to external object.
The sample principle should work with different threads. Use the event system to send information from the worker thread(s) to the GUI thread, use wxMessageQueue in the other direction. (Events are always processed in the GUI thread, so you can't send an event to a secondary thread).
https://docs.wxwidgets.org/trunk/classwx_thread.html
https://docs.wxwidgets.org/trunk/classw ... _01_4.html
Thanks for the explanations I'll check.
I suspect that there might not be any sample showing this. Right?
Ohh it's an exception occuring in the StateMachine code but our debug tooling has some issues we need to solve for investigating.Please give an example.I had some difficulties doing so...
So we need to work on that.
Re: Linking UI to external object.
Not exactly. The "thread" sample contains the fundamentals you need, but as it demonstrates many things, it's relatively complex and not so easy to follow.I suspect that there might not be any sample showing this. Right?
Use the source, Luke!