From: Batox on
Short form:
It seems to me that the active element of a tablelist changes only
after the event TablelistSelect has fired. Is there an event which
fires *after* the active element has changed?

Long form:
When I run the following script, it displays a tablelist with two
rows. When I click on the second row, the messagebox pops up and
displays the first element of the first row (which is not active at
that time). When I click again on the second row, it properly shows
the first element of the second row. When I do a third click on the
first row, it again shows the first element of the second row, a
second click again shows the proper element, and so on.

package require Tk
package require tablelist

namespace import ::tablelist::*

proc ShowSelected {tl} {

tk_messageBox -message [$tl getcells active,0]
}

tablelist .tl -columns {0 Head1 0 Head2}
..tl insert end {{Ahuga} {Haga}}
..tl insert end {{Foo} {Bar}}
bind .tl <<TablelistSelect>> "ShowSelected .tl"

pack .tl
From: Csaba Nemethi on
Am 16.07.2010 09:58, schrieb Batox:
> Short form:
> It seems to me that the active element of a tablelist changes only
> after the event TablelistSelect has fired. Is there an event which
> fires *after* the active element has changed?
>
> Long form:
> When I run the following script, it displays a tablelist with two
> rows. When I click on the second row, the messagebox pops up and
> displays the first element of the first row (which is not active at
> that time). When I click again on the second row, it properly shows
> the first element of the second row. When I do a third click on the
> first row, it again shows the first element of the second row, a
> second click again shows the proper element, and so on.
>
> package require Tk
> package require tablelist
>
> namespace import ::tablelist::*
>
> proc ShowSelected {tl} {
>
> tk_messageBox -message [$tl getcells active,0]
> }
>
> tablelist .tl -columns {0 Head1 0 Head2}
> .tl insert end {{Ahuga} {Haga}}
> .tl insert end {{Foo} {Bar}}
> bind .tl <<TablelistSelect>> "ShowSelected .tl"
>
> pack .tl

You are not right! Please run the following script, derived from yours,
in which I basically just replaced the tablelist widget with a Tk core
listbox (and, of course, the <<TablelistSelect>> event with
<<ListboxSelect>>:


package require Tk

proc ShowSelected {lb} {

tk_messageBox -message [$lb get active]
}

listbox .lb
..lb insert end Ahuga
..lb insert end Foo
bind .lb <<ListboxSelect>> "ShowSelected .lb"

pack .lb


You will see that this script behaves *exactly* like yours. By design,
tablelist widgets are highly compatible with Tk core listboxes. A more
thorough study of the listbox manual page (which includes a detailed
description of the bindings and which is also explicitly referred to in
the Tablelist documentation) will surely help you understand the
(identical) behavior of the two scripts.

To your question: There is no event that fires after the active element
has changed. But you can use my Wcb package, which allows you to define
a callback that fires after the active row or cell has changed.

--
Csaba Nemethi http://www.nemethi.de mailto:csaba.nemethi(a)t-online.de

From: Batox on
BTW I never claimed that tablelist would behave differently from
listbox, but I guess you've heard my question combined with that claim
so many times ...

At first I didn't want to use Wcb because it's one more package I have
to maintain, but after some fiddling around I decided it's worth the
hassle. Thanks a lot and keep up the good work :)