Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tablelist bug?

22 views
Skip to first unread message

DrS

unread,
Jan 30, 2012, 9:22:06 AM1/30/12
to
I am not sure if I am missing something or if this could be a bug. I
thought tablelist was a drop-in replacement for the built-in listbox but
I am seeing some differences.

This is the scenario: tablelist has a single column, select mode is
extended and the user has selected multiple items. Now, when the user
clicks on one of the selected items, I would like to get all of them so
I can take action on them as a group. With the built-in listbox, this
is the behavior. With tablelist, I am only getting the one that is last
clicked. Is there a way to do this?


DrS

nemethi

unread,
Jan 30, 2012, 6:06:28 PM1/30/12
to
What do you mean by getting all of them? If the -selectmode option was
set to "extended" and you click on one of the selected items then that
item will remain selected and all the others will lose the selection.
This is exactly the same behavior as the one exhibited by the Tk core
listbox.

--
Csaba Nemethi http://www.nemethi.de mailto:csaba....@t-online.de

DrS

unread,
Jan 30, 2012, 6:33:30 PM1/30/12
to
On 1/30/2012 6:06 PM, nemethi wrote:
> What do you mean by getting all of them? If the -selectmode option was
> set to "extended" and you click on one of the selected items then that
> item will remain selected and all the others will lose the selection.
> This is exactly the same behavior as the one exhibited by the Tk core
> listbox.
>

I mean that the selection that exists right before/at the moment of the
current mouse click. I am listing a couple of demo scripts:

1) Normal listbox example: Make a selection, with shift/control buttons,
then click on the listbox. Before the new click "registers", the
listbox still returns the "previous" selection.

package req Tk
listbox .l -selectmode extended
pack .l -expand 1 -fill both
bind .l <Button-1> [list print_selection %W]
.l insert end 1
.l insert end 2
.l insert end 3
.l insert end 4
proc print_selection {w} {puts "SELECTION: [$w curselection]"}

SELECTION:
SELECTION: 1
SELECTION: 1 2
SELECTION: 2
SELECTION: 2 3
SELECTION: 0 2 3



2) Tablelist example: With tablelist, the selected items at the moment
of the new mouse click is never accessible. It only returns a single
(newly selected) item.


package req Tk
package req tablelist

tablelist::tablelist .l -columntitles {test} -selectmode extended
pack .l -expand 1 -fill both
bind TablelistBody <Button-1> +[list print_selection %W]
.l insert end 1
.l insert end 2
.l insert end 3
.l insert end 4

proc print_selection {w} {
puts "SELECTION: [$::tablelist::W curselection]"
}

SELECTION: 1
SELECTION: 0
SELECTION: 2
SELECTION: 3
SELECTION: 0
SELECTION: 2
SELECTION: 0
SELECTION: 3

nemethi

unread,
Jan 31, 2012, 3:36:30 PM1/31/12
to
The bug is not in Tablelist, but in the way you are using the binding tags.

In your listbox example you bind a script to the widget name, which
precedes the widget class binding tag "Listbox". Consequently, the
print_selection procedure will be invoked before the default bindings
for "Listbox" unselect all elements, except the last clicked one. Due
to this fact, the curselection listbox subcommand will return the
expected index list.

On the other hand, in your tablelist example you bind a script to the
binding tag "TablelistBody", which is used by the Tablelist
implementation in the default mouse and keyboard bindings for the
tablelist body, embedded images, and other auxiliary objects that have
this name in the list of their binding tags. In addition, due to the
"+" character starting your script, the print_selection procedure will
be invoked after the default binding script for this tag, which belongs
to the private part of the Tablelist implementation. Consequently, by
the time this procedure is called, all items except the last clicked one
will already be in unselected state, and thus the curselection tablelist
subcommand will return a list of length 1.

To make your 2nd script work like the 1st one, you have to replace the
binding tag "TablelistBody" with [.l bodypath] or [.l bodytag] (the
latter is the recommended choice). Here is the corrected version of the
script:

package req Tk
package req tablelist

tablelist::tablelist .l -columntitles {test} -selectmode extended
pack .l -expand 1 -fill both
bind [.l bodytag] <Button-1> [list print_selection %W]
.l insert end 1
.l insert end 2
.l insert end 3
.l insert end 4

proc print_selection {w} {
set tbl [tablelist::getTablelistPath $w]
puts "SELECTION: [$tbl curselection]"
}

In this example, the argument passed to the print_selection procedure
will be the body component of the tablelist widget whose name is
returned by the tablelist::getTablelistPath procedure.

DrS

unread,
Feb 1, 2012, 2:17:45 PM2/1/12
to
On 1/31/2012 3:36 PM, nemethi wrote:
> To make your 2nd script work like the 1st one, you have to replace the
> binding tag "TablelistBody" with [.l bodypath] or [.l bodytag] (the
> latter is the recommended choice). Here is the corrected version of the
> script:
>

That was great! Thanks!


DrS


0 new messages