47

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.

tobias47n9e
  • 2,233
  • 3
  • 28
  • 54
  • This is exactly the warning I end up with when running this example from the official gtkmm documentation: https://developer.gnome.org/gtkmm-tutorial/stable/sec-builder-accessing-widgets.html.en – Evgeny Bobkin May 23 '18 at 12:06

2 Answers2

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.

andlabs
  • 11,290
  • 1
  • 31
  • 52
  • 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. – tobias47n9e Apr 27 '15 at 06:34
  • 1
    Is there any reason you can't call `set_transient_for()` when you show your dialog? That's what the "mapped" part means – andlabs Apr 27 '15 at 13:41
  • 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: https://github.com/tobias47n9e/innstereo/blob/master/innstereo/layer_properties.py#L47 – tobias47n9e Apr 27 '15 at 16:14
  • And what object is the main window? Alternatively, could you pass it to your `run()` method? – andlabs Apr 30 '15 at 15:54
  • 1
    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! – tobias47n9e Apr 30 '15 at 22:22
  • 10
    My application is only dialogs, there is no "main window". What am I supposed to pass to this function? – Rich May 28 '16 at 19:40
  • 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. – andlabs May 28 '16 at 20:33
  • Your "answer" use C-code but the question here is about the Python binding PyGObject. – buhtz Aug 11 '18 at 19:50
  • @Rich 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. – Bachsau Nov 08 '18 at 22:32
  • @tobias47n9e 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. – ʇsәɹoɈ Feb 23 '19 at 03:05
  • @andlabs 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"');` ? – tatsu Apr 15 '19 at 16:07
  • `gtk_window_set_modal()` is not a shell command; you will have to modify the code that uses GTK+. – andlabs Apr 16 '19 at 17:59
0

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

kenchoy
  • 9
  • 1
  • 1
  • 3