Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save_dialog and open_dialog breaks when called by buttons #44

Closed
ChantalJuntao opened this issue Nov 7, 2023 · 2 comments
Closed

save_dialog and open_dialog breaks when called by buttons #44

ChantalJuntao opened this issue Nov 7, 2023 · 2 comments

Comments

@ChantalJuntao
Copy link

While save_dialog() and open_dialog work fine when called from the command line, they break when called by a button.

using GtkObservables, Gtk4

c = canvas(UserUnit)
win = GtkWindow(c)

function saveme(window)
    @show "saving"
    name = save_dialog("Choose file", window)
    @show name
end

savebutton = button("save"; widget=nothing, observable=nothing)
sbox = GtkBox(:v)
push!(sbox, savebutton)
push!(win, sbox) #this is a stupid location to put this button
GtkObservables.gc_preserve(win, savebutton)
savesignal = on(savebutton) do _
    @show "click"
    saveme(win);
end

After clicking:

julia> "click" = "click"
"saving" = "saving"


<julia freezes and crashes>
@jwahlstrand
Copy link
Member

When you use the dialog functions in a callback you have to use the method that takes a function callback (or the do syntax). This should probably be more prominent in the documentation:

https://juliagtk.github.io/Gtk4.jl/dev/manual/dialogs/#File-Dialogs

I'll make them clearer.

The following works for me:

using GtkObservables, Gtk4

c = canvas(UserUnit)
win = GtkWindow(c)

function saveme(window)
    @show "saving"
    save_dialog("Choose file", window) do name
        @show name
    end
end

savebutton = button("save"; widget=nothing, observable=nothing)
sbox = GtkBox(:v)
push!(sbox, savebutton)
push!(win, sbox) #this is a stupid location to put this button
GtkObservables.gc_preserve(win, savebutton)
savesignal = on(savebutton) do _
    @show "click"
    saveme(win);
end

@jwahlstrand
Copy link
Member

Added a couple of notes to the dialogs docs: https://juliagtk.github.io/Gtk4.jl/dev/manual/dialogs/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants