Re: Non modal dialog : how?

(When I sent this email yesterday, it could not be delivered to gtkmm-list due to some unavailable server. I try again now.)

Gtk::Widget::show() is asynchronous, i.e. it returns before the widget is fully shown. During sleep() or any other long operation after show(), events in the main event loop are not processed. You can use show_now() instead of show(), but that will only partly solve your problem. The message dialog is fully shown when the call to show_now() returns, but your program's GUI does not respond during sleep() or another long operation. E.g. if one of your windows is covered by another window, and then uncovered, it will not redraw itself immediately.

You can mitigate the problem by running the main loop now and then. I tested with the following code

    for (int i = 0; i < 10; i++)
      // Dispatch all events in the main event queue, if any.
      while (Glib::MainContext::get_default()->iteration(false))

where sleep(1) is meant to simulate your long operation, divided into shorter parts.

This solution is fairly easy to implement, but it's not the best one, and it may have strange side-effects. A program with long-running operations works best, if it contains several threads. Two threads are usually enough. One thread handles the GUI and other user interactions. Another thread, with lower priority, runs the long operations.


2013-05-13 16:53, Yannick Barbeaux skrev:
Thank you for your help.
I have found out where the problem comes from (but no solution yet) : the
point is that I want the modeless dialog to be closed automatically after
running a given operation.
To simulate this behaviour in your code Kjell, I just added a sleep() call
right after the show method (then I delete the dialog after sleeping). In
your function "on_button_modeless_clicked()" :

delete m_MessageDialog_Modeless;
m_MessageDialog_Modeless = 0;

Note that if I do anything else than sleep (any long operation), I have the
same behaviour : the window appears all blank (no widget).

If I just let the sleep line (and do not delete the dialog after), the
dialog appears blank during 4 seconds (sleep time) then the wigets (labels)

My observation is that the dialog does not appear correctly before exiting
the event handler. Correct? Could anyone confirm and explain why?

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]