Michal S. wrote in post #1019345:
The callback selection_changed is set on treeview-selection1 with user
data treeview-selection2 and when triggered on treeview-selection1
treeview-selection2.selection_changed treeview_selection1 is called.
Indeed. I tested this, see attachment, and this is really bad.
Basically, ruby Gtk::Builder sends a message to the “user data” object,
with the name of the callback, passing expected arguments for the
signal. And it does so even if you do not connect_signals. Just comment
out ‘method(handler)’ line 20 to be sure.
Just add puts “Adding callback #{name}” to the builder.connect_signal,
and you will see it is called only once for each selection.
It is called twice with selection_changed.
And it should be called 4 times. It’s only called for the one without
“user data”.
When I comment out the two with user data it is also called twice but
the demo does not work then so the signals with user data are not
connected in the block but are still connected.
That’s because of the buggy behaviour of gtk::builder I outline above.
You might think it is backward because, when you change something in
ts1, if it changes something in ts2, the ts2 ‘selection_changed’ is then
called, and it is called before you finish what you were doing in ts1.
At least, that’s the only way I can think of.
No, when I have Item 4 selected in one view and select item 4 in the
other I get:
sel “Item 4” “Item 4”
sel “Item 4” nil
sav “Item 4” nil
sav “Item 5” “Item 4”
So the other callback fires before the first finishes due to the
unselect call - the method producing the sav output is called from the
callback.
There is no problem with that, though. The sel output is produced at
the very start of the callback and is in order.
After more thorough testing, it calls 3 callbacks.
The first two are the backward callback, which I would call buggy,
and should not exist.
The third one is the expected callback, which just sets the title, and
nothing else.
The main problem, afaik, is that ruby gtk::builder does not handle “user
data”. I took a look at rbgtkbuilder.c, but I’m really too bad at C to
understand what is going on.
Obviously it does.
I still think it does not. It just has a buggy behaviour which makes it
work somewhat, but is not what I expect.
for example, if I have :
I want to write somewhere in my code :
def my_callback(button, user_data)
and not :
my_entry = builder[‘y_entry’]
def my_entry.my_callback(button)
or even worse, reopening Gtk::Entry, like you do on TreeSelection :
class Gtk::Entry
def my_callback(button)
I think it should be fixed. And signals should handle “user data”, and
passing them as the last argument of the signal, if they are present.
Simon