GtkDialog mapped without a transient parent
Asked Answered
S

2

48

I have a GUI built in Glade (3.18) which is called by a Python 3 program (using PyGObject). I get a lot of warnings when running the program (Fedora 21) that say:

Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

How can I fix this warning? I tried filling in the field Transient for: main_window in Glade for all the dialog windows, but the warnings still appear.

Swashbuckler answered 26/4, 2015 at 20:36 Comment(1)
This is exactly the warning I end up with when running this example from the official gtkmm documentation: developer.gnome.org/gtkmm-tutorial/stable/…Magavern
B
26

You fix this warning by giving the GtkDialog a parent to be modal to. The relevant functions are gtk_window_set_transient_for() (which sets this window to always be on top of, or transient for, another one) and optionally gtk_window_set_modal() to make it a modal dialog. This is ultimately what the various GtkDialog constructors do.

Butylene answered 26/4, 2015 at 21:9 Comment(12)
Does that mean I need to pass the main_window instance to each dialog class? If I instead use self.builder.add_objects_from_file(..."main_window") in the dialog, then I get errors, because the main_window signals are not connected (which is of course correct, because the dialog has different signals than the main window). The setting in Glade might fail because of similar reasons. The transient option is set, but on runtime, the dialog has no access to the main_window instance.Swashbuckler
Is there any reason you can't call set_transient_for() when you show your dialog? That's what the "mapped" part meansButylene
I probably made a silly mistake, but inserting any of those variants in the below the linked line does not help with the error message: github.com/tobias47n9e/innstereo/blob/master/innstereo/…Swashbuckler
And what object is the main window? Alternatively, could you pass it to your run() method?Butylene
I just made another try, and indeed it works if I pass the main_window object (the GtkWindow) to each dialog and then use self.dialog.set_transient_for(main_window) (I used the __init__ function for that). Thanks again for your help!Swashbuckler
My application is only dialogs, there is no "main window". What am I supposed to pass to this function?Essen
Then you will have to pass NULL and deal with the warnings. I suppose you could try making a new window and not showing it, but I'm not sure if that will work. This problem is definitely one people are thinking about, though.Butylene
Your "answer" use C-code but the question here is about the Python binding PyGObject.Limpid
@Essen I would recommend to always have a main window. I also created an application, whose main window is more like a dialog, but I buildt it on a default GtkWindow.Transudate
@Swashbuckler I believe you can silence this warning by using the result of your dialog's get_toplevel() method (inherited from Gtk.Widget) as the parent/transient window.Sthenic
@Butylene in the context of a script creating a new terminal windows with commands, do you just do gtk_window_set_modal(); xterm -e 'echo "hi"'; or gtk_window_set_modal(xterm -e 'echo "hi"'); ?Intuitivism
gtk_window_set_modal() is not a shell command; you will have to modify the code that uses GTK+.Butylene
B
0

Use a GtkWindow instead; and use a GtkDialog only when there is a parent window/dialog.

Bouffant answered 14/5, 2018 at 16:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.