Seek advice on displaying clickable N by N images

I would like to build an N by N squares laid out in a grid form.
Each square has a background color and an image at the center.
No distance between two squares.
If one of the images is clicked, an event signal is emitted and processed
(for example to change the image being clicked).

Initially, I thought of using N by N Gtk buttons. But I still have trouble with finding
the most recent coding examples.

I am wondering if there is a ‘high level’ package which can help set up such
a form.

Thanks
HP

If you don’t need focus (highlighted area which you can click on) and don’t need click-action (change of rendering when mouse button is pressed), the simplest way is to put the images on a Canvas and pack it into an EventBox, so you’re program gets ‘raw’ events. Then just use the coordinates of ‘click-event’ and match it back to your selection.

Thank you for the suggestion. I agree that the ‘simplest’ way is DIY.
I cooked up below code to get started. It displayed a window on screen. The top left
canvas is supposed to be painted with light gray color. THE REPL prints out “canvas name= 1” as expected. (Later, each canvas’ drawing will depend on the name.)
BUT no drawing occurred in this case. I must have missed something ?

Btw, do you know of any example usage of EventBox that you suggested ?

Thanks, HP


using Gtk

function mydraw(widget)
ctx = Gtk.getgc(widget)
println("canvas name= ", get_gtk_property(widget, :name, AbstractString))
# background color
set_source_rgb(ctx,0.8,0.8,0.8); # light gray
rectangle(ctx,0.0,0.0,100.0,100.0); # background
fill(ctx)
end

win = GtkWindow(“A new window”, 200, 200)
g = GtkGrid()

a = GtkCanvas()
set_gtk_property!(a, :name, “1”)
a.draw = mydraw

b = GtkCanvas()
set_gtk_property!(b, :name, “2”)
c = GtkCanvas()
set_gtk_property!(c, :name, “3”)
d = GtkCanvas()
set_gtk_property!(d, :name, “4”)

g[1,1] = a
g[2,1] = b
g[1,2] = c
g[2,2] = d

set_gtk_property!(g, :column_homogeneous, true)
set_gtk_property!(g, :column_spacing, 0)
set_gtk_property!(g, :row_spacing, 0)
push!(win, g)

draw(a)
showall(win)

I found the problem. I need to specify the size!
a = GtkCanvas(100,100)

And I use this scheme to get the result of mouse click:
callback(w,evt) = println("name= ", get_gtk_property(w, :name, AbstractString))

and then I assign
signal_connect(callback, a, “button-press-event”)
for all 4 canvas (a, b,c,d) in this case.

The callback indicates the canvas’ name to identify which canvas needs to be
worked on. So, proof of concept…


As far as you can see, when the number of canvas reaches 64 (a chess board),
will this scheme cause any issue ?
[ I can see that there will be a LOT of typing to do if I do not use macro to help. ].
Can Julia. handle large amount of signal_connect ? I have no idea if 64 is considered
tiny or …

thanks
HP