Another good insight of GtkTreeView behavior ... Thank you Mr Doug Quale.
I'll try them out.
regards, mige
Doug Quale wrote:
This is something that surprises many people when they first see it. GTK+ emits a selection "changed" signal for the initial default selection of the first row in the treeview. I think this happens when the treeview widget is mapped.
This behavior is consistent since the selection has changed from no selection to the first row selected, but often we don't want the callback activated for the default selection since no user input has occurred.
I know of 3 approaches to handle the initial "changed" signal when it is unwanted. I'll save my favorite for last.
1. Write your "changed" signal callback to ignore the first signal it receives by testing and setting a flag variable. This is simple and obvious and I would guess it's the most popular method.
2. Delay connecting to the "changed" signal until after the treeview is mapped. If you try something like this:
win.add(treeview) win.show_all()
# The treeview is already mapped, so by connecting here we don't # get the initial "changed" signal. selection = treeview.get_selection() selection.connect('changed', on_selection_changed)
This can work but the code ordering requirement is awkward and hard to document. I don't recommend it. (You can avoid the code ordering requirement by putting the connection code into a gtk.idle() callback. I think that's even worse.)
3. Fake GTK+ out by preemptively setting the selection yourself just before you connect to the "changed" signal.
# Select the default row before we connect to the "changed" signal. # GTK+ will emit a "changed" signal now before we are connected. # When the treeview is mapped the selection won't change so GTK+ # won't emit another unwanted "changed" signal. selection = treeview.get_selection() selection.select_path(0) selection.connect('changed', on_selection_changed)
This is nice because the all the selection setup occurs together in one spot.
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
