wxBusyInfo not working in Ubuntu

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
dermayank
In need of some credit
In need of some credit
Posts: 9
Joined: Fri Jan 22, 2021 8:56 am

wxBusyInfo not working in Ubuntu

Post by dermayank » Fri Mar 12, 2021 7:39 am

I'm following MVC pattern for my application. When the application launches, the Model does some computation in an infinite loop and exits the loop when the operation is completed.

Now, while this initial computation is being performed, I am displaying a wxBusyInfo box with message stating please wait. This works fine in case of Windows, but in Linux the wxBusyInfo box is not visible.

Code: Select all


wxBusyInfo wait("Working on Something in background !"); 
{
    Controller* controller = new Controller();
    controller->Create();
 }

Also, this busyinfo box only contains static information, so I tried creating a wxFrame on the top of wxWindows. This frame will be visible on the screen with dynamic text stating what is currently happening in background.

Now this too was working fine on Windows, but on linux only application sign is visible in Ubunutu Dock and when I'm trying to click on it, following messages shows up
ComplainceApp is not responding
Wait or Force Close.
Last edited by dermayank on Mon Mar 15, 2021 6:57 am, edited 2 times in total.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 3041
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxBusyInfo not working in Ubuntu

Post by PB » Fri Mar 12, 2021 8:40 am

(I use Windows only)

I personally dislike wxBusyInfo very much. On Windows, it stays on top of all windows so it effectively obscures your desktop so one cannot even really use other applications on the same display.
dermayank wrote:
Fri Mar 12, 2021 7:39 am
...I tried creating a wxFrame on the top of wxWindows. This frame will be visible on the screen with dynamic text stating what is currently happening in background.
What about wxProgressDialog?

The correct answer to your problems would be: Never block the UI, do the work in the background thread. I do understand that this is easier said than done.

dermayank
In need of some credit
In need of some credit
Posts: 9
Joined: Fri Jan 22, 2021 8:56 am

Re: wxBusyInfo not working in Ubuntu

Post by dermayank » Fri Mar 12, 2021 9:32 am

Can you provide to some example samples that can be used in such scenarios. I need help on doing interthread communication.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 3041
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxBusyInfo not working in Ubuntu

Post by PB » Fri Mar 12, 2021 9:55 am

I think that if you search for it, you will find many examples.

FWIW, here is my example of very simple code (for some reasons has issues with wxWidgets 3.0 on MSW but works with 3.1)
viewtopic.php?f=1&t=46485#p194840

here is another simple example: viewtopic.php?f=1&t=48112#p204846

Basically, it is very simple:
1. Do not touch any GUI elements in a worker thread (i.e., a thread where wxIsMainThread() returns false).
2. To update the UI from the worker Call wxQueueEvent() (the passed event must be allocated on heap) and handle the event in the main thread where you update the UI.
3. If you need two-side communication between threads, look into wxMessageQueue.

As long as you follow points 1 and 2, it does not matter if you use wxWidgets threading classes (e.g., wxThread or wxMutex) or C++ classes (e.g., std::thread or std::mutex).

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5152
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxBusyInfo not working in Ubuntu

Post by ONEEYEMAN » Fri Mar 12, 2021 1:29 pm

Hi,
So, what is your question?
Or you just restating the fact that wxWidgets GUI classes are not thread-safe?

Thank you.

dermayank
In need of some credit
In need of some credit
Posts: 9
Joined: Fri Jan 22, 2021 8:56 am

Re: wxBusyInfo not working in Ubuntu

Post by dermayank » Mon Mar 15, 2021 6:56 am

PB wrote:
Fri Mar 12, 2021 9:55 am

Basically, it is very simple:
1. Do not touch any GUI elements in a worker thread (i.e., a thread where wxIsMainThread() returns false).
2. To update the UI from the worker Call wxQueueEvent() (the passed event must be allocated on heap) and handle the event in the main thread where you update the UI.
3. If you need two-side communication between threads, look into wxMessageQueue.

I tried following example given here on sending events to main thread -
https://wiki.wxwidgets.org/Inter-Thread ... munication

But here they are passing only values like int or string using events, but I have to send the information stored as vector of vector from the worker thread, so what should I opt for in that case: wxQueueEvent() or by directly passing data to the main thread.
Note I only have to send information from worker thread to main thread not other way around.

Also, can you provide some more information on wxQueueEvent()

PB
Part Of The Furniture
Part Of The Furniture
Posts: 3041
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxBusyInfo not working in Ubuntu

Post by PB » Mon Mar 15, 2021 11:36 am

The example I linked in my previous post shows how to use a custom payload with a wxThreadEvent.

I do not know anything about wxQueueEvent besides what I wrote, is shown in the example, and what is in the docs.

BTW, make sure you understand the difference between joinable and detached threads, see the wxWidgets docs.

Post Reply