Gtk.jl icon indicating copy to clipboard operation
Gtk.jl copied to clipboard

What's the preferred design pattern for opening modal windows with callbacks?

Open Boxylmer opened this issue 3 years ago • 0 comments

I have a window that can be opened in multiple places to edit parameter values in an experiment struct. I want to set callbacks to "confirm" and "cancel" to do validation or nothing respectively. What happens to these callbacks when the window is destroyed? What about when it reopens? I don't know if I need to do cleanup / destroy the callbacks after the function is over.

function open_experiment_parameter_panel(parent=Gtk.GtkNullContainer(), experiment=nothing)
    gladefile = GtkBuilder(filename=joinpath(@__DIR__, "experiment_parameters_panel.glade"))
    win = gladefile["window_parameter"]
    showall(win)

    btn_confirm = gladefile["btn_confirm"]
    btn_cancel = gladefile["btn_cancel"]

    temperature_val = gladefile["temperature_val"]
    temperature_err = gladefile["temperature_err"]
    # ... quite a bit of this
    alum_mesh_dens_err = gladefile["alum_mesh_dens_err"]

    if !isnothing(experiment)
        # we fill out the above entries with these values, this isn't relevant to the example though. 
    end

    cancel_id = signal_connect(btn_cancel, "clicked") do 
        # close the window
        # what do I do with these callback signals?
        # possibly nothing? https://github.com/JuliaGraphics/Gtk.jl/issues/503
    end
    confirm_id = signal_connect(btn_confirm, "clicked") do 
        # try
            # gather all the cleaned input
            # i.e., parse(filter_number_string(get_entry_text(entry)))
            # from the parsed values, construct the correct input
            # modify the exp setup file using the relevant setter funcs
        # catch
            # dialog_warn and don't do anything else.
    end
    return confirm_id, cancel_id  # maybe I can kill these later with signal_disconnect? 
    # OR maybe I can create a while loop in here and disconnect them after?
    # I don't know what's required here to avoid a bunch of useless callbacks if I keep opening and closing this.
end

Boxylmer avatar Jul 19 '22 20:07 Boxylmer