ImageView/Gtk Unstable Results

I’m working on some code using ImageView to show an image in a Gtk window and grab the (x,y) coordinate where the user clicks within the window. I based it on the Calling imshow from a script file section of the ImageView.jl github page.

When the code is run in a clean notebook, it is sometimes slow to execute, then fails to capture the values from gui["canvas"].mouse.buttonpress. Other times, it works fine on the first go-round in a clean notebook.
I’ve tested this on PC and Mac and its having the same issue on both, but seems more unstable on the Mac. Using Julia 1.0.1

Any thoughts on how to improve this to get more consistent behavior would be appreciated.

Here is a MWE:

using Images, GtkReactive, ImageView, Gtk.ShortNames

function SelectPts(A::Array) 
    guidict = imshow(A)
    # Create a condition object
    c = Condition()

    # Get the window
    win = guidict["gui"]["window"]
    gui = guidict["gui"]
    temp_x1 = 0
    temp_y1 = 0

map(gui["canvas"].mouse.buttonpress) do btn
        temp_x1 = Float64(value(btn.position).x)
        temp_y1 = Float64(value(btn.position).y)

        println("Init_X: ",temp_x1,"    Init_Y: ",temp_y1)

    # Notify the condition object when the window closes
    signal_connect(win, :destroy) do widget

    # Wait for the notification before proceeding ...
    return temp_x1, temp_y1

A = Gray.(rand(100,100))
x,y = SelectPts(A)

Try adding preserve around that map call, i.e., preserve(map(gui["canvas"]...)). Your new signal may be getting garbage collected, at which point it stops working.