Open_dialog with a transient parent

How exactly do I use Gtk.open_dialog from Gtk with a parent, and avoid this:

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

Any MWE would be great, thanks!

How do you user open_dialog right now?

has a paragraph about
gtk_window_set_transient_for ()
and i’d guess this should be used to give a modal window like the dialog a parent.

Thanks for the tip, but I’m still not sure how I can specify that there is no parent window. What I do now is:

txtfile = open_dialog("Pick a `.txt` file", Null(), ("*.txt",))

and open_dialog is from where?

OMG, sorry: Gtk.

https://github.com/JuliaGraphics/Gtk.jl/blob/5d12682c9ffa75f7ff5e24d352643e61d9ce10ba/docs/src/manual/filedialogs.md says the second argument is the parent container.

Yea, but if I use their example, I still get that warning:

julia> using Gtk

julia> open_dialog("title", GtkNullContainer(), String[])
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

Maybe there is no way to circumvent that warning?

The warning is there, because a Null container is somehow a non-window and therefore the parent is missing. Digging a little bit deeper: the warning shows up to inform you, that with a setup like this your window manager might not be able to manage the dialog window which can have strange side effects like sticking on your screen (happens a lot with tool tips from Gtk on windows).

I see. So it’s there to stick, unless I give it a real parent. But is there a clean simple way to do that? Like what would be the correct way to use open_dialog if that is the only need we have to communication with the user?

Afair (i haven’t done gtk application development for some time), a well behaving gtk GUI application should have an top-level application window to which you add menu, dialogs etc. If you only call open_dialog to ask for input and your application is terminal only, i’d guess you can live with the warning.

yes, this is the way I do this as well. The advantage when passing the top-level window is that one can set the dialog to be modal.

It makes sense. I guess one way “around it” is to open a transparent window as a default parent and kill it with the dialog.

I‘ve got a similar (same) problem when I carry out the following steps:
Step 1
Loading the main program. Opening the main GtkWindow.

Step 2
Try to open a file via a button (→ load a file) which opens the dialog box:
as a result: the loading action sticks with a message:

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

Step 3
Now loading the file from console without closing the GtkWindow:

julia> file = open_dialog(“Pick a file”, Null(), (“*.jld2”,))
Gtk-Message: 14:43:52.239: GtkDialog mapped without a transient parent. This is discouraged.
“D:\WORK\ResultsNew\233=010.jld2”
julia> load_para1(file)
load_profilemodel_type(): >>>>>>>>>>>>> 233=010
load_para1(file): >>>>>>>>>>>>>>>>>>> done
julia>

All parameter loaded!

Step 4
Set the focus on the main GtkWindow. Repeat the loading process via button and the open_dialog box. Now, all data are loaded without a message:

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

What‘s wrong? Is there a workaround to get rid of the Gtk-WARNING message?

Same behavior if I apply:

file = open_dialog("Choose a file", GtkNullContainer(), ("*.jld2, *.jl",), select_multiple=false)

(btw. What the difference between Null() vs GtkNullContainer() ?)

you should pass the GtkWindow from your main program as the second argument to the open_dialog. Then you won’t get the warning.

:clap:

# Test of Julia-Gtk messaging
using Gtk
win = GtkWindow("Test")
res = ask_dialog("Hello", win, "OK", "No") && println("Done.")
# This gives the fatal error
#=(<unknown>:2724): Gtk-CRITICAL **: 20:46:30.936: gtk_message_dialog_new: assertion 'parent == NULL || GTK_IS_WINDOW (parent)' failed
ERROR: LoadError: Cannot construct GtkMessageDialogLeaf with a NULL pointer
=#
res = ask_dialog("Hello", "OK", "No") && println("Done.")
# This works but gives the warning
# Gtk-Message: 20:47:24.154: GtkDialog mapped without a transient parent. This is discouraged.

How should the first one be modified to work?