Reputation: 14379
I would like to show a Gtk.Dialog
defined in a Glade file multiple times.
Currently I am able to do it using a custom button to call the hide()
method of the Dialog but, if the user uses Alt+F4 to close the dialog, it re-opens empty:
And in console I see multiple errors:
(main.py:29152): Gtk-CRITICAL **: 15:28:29.637: gtk_container_foreach: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_button_box_get_layout: assertion 'GTK_IS_BUTTON_BOX (widget)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_button_box_get_layout: assertion 'GTK_IS_BUTTON_BOX (widget)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_button_box_get_layout: assertion 'GTK_IS_BUTTON_BOX (widget)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
I am getting the instance of the Dialog with a normal get_object()
:
self.__settings_dialog : Gtk.Dialog = self.__builder.get_object("settings_dialog")
and than just calling show()
and hide()
. But after closing it with Alt+F4 I am not able to show it again.
Upvotes: 1
Views: 463
Reputation: 14379
Thanks to a Reddit user, I find out that you have to connect to the dialog's delete-event
and make sure to return True
to avoid the dialog being destroyed.
First create the signal handler in Glade, then in your Python code:
def on_dialog_delete_event(self, dialog, event):
dialog.hide()
return True
Upvotes: 1