I need help with Gtk.jl for the following basic problem.
I am trying to get input from the REPL in a closed loop program and update a Gtk window that keeps track of all items generated during program execution.
See the MWE example below. Each input string and integer items are added to a Gtk window list, which is redrawn each time to reflect the new data. The problem is that displaying the Gtk window steals the cursor focus from the REPL.
How can this be solved?
Thanks in advance.
Gtk.jl MWE code
using Gtk
@kwdef mutable struct Item
name::String = ""
size::Int = 0
end
function gtk_list(data::Vector{Item})
global win
visible(win, false)
ts = GtkTreeStore(String, String, String)
tv = GtkTreeView(GtkTreeModel(ts))
sw = GtkScrolledWindow(tv)
rTxt = GtkCellRendererText()
c0 = GtkTreeViewColumn("#", rTxt, Dict([("text", 0)]))
c1 = GtkTreeViewColumn("Name", rTxt, Dict([("text", 1)]))
c2 = GtkTreeViewColumn("Size", rTxt, Dict([("text", 2)]))
cols = [c0, c1, c2]
push!(tv, cols...)
iter1 = push!(ts, ("", "MY ITEMS", "",))
for (n,d) in pairs(data)
push!(ts, (string(n), d.name, string(d.size)), iter1)
end
win = GtkWindow(sw, "MyData")
Gtk.showall(win)
Gtk.G_.position(win, 200, 200)
set_gtk_property!(win, :width_request, 700)
visible(win, true)
return nothing
end
function input_data!(data::Vector{Item})
s = "n"
while s ā ("y", "Y")
println("New item name:")
name = readline()
println("New item size (Int):")
sz = tryparse(Int, readline())
isnothing(sz) && (sz = -999)
push!(data, Item(name, sz))
gtk_list(data)
println("[ENTER]:continue, (Y):stop")
s = readline()
end
return nothing
end
function start_code()
@eval win = GtkWindow("MyData", visible=false)
data = Item[]
input_data!(data)
destroy(win)
return nothing
end
# Copy and paste the above code into the Julia REPL (not the VSCode REPL)
# ... and then call the function:
start_code()