Fail to execute jl. file

How can I execute this code by clicking on the jl file on windows?

using Gtk

ls = GtkListStore(String, Int, Bool)
push!(ls,("Peter",20,false))
push!(ls,("Paul",30,false))
push!(ls,("Mary",25,true))
insert!(ls, 2, ("Susanne",35,true))

tv = GtkTreeView(GtkTreeModel(ls))

rTxt = GtkCellRendererText()
rTog = GtkCellRendererToggle()

c1 = GtkTreeViewColumn("Name", rTxt, Dict([("text",0)]))
c2 = GtkTreeViewColumn("Age", rTxt, Dict([("text",1)]))
c3 = GtkTreeViewColumn("Female", rTog, Dict([("active",2)]))

push!(tv, c1, c2, c3)

for (i,c) in enumerate([c1,c2,c3])
    GAccessor.sort_column_id(c,i-1)
end

selection = GAccessor.selection(tv)

# selection = GAccessor.mode(selection,Gtk.GConstants.GtkSelectionMode.MULTIPLE)

signal_connect(selection, "changed") do widget
    if hasselection(selection)        
        currentIt = selected(selection)  
        # now you can to something with the selected item     
        if ls[currentIt,3]
            ls[currentIt,3] = false
        else
            ls[currentIt,3] = true
        end
    end
end



win = GtkWindow(tv, "List View")
showall(win)

I am not sure if it is possible.
What you could do is generating a batch file and run that one with double clicking.

run.bat:

julia yourfile.jl

I tried, but the GUI didn’t start

I don’t know Gtk that well, but it seems that showall is not blocking. So if you start it with the batch file it will immediately close again. I could retain the GUI for a few seconds if I put sleep(10) at the end of the file. There is a better solution using signals in this stack overflow post.

https://stackoverflow.com/questions/52589873/gtk-jl-julia-bindings-for-gtk-gtk-window-is-not-displayed-outside-the-repl

1 Like

I’m ashamed. The solution was in the GTK.jl documentation.

Solution!

Thanks feanor12

1 Like