Modal and threads question 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
ScEngMan
Earned a small fee
Earned a small fee
Posts: 14
Joined: Wed Oct 01, 2008 12:45 pm
Location: Canada
Contact:

Modal and threads question

Post by ScEngMan »

Hello,

I'm developing a typical 3D application, where a modeless dialog box allows the user to set the rendering width and height, and when the user clicks Render, a modal render progress dialog box is shown and rendering starts.

Image

I'm opening the Progress dialog box with a ShowModal call... but I haven't found the threads combination to be able to show the progress dlg, and start rendering right away.

And there is also a View Image modeless panel which shows the image that is being rendered (the image is updated every time a 32x32 pixels bucket is rendered.) This View Image panel needs to be accesible and ready for mouse input to display information about the image itself (colors, alpha, elements, etc.)

Does anybody knows a way to handle this correctly?

thank you,
Diego
Last edited by ScEngMan on Wed Oct 01, 2008 2:23 pm, edited 1 time in total.
Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank »

I start my threads mostly in the constructor. Sometimes I make a MyDialog::doIt(), wich first starts the thread, then calls ShowModal on itself.

Code: Select all

bool MyDialog::doIt ()
{
   boost::thread(boost::bind(&MyDialog::thread, this)); // Should work fine with wxThread too, but I don't know how to use it
   return ShowModal() == wxID_OK;
}
Never had any problems with any of these options. The thread runs just fine, even when your window is not visble at the moment.

Third option (never used it, but should work too): Post yourself an Event at the end of your constructor. The handler starts the thread. That way your thread should start *after* the call to ShowModal().
ScEngMan
Earned a small fee
Earned a small fee
Posts: 14
Joined: Wed Oct 01, 2008 12:45 pm
Location: Canada
Contact:

Post by ScEngMan »

Thank you Frank, it works very well.

Actually I was editing the post while you replied...

I also have to deal with the View Image File panel. I'll test to see if making it a modeless child of the ProgressDlg I can keep both active. Any ideas here?

Thank you very much for your help!
Diego
ScEngMan
Earned a small fee
Earned a small fee
Posts: 14
Joined: Wed Oct 01, 2008 12:45 pm
Location: Canada
Contact:

Post by ScEngMan »

I tried to create a Modeless View Image frame from both the Progress Dlg and Rendering Dlg, and in both cases it is created, but as soon as I call ProgressDlg::ShowModal, the View Image frame becomes inactive and is or closed or moved to the background.

Any ideas on how to make this work?

These are the main windows:

SceneViewerFrame : The app main frame
RenderingDlg : A modeless window
ProgressDlg : A modal progress dlg with Pause/Continue and Stop
ViewImageFrame : A frame that displays the image that is being rendered and allows the user to pick pixels for info.

This is the workflow (u:user a:application w:wish)

u : SceneViewerFrame > Menu > Tools > Rendering
a : Opens the RenderingDlg
u : Hit Render button
a : RenderingDlg create a thread for the renderer
a : RenderingDlg create a ProgressDlg and Shows it with ShowModal
w : RenderingDlg or ProgressDlg open a ViewImageFile frame
a : Rendering is finished and the ProgressDlg closses
w : ViewImageFile is not closed

The w items are those I wish to have working, but I can't find a way to get it done.

Thank you
Diego
Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank »

I tried that some time ago. Never found a solution. Seems to be a design flaw of wx. It's no Problem with WinAPI or other toolkits to make your Dialog Modal to your Parent and only the parent. But with wx that seems to be imposslble.

The same goes for MakeModal().
ScEngMan
Earned a small fee
Earned a small fee
Posts: 14
Joined: Wed Oct 01, 2008 12:45 pm
Location: Canada
Contact:

Post by ScEngMan »

Yeah, I tried many things with ShowModal and nothing worked.

Now I'm trying to Disable the main frame and the Rendering Dlg when render starts, and Enable them again when render ends.

In wx docs it says about Enable/Disable:

"Enable or disable the window for user input. Note that when a parent window is disabled, all of its children are disabled as well and they are reenabled again when the parent is."

This is true for docked windows, but my other windows are not disabled. Is there a way to force disable in everything?

Or is there a way to get all existing wxWindows in my application to use a Disable in all of them?

Thanks
Post Reply