Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Yes, and I feel bad about rendering their useless carci into dogfood..." -- Badger comics


devel / comp.lang.tcl / Tablelist and sorting a column with empty cells by integer

SubjectAuthor
* Tablelist and sorting a column with empty cells by integergreg
`* Re: Tablelist and sorting a column with empty cells by integergreg
 `* Re: Tablelist and sorting a column with empty cells by integernemethi
  `* Re: Tablelist and sorting a column with empty cells by integergreg
   +* Re: Tablelist and sorting a column with empty cells by integernemethi
   |`- Re: Tablelist and sorting a column with empty cells by integergreg
   `- Re: Tablelist and sorting a column with empty cells by integerRalf Fassel

1
Tablelist and sorting a column with empty cells by integer

<uuhv27$3evo2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13231&group=comp.lang.tcl#13231

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gregor.e...@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Tablelist and sorting a column with empty cells by integer
Date: Tue, 2 Apr 2024 23:58:31 +0200
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <uuhv27$3evo2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 02 Apr 2024 21:58:31 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2b6ae9c817769b825a39343c953b9aa9";
logging-data="3636994"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19A9HsAf6KngLZGI79PHe/8QlZINHdsmfk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:a/A6bEewfomp21x2pICig8fs3BI=
Content-Language: de-DE
 by: greg - Tue, 2 Apr 2024 21:58 UTC

Hello

Tablelist 7.1
Sorting a column with empty cells by integer:
But I have an error. How do I do this correctly?

Gregor

if {0} {
https://www.nemethi.de/tablelist/tablelistWidget.html#col_formatcommand
....
proc formatNumber val { return [expr {$val == -1 ? "" : $val}] }

This will make the cells displaying an empty string appear before
all the others when sorting the column in increasing order. To achieve
the opposite effect, you will have to replace the -1 with an
application-specific value that is strictly greater than all the other
numbers contained in the column in question.
....
}

package require Tk
package require tablelist

proc formatNumber val {
return [expr {$val == -1 ? "" : $val}]
}

set tf [frame .fr]
set tbl $tf.tbl
set vsb $tf.vsb

tablelist::tablelist $tbl -columns {0 Text left 0 "Number" right } \
-yscrollcommand [list $vsb set] -width 0 \
-labelcommand tablelist::sortByColumn

set col 1
$tbl columnconfigure $col -formatcommand formatNumber -sortmode integer

scrollbar $vsb -orient vertical -command [list $tbl yview]
grid $tbl -row 0 -column 0 -sticky news
grid $vsb -row 0 -column 1 -sticky ns
grid rowconfigure $tf 0 -weight 1
grid columnconfigure $tf 0 -weight 1
pack $tf -side top -expand yes -fill both

# Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty ""}]

if {0} {
Output:
expected integer but got ""
expected integer but got ""
while executing
"tablelist::sortByColumn .fr.tbl 1"
("uplevel" body line 1)
invoked from within
"uplevel #0 $cmd [list $win $col] "
(procedure "tablelist::labelB1Up" line 109)
invoked from within
"tablelist::labelB1Up .fr.tbl.hdr.t.f.l1 990"
(command bound to event)

}

Re: Tablelist and sorting a column with empty cells by integer

<uuikf8$3n5e4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13232&group=comp.lang.tcl#13232

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gregor.e...@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Re: Tablelist and sorting a column with empty cells by integer
Date: Wed, 3 Apr 2024 06:03:52 +0200
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <uuikf8$3n5e4$1@dont-email.me>
References: <uuhv27$3evo2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 03 Apr 2024 04:03:52 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="84acdb88f5cb21e68f85bc11c10c565e";
logging-data="3904964"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/N7WC8E57DWZrCxUOM9v5V8RBb7fRNV/U="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5wDleY/mK5R/yqqEXut8p7H3roE=
In-Reply-To: <uuhv27$3evo2$1@dont-email.me>
Content-Language: de-DE
 by: greg - Wed, 3 Apr 2024 04:03 UTC

Misconception on my part

correct with

#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty -1}]

for
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty ""}]

I have to write a sort command.

Re: Tablelist and sorting a column with empty cells by integer

<uuj7bm$2r4j$1@tota-refugium.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13233&group=comp.lang.tcl#13233

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.tota-refugium.de!.POSTED!not-for-mail
From: csaba.ne...@t-online.de (nemethi)
Newsgroups: comp.lang.tcl
Subject: Re: Tablelist and sorting a column with empty cells by integer
Date: Wed, 3 Apr 2024 11:26:14 +0200
Message-ID: <uuj7bm$2r4j$1@tota-refugium.de>
References: <uuhv27$3evo2$1@dont-email.me> <uuikf8$3n5e4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 3 Apr 2024 09:26:14 -0000 (UTC)
Injection-Info: tota-refugium.de;
logging-data="93331"; mail-complaints-to="abuse@news.tota-refugium.de"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ATAnlM+JgduydgtZI6SyhvQtCQM=
In-Reply-To: <uuikf8$3n5e4$1@dont-email.me>
Content-Language: en-US
X-User-ID: eJwNx8EBwCAIA8CVmoaAjlME9h/B3u9Eh58wl5tG0/4sTix8HWR5jNnGNFJlnfVy63Tyz1QBFxyLEZo=
 by: nemethi - Wed, 3 Apr 2024 09:26 UTC

Am 03.04.24 um 06:03 schrieb greg:
> Misconception on my part
>
> correct with
>
> #Data
> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
>  {empty -1}]
>
>
>
> for
> #Data
> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
>  {empty ""}]
>

This correction eliminates the error message because all *internal* cell
values of the column "Number" are now integers.

> I have to write a sort command.
>

Why? For the column "Number" no sort command is needed.

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

Re: Tablelist and sorting a column with empty cells by integer

<uuk8on$3hrs$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13235&group=comp.lang.tcl#13235

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gregor.e...@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Re: Tablelist and sorting a column with empty cells by integer
Date: Wed, 3 Apr 2024 20:56:22 +0200
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <uuk8on$3hrs$1@dont-email.me>
References: <uuhv27$3evo2$1@dont-email.me> <uuikf8$3n5e4$1@dont-email.me>
<uuj7bm$2r4j$1@tota-refugium.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 03 Apr 2024 18:56:23 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="84acdb88f5cb21e68f85bc11c10c565e";
logging-data="116604"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18f5sS326I1E2CSwlTl0l8JgyZhLhFTIs8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:o8U5WbHOdejS+sAffeqlGMtq3G8=
In-Reply-To: <uuj7bm$2r4j$1@tota-refugium.de>
Content-Language: de-DE
 by: greg - Wed, 3 Apr 2024 18:56 UTC

Am 03.04.24 um 11:26 schrieb nemethi:
> Am 03.04.24 um 06:03 schrieb greg:
>> Misconception on my part
>>
>> correct with
>>
>> #Data
>> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
>> 11}   {empty -1}]
>>
>>
>>
>> for
>> #Data
>> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
>> 11}   {empty ""}]
>>
>
> This correction eliminates the error message because all *internal* cell
> values of the column "Number" are now integers.
>
>> I have to write a sort command.
>>
>
> Why?  For the column "Number" no sort command is needed.
>

1)
set col 1
$tbl columnconfigure $col -formatcommand formatNumber
# Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty -1}]

sorts the 11 between 1 and 2

2)
set col 1
$tbl columnconfigure $col -formatcommand formatNumber -sortmode integer
# Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty -1}]

#sorts ok

But if I need the values from column Number for a summation, I cannot
use this method. Then I have an incorrect sum with the substitute values
for "".
Hence a proc for it

proc customCompare {a b} {
# Treat empty cells as very large so they will be sorted at the end
if {$a eq ""} {set a 999999}
if {$b eq ""} {set b 999999}
# Convert to numbers and compare
set numA [expr {int($a)}]
set numB [expr {int($b)}]
if {$numA < $numB} {
return -1
} elseif {$numA > $numB} {
returns 1
} else {
return 0
}
}

Re: Tablelist and sorting a column with empty cells by integer

<uukb63$3fah$1@tota-refugium.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13236&group=comp.lang.tcl#13236

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.tota-refugium.de!.POSTED!not-for-mail
From: csaba.ne...@t-online.de (nemethi)
Newsgroups: comp.lang.tcl
Subject: Re: Tablelist and sorting a column with empty cells by integer
Date: Wed, 3 Apr 2024 21:37:39 +0200
Message-ID: <uukb63$3fah$1@tota-refugium.de>
References: <uuhv27$3evo2$1@dont-email.me> <uuikf8$3n5e4$1@dont-email.me>
<uuj7bm$2r4j$1@tota-refugium.de> <uuk8on$3hrs$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 3 Apr 2024 19:37:39 -0000 (UTC)
Injection-Info: tota-refugium.de;
logging-data="114001"; mail-complaints-to="abuse@news.tota-refugium.de"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:SjdnSH1rvopTwzsmK9Mb52OkLck=
X-User-ID: eJwFwYEBwCAIA7CXQGjFcxiz/59ggqBzdhJMCMrx8tJ80bqGhdNls+vyzGrCo6/PL5mpU/EAIToRiQ==
Content-Language: en-US
In-Reply-To: <uuk8on$3hrs$1@dont-email.me>
 by: nemethi - Wed, 3 Apr 2024 19:37 UTC

Am 03.04.24 um 20:56 schrieb greg:
> Am 03.04.24 um 11:26 schrieb nemethi:
>> Am 03.04.24 um 06:03 schrieb greg:
>>> Misconception on my part
>>>
>>> correct with
>>>
>>> #Data
>>> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
>>> 11}   {empty -1}]
>>>
>>>
>>>
>>> for
>>> #Data
>>> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
>>> 11}   {empty ""}]
>>>
>>
>> This correction eliminates the error message because all *internal*
>> cell values of the column "Number" are now integers.
>>
>>> I have to write a sort command.
>>>
>>
>> Why?  For the column "Number" no sort command is needed.
>>
>
> 1)
> set col 1
> $tbl columnconfigure $col -formatcommand formatNumber
> # Data
> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
>  {empty -1}]
>
> sorts the 11 between 1 and 2
>
> 2)
> set col 1
> $tbl columnconfigure $col -formatcommand formatNumber -sortmode integer
> # Data
> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
>  {empty -1}]
>
> #sorts ok
>
>
>
> But if I need the values from column Number for a summation, I cannot
> use this method. Then I have an incorrect sum with the substitute values
> for "".
> Hence a proc for it
>
> proc customCompare {a b} {
> # Treat empty cells as very large so they will be sorted at the end
>  if {$a eq ""} {set a 999999}
>  if {$b eq ""} {set b 999999}
> # Convert to numbers and compare
>  set numA [expr {int($a)}]
>  set numB [expr {int($b)}]
>  if {$numA < $numB} {
>    return -1
>  } elseif {$numA > $numB} {
>    returns 1
>  } else {
>   return 0
>  }
> }
>
>
>

Why not use a summation proc rather than a comparison one? You could
write a simple proc that adds the internal cell values, except that it
skips the value -1 (or 999999) when building the sum.

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

Re: Tablelist and sorting a column with empty cells by integer

<uul8ef$e6du$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13237&group=comp.lang.tcl#13237

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gregor.e...@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Re: Tablelist and sorting a column with empty cells by integer
Date: Thu, 4 Apr 2024 05:57:03 +0200
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <uul8ef$e6du$1@dont-email.me>
References: <uuhv27$3evo2$1@dont-email.me> <uuikf8$3n5e4$1@dont-email.me>
<uuj7bm$2r4j$1@tota-refugium.de> <uuk8on$3hrs$1@dont-email.me>
<uukb63$3fah$1@tota-refugium.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 04 Apr 2024 03:57:03 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="5c700c44ebe2d9f74b80784101e45988";
logging-data="465342"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sRoeyItXeTYR1rW0h/5OlJdt+kBZNeGY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:eHfJRHLBChjRiM/F2Rs1MhiLfAs=
Content-Language: de-DE
In-Reply-To: <uukb63$3fah$1@tota-refugium.de>
 by: greg - Thu, 4 Apr 2024 03:57 UTC

Am 03.04.24 um 21:37 schrieb nemethi:
> Am 03.04.24 um 20:56 schrieb greg:
>> Am 03.04.24 um 11:26 schrieb nemethi:
>>> Am 03.04.24 um 06:03 schrieb greg:
>>>> Misconception on my part
>>>>
>>>> correct with
>>>>
>>>> #Data
>>>> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
>>>> 11}   {empty -1}]
>>>>
>>>>
>>>>
>>>> for
>>>> #Data
>>>> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
>>>> 11}   {empty ""}]
>>>>
>>>
>>> This correction eliminates the error message because all *internal*
>>> cell values of the column "Number" are now integers.
>>>
>>>> I have to write a sort command.
>>>>
>>>
>>> Why?  For the column "Number" no sort command is needed.
>>>
>>
>> 1)
>> set col 1
>> $tbl columnconfigure $col -formatcommand formatNumber
>> # Data
>> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
>> 11}   {empty -1}]
>>
>> sorts the 11 between 1 and 2
>>
>> 2)
>> set col 1
>> $tbl columnconfigure $col -formatcommand formatNumber -sortmode integer
>> # Data
>> $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
>> 11}   {empty -1}]
>>
>> #sorts ok
>>
>>
>>
>> But if I need the values from column Number for a summation, I cannot
>> use this method. Then I have an incorrect sum with the substitute
>> values for "".
>> Hence a proc for it
>>
>> proc customCompare {a b} {
>> # Treat empty cells as very large so they will be sorted at the end
>>   if {$a eq ""} {set a 999999}
>>   if {$b eq ""} {set b 999999}
>> # Convert to numbers and compare
>>   set numA [expr {int($a)}]
>>   set numB [expr {int($b)}]
>>   if {$numA < $numB} {
>>     return -1
>>   } elseif {$numA > $numB} {
>>     returns 1
>>   } else {
>>    return 0
>>   }
>> }
>>
>>
>>
>
> Why not use a summation proc rather than a comparison one?  You could
> write a simple proc that adds the internal cell values, except that it
> skips the value -1 (or 999999) when building the sum.
>
That approach didn't even occur to me.
Thanks! Is also a solution

Gregor
Every now and then I have
"ein Brett vor dem Kopf".

Re: Tablelist and sorting a column with empty cells by integer

<ygafrw14fzj.fsf@panther.akutech-local.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13238&group=comp.lang.tcl#13238

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Tablelist and sorting a column with empty cells by integer
Date: Thu, 04 Apr 2024 11:46:56 +0200
Lines: 16
Message-ID: <ygafrw14fzj.fsf@panther.akutech-local.de>
References: <uuhv27$3evo2$1@dont-email.me> <uuikf8$3n5e4$1@dont-email.me>
<uuj7bm$2r4j$1@tota-refugium.de> <uuk8on$3hrs$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net 0hHrdu7zeyCPsxSEVoDMOgSMxb8iAFzW53R4VwyK6awWW3fF4=
Cancel-Lock: sha1:bJDkJD1BjBlfI5XAuWG90v0DYn8= sha1:h8HlSLYZh4Ev0b8905bFmQnSpOI= sha256:e3az3/dnEOdhs/vyXFlVHllvT9V8g86Zow2BOCxjxuY=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Thu, 4 Apr 2024 09:46 UTC

* greg <gregor.ebbing@gmx.de>
| 1)
| set col 1
| $tbl columnconfigure $col -formatcommand formatNumber
| # Data
| $tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
| 11} {empty -1}]
>
| sorts the 11 between 1 and 2

[-sortmode dictionary] might take care of that, plus one would not
(I *think*) require the special value -1. But even then, a separate
summation command would be required to take care of the {empty ""}
cells.

R'

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor