Page 1 of 1

special semi-modal dialog

Posted: Wed Oct 21, 2009 4:49 pm
by spectrum
Hello All,

i am looking for a special dialog, but maybe there is already some chance, or an easy way to implement it:

If you loow at Wireshark, there are some warning popup dialogs (done trough gtk), for example if you write a wrong filter in the filter bar, an error dialog popup.

These dialogs allow the interface below to be updated, so i suppose the main loop still process events like OnIdle.
At the same time they are modal, so no actions in the GUI below are allowed.

As far as i know, wxWidgets ShowModal() block other frame events, and main frame OnIdle() is no more processed.

I am trying to implement something like this, using KillFocus events, to avoid to click on other windows, anyway it is resulting quite hard and i don't think it is the right way to do this.

Any help is really appreciated.
Angelo

Posted: Thu Oct 22, 2009 9:24 am
by DavidHart
Hi Angelo,

I don't know if wxWindowDisabler blocks the event loop too, but it would be worth trying.

Regards,

David

Posted: Tue Oct 27, 2009 6:36 pm
by spartygw
Yeah, I think you can do what you want with a combination of a dialog-derived class and doing:

Code: Select all


MyDialog *myDialog = new MyDialog();

while (someJobNotYetComplete)
{
  wxYieldIfNeeded();
  myDialog->Pulse();
  wxYieldIfNeeded();  
}
The constructor of the MyDialog class would have this at the end:

Code: Select all

  m_WinDisabler = new wxWindowDisabler(this);
  Show();
  Enable();
  wxDialog::Update();
Then delete the m_WinDisabler in the dtor. The condition for the while loop would presumably be some variable set if you were waiting on work being done in the background. This is just the scenario that I needed. It sounds like your problem might be even easier to solve.

I got this idea and from another post a while back, so someone else deserves the credit.

I use it in my app to update my custom progress dialog while still drawing the main GUI with updates behind it (but not allowing user input to muck with it).

Good luck.
-gw

Posted: Wed Oct 28, 2009 6:58 pm
by spectrum
many thanks,

anyway, wxWindowsDisabler block the main frame loop.
Every kind of for/while loop will not make the main loop to return.
And i need it to return since i have to enter the MainFrame::OnIdle where i process some GUI updates.

So i have found only one solution actually, let me know if you see some ctitical points:

I derive from wxDialog, in constructor i collect all the childrens into a wxWindowList, i connect all the children kill_focus events to a single static OnLostFocus, from there,
if the window that trigger the KillFocus is not in the children list, i move the focus back to the dialog.

Then i do a Show() without blocking with any loop, and return.
And it act like a modal dialog.

regards,