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

Major bug in tablelist?

4 views
Skip to first unread message

DrS

unread,
Feb 3, 2012, 11:52:55 AM2/3/12
to
It seems that there is a bug when returning values with spaces in them
stored in a tablelist widget. This is significant as it is impossible
to get the same data back that you put in it. Please see below for an
example.


## setup
package req tablelist
toplevel .t
tablelist::tablelist .t.tab -columntitles {Test}
pack .t.tab -fill both -expand 1


## inserting data with spaces
% .t.tab insert end "Hello there" ## this shows as a single "hello"
% .t.tab insert end {Hello there} ## same thing
% .t.tab insert end {{Hello there}} ## ok; it requires a list of values


## getting data inserted above
% .t.tab get 0 ## this is ok; given only hello was accepted
Hello
% .t.tab get 1 ## same as above
Hello
% .t.tab get 2 ## odd!! this looks like a list with one element
{Hello there}
% .t.tab get 0 end ## yes; 3rd item is definitely a sub-list in a list
Hello Hello {{Hello there}}


The correct result should have been:
Hello Hello {Hello there}







DrS

unread,
Feb 3, 2012, 12:11:59 PM2/3/12
to
On 2/3/2012 11:52 AM, DrS wrote:
> It seems that there is a bug when returning values with spaces in them
> stored in a tablelist widget. This is significant as it is impossible to
> get the same data back that you put in it. Please see below for an example.
>

Well, perhaps I assumed that since it had a single column, it would
behave just like the built-in listbox. I guess the behavior makes sense
if you assume each returned element is a list. However, this goes
against the idea of the built-in listbox - a simple list vs. a list of
lists. Even though the interface is the same (insert/get), you can't
really use the same code across the two widgets.


DrS

nemethi

unread,
Feb 3, 2012, 4:12:54 PM2/3/12
to
The reference manual clearly defines tablelist items as *lists* of
elements. When you insert an item and then retrieve it by passing just
one index to the get subcommand, then the return value will be (just
like the inserted one) a list and should be treated as such.

Of course, if the widget has just one column and you insert an item
consisting of two or more elements, then the item in question will be
truncated after its first element and the resulting one-element list
will be inserted in place of the original one. On the other hand, in
the most common case that the number of elements of the original item
equals the number of columns, exactly this number of elements will be
inserted at the specified row position.

Tablelist widgets behave really very much like Tk core listboxes. But,
due to the definition of tablelist items as being *lists*, this similar
behavior cannot be completely identical. IMHO, this is by no way a
"major bug in tablelist", but a quite logical consequence of the
difference between the notions of string and list. In addition, there
is no place in the documentation stating that you can "use the same code
across the two widgets". The scripts will be very similar, but they
cannot be identical!

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

DrS

unread,
Feb 3, 2012, 4:59:13 PM2/3/12
to
On 2/3/2012 4:12 PM, nemethi wrote:
>
>IMHO, this is by no way a
> "major bug in tablelist", but a quite logical consequence of the
> difference between the notions of string and list.

Of course, it is not major - it actually seems logical after the fact.
Somehow, I was under the impression that in the simple one-column case,
it would behave like a listbox. Once I realized it was always returning
rows, things were OK.

Thanks,

DrS

0 new messages