I’m trying to add a button to the image series display GUI from ImageView.jl that, when pressed, runs some series of functions. I’ve added the button, but (probably due to some reading comprehension failure) I haven’t managed to hook it up properly: the functions run immediately rather than waiting for the button to be pressed. In the MWE below, the button should remove the annotation point at the center of the image when pressed.
using Images, ImageView, GtkReactive, Gtk.ShortNames
img = Gray.(rand(100,100,10))
guidata = imshow(img, axes=(1,2))
done = button("Done")
push!(guidata["gui"]["vbox"][3], done)
idx = annotate!(guidata, AnnotationPoint(50, 50, shape='.', size=4, color=Gray(1.0)))
showall(guidata["gui"]["window"])
sigdone = map(done) do btn
delete!(guidata, idx)
end
I managed to get it working by looking at the test suite for the button. It seems kludgy: why does a signal fire when the map is created?
using Images, ImageView, GtkReactive, Gtk.ShortNames
img = Gray.(rand(100,100,10))
guidata = imshow(img, axes=(1,2))
done = button("Done")
push!(guidata["gui"]["vbox"][3], done)
idx = annotate!(guidata, AnnotationPoint(50, 50, shape='.', size=4, color=Gray(1.0)))
global btn_counter = 0
sigdone = map(done) do btn
global btn_counter
btn_counter::Int += 1
if btn_counter > 1 # creating the map executes `sigdone` prematurely
# need to wait for the second run: use a global counter
delete!(guidata, idx)
end
end
showall(guidata["gui"]["window"])
because you need a first value to create the signal from… either we make all signals from a map untyped, hack type inference, or call the function when creating the map