Problem with GUI ask_dialog

Julia is freezing when I use ask_dialog() in julia file. I added extra code as suggested to let it work, however, the problem is still existing. Any solution?

using Gtk
win = GtkWindow("gtkwait")
if !isinteractive()
    @async Gtk.gtk_main()
    Gtk.waitforsignal(win,:destroy)
  end
  state = ask_dialog("Like or Not?", "No", "Yes")

Any solution?

Try ensuring it runs in the UI thread by putting it in an Gtk.@idle_add begin ... end block.

Also, I think the Gtk.waitforsignal call is only intended for the end of a script?

I think you can ignore @idle_add for now, it looks like, based on the documentation, you need to put the ask_dialog first, and then at the end of the script, do the if !isinteractive block.

Ah, I see the issue. Sorry, just trying it out myself.

It’s not that it gets frozen per se, it’s that the dialog button press isn’t registering somehow, so the dialog never closes and allows the program to continue.

1 Like

Might be related to this issue: Hangs when calling open_dialog()/open_dialog_native() non-interactively · Issue #576 · JuliaGraphics/Gtk.jl · GitHub

1 Like

Thank you!

Unfortunately, I did not find a solution at this link.

Right, it may need people to look more deeply into what’s going on. I might be able to poke around but I’m not the most familiar with the code base.

1 Like

@JeffFessler JeffFessler
Can you support please?

Oh no… this is a Heisenbug. If you stick printlns in the function, it starts working :laughing:

Sorry, I mean in the Gtk.jl function itself. But, you can call the internal functions directly and it seems to work:

    dlg = GtkMessageDialog(message, ((no_text, 0), (yes_text, 1)),
            Gtk.GtkDialogFlags.DESTROY_WITH_PARENT, Gtk.GtkMessageType.QUESTION, Gtk.GtkNullContainer())
    println("I'm necessary for some reason")
    response = run(dlg)
    destroy(dlg)
    status = response == 1
1 Like

See my edited post

1 Like

Many thanks for your help. It works!

1 Like

A better solution was posted in the GitHub issue you could try.

1 Like

Thank you, I will have a look

for the records: Here is what you want if you are using Gtk in an interactive/still scripted manner:

using Gtk
  
if !isinteractive()
    @async Gtk.gtk_main()
end

t = @async begin
  state = ask_dialog("Find Steady-state solution and start rom steady-state?", "No", "Yes")
end

if !isinteractive()
    wait(t)
end
2 Likes