Gtk.jl
Gtk.jl copied to clipboard
setindex notation for replacing elements
It would be nice to be able to write
builder["button"] = GtkButton("The new button")
I'm not very familiar with GtkBuilder, is that something that is supported ? I only had a quick look but didn't found much :
https://developer.gnome.org/gtk3/stable/GtkBuilder.html
well you can do it manually, I did something like
builder = GtkBuilder(file)
button_parent = builder["parentID"]
destroy(button_parent[1]) # or other index of button
push!(button_parent, GtkButton("The new button")
what is builder["parentID"]
? A container? In particular it would be interesting what button_parent[1]
actually is.
In my case builder["parentID"]
is a GtkScrolledWindow
, but in principle could be any container and button_parent[1]
would be the GtkButton
that I want to replace.
button_parent[1]
would be the same as builder["button"]
, but one could also loop through the container and check the ids for "button"
if the element doesn't know its index in the parent container.
As I understand you're modifying the container here (the GtkScrolledWindow) and not the builder itself. Essentially you're doing :
x = [zeros(2)]
x[1][1] = 1
Which is different from x[1] = 1
.
From the GtkBuilder doc it seems to me it's meant to an immutable object and you'd rather have to modify the input file than the object.
That said it could make sense to define setindex
for array-like containers (e.g. GtkNotebook).
That said it could make sense to define setindex for array-like containers (e.g. GtkNotebook). I think that would also make sense.
Then one could write builder["parentID"][1] = GtkButton()
, though kind of my point was, that finding out who is the parent, could be done automatically and make things a great deal easier, since builder["ID"] = element
would mean: delete the element known by this name and replace it with this new element under the same name.