how to make a wxMessageDialog() go away programmatically??

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
gregfjohnson
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Apr 11, 2017 6:28 am

how to make a wxMessageDialog() go away programmatically??

Post by gregfjohnson »

I am using wxWidgets to create a front-end GUI that interacts via wxSockets with a remote TCP server.

I create a wxMessageDialog(), and do a ShowModal() on that object to display it.

So far, so good. As expected, it appears to be running the event loop inside the Modal dialog, and not the main wxWidgets event loop.

Fortunately, I still receive events in the handler I connected to my TCP client socket.

Depending on the TCP message that I receive, I would like to programmatically remove the wxMessageDialog, and not wait for the user to
press a button on the Dialog.

The TCP message handler does a dialog->EndModal(0). However, this seems to do nothing to the dialog. It is still there on the screen,
the rest of the GUI is unresponsive, and debug-print statements after the call to ShowModal() do not print anything.

Any suggestions on how to get a wxMessageDialog() to go away programmatically from inside a socket message handler?

One thing that "worked": After the ShowModal(), I do a dialog->Destroy(). This makes the dialog disappear, and the rest of the GUI becomes
available again. However, I see a sequence of ugly and alarming warning messages in the xterminal window:

(lua:7495): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(lua:7495): GLib-GObject-CRITICAL **: g_signal_handlers_disconnect_matched: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(lua:7495): Gtk-CRITICAL **: IA__gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(lua:7495): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

(I am using the wxLua wrapper for wxWidgets.)

Is it "ok" to do the dialog->Destroy() in this situation, even though the EndModal() did not seem to have any effect?

Thanks VERY MUCH for any guidance or assistance.

Greg Johnson
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how to make a wxMessageDialog() go away programmatically??

Post by doublemax »

I don't know how wxMessageDialog is implemented under GTK, but under Windows, it's just a wrapper around the native control and there is no second wxWidgets event loop running. This makes it difficult to close it from the "outside".

For "real" wxDialogs, this works, just replace wxID_CANCEL with a proper button id for your purpose:

Code: Select all

wxCommandEvent evt(wxEVT_BUTTON, wxID_CANCEL );
evt.SetEventObject( m_dialog );
m_dialog->GetEventHandler()->ProcessEvent( evt );
I tested this with a wxTextEntryDialog that automatically closes after 10 seconds from a timer event in the main event loop.

It should work if you use wxGenericMessageDialog instead of wxMessageDialog. But i don't know if this is available in wxLua.
Use the source, Luke!
Post Reply