Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The generation of random numbers is too important to be left to chance.


devel / comp.lang.tcl / Re: Multi Selection in treeview

SubjectAuthor
* Multi Selection in treeviewGeorgeB
`* Re: Multi Selection in treeviewsaitology9
 `* Re: Multi Selection in treeviewsaitology9
  `* Re: Multi Selection in treeviewGeorgeB
   +- Re: Multi Selection in treeviewsaitology9
   `* Re: Multi Selection in treeviewRich
    `* Re: Multi Selection in treeviewGeorgeB
     `* Re: Multi Selection in treeviewRich
      `* Re: Multi Selection in treeviewGeorgeB
       `- Re: Multi Selection in treeviewRich

1
Multi Selection in treeview

<7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:28ce:b0:6cf:933c:40d3 with SMTP id l14-20020a05620a28ce00b006cf933c40d3mr11875504qkp.258.1664379794518;
Wed, 28 Sep 2022 08:43:14 -0700 (PDT)
X-Received: by 2002:a05:6214:f6a:b0:4a7:fe99:a39f with SMTP id
iy10-20020a0562140f6a00b004a7fe99a39fmr26314744qvb.26.1664379794345; Wed, 28
Sep 2022 08:43:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 28 Sep 2022 08:43:14 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=147.161.166.87; posting-account=raWrPgoAAACs0CUtdroJeI3APEgMzJCg
NNTP-Posting-Host: 147.161.166.87
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com>
Subject: Multi Selection in treeview
From: george.booth3182@gmail.com (GeorgeB)
Injection-Date: Wed, 28 Sep 2022 15:43:14 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 7617
 by: GeorgeB - Wed, 28 Sep 2022 15:43 UTC

Is it possible to multi select and keep the selection persistent without holding Ctrl.

Basically I would like to make selection easier for User (tree is has grown to 10 nodes each with several children).

1) select item
2) to deselect User will have to click item in tree again, until then it remains persistent.

I'd prefer to have a checkbox facility where User can check/uncheck selection, but checkbox is not possible in treeview.

I've tried with image of check and unchecked that can be toggled upon selection, I can add the image but can't seem to understand where to set it such that it toggles to unchecked (not sure if this is a wise approach).

Any help/advice is appreciated. Code is below.

package req Tk

image create photo ::img::cbu(0) -data {
R0lGODlhDwAPANUAANnZ2Y6Pj/T09K6zua+0urS5vbu+wcvP1dDT2NXY3Nvd38HDxc3R1tLV2tjb
3t3f4eLj5MbHyM3R19DU2dTX2+Hi4+Xm5ujo6MzNzbK3vNrc3+Dh4+zs7O3t7dTV1ri7v+Tl5erq
6u/v7/Ly8tzd3ry/wuPk5enp6fX19eHi4sLExvDw8Pb29ubm5srLzNTU1dvb3ODh4ebn5+rr6+vs
7Ovr7Onp6v///////////////////////////////////yH5BAEAAAAALAAAAAAPAA8AAAZvQIBw
SCwCAsikMikMCJ7QqCDQFAyuWELBMK0ODuADIqFYdI9WMKPheEAiZ+dAMqEoKpYLJi7IJDQbFxwd
HR58Hw8gISIjjSR8JSYnHSMCKAIpfCqTKwIsny18Li8wMTIzNDU2fFJSVEdLsa9GtABBADs=}
image create photo ::img::cbc(1) -data {
R0lGODlhDwAPAOYAANnZ2Y6Pj/T09Pj4+Pn5+fb29q6zucnM0J2nwHeGq9zf5PX19cvP1czQ1u3u
8VdqnURakrm/0M3R1uDi5q+4z0VakmV3pefn6NXZ3d/i5dXY3PLz9F5xoUdclLzD1tvc3MXJzcnP
3aOuyO3u7rrB1UlelmR2pdXV1t7g4W5/qs/U4md4p0tgl7e/1dzd3s3P0d7h6UhdlUlflmFzpPj5
+uHi4sbIyurs8IuZu0pfl0xhmLC50ebm5srLzNra29/i6YyZupCdvfLz9uzt7evr7Onp6v//////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////yH5
BAEAAAAALAAAAAAPAA8AAAeFgACCg4SFAAGIiYqJggECj5ACAwQFAgGNAgaamgcICQoLl4eZDKUN
Dg8QEQWijgalEhMUFRYXlpgGGBkaGxwdHh+3oyAhIiMkJSYDJ8KOKCkdKissLQUuzQIvMDEyLDM0
AjXYNjc4OTo7lDzYPT4/QEFCQ0RF2I8LBAMLka2L/qKGAgIIBAA7}

proc populateRoots {tree ROOT SHOW_TYPES} {
populateTree $tree \
[$tree insert {} end -text "Network File" \
-values [list $ROOT directory] \
-open 1] \
$SHOW_TYPES
}

## Code to populate a node of the tree
proc populateTree {tree node SHOW_TYPES} {

if {[$tree set $node type] ne "directory"} {
return
} set path [$tree set $node fullpath]
$tree delete [$tree children $node]

### display so that folders comes before files at the same level
### files and folders are displayed in alphabetical order
set folders [lsort -dictionary [glob -nocomplain -type d -dir \
$path *]]
set files [lsort -dictionary [glob -nocomplain -type f -dir \
$path *]]

foreach f [list {*}$folders {*}$files] {
set type [file type $f]
if {$type eq "directory"} {
### this is a folder
### Make it so that this node is openable
set id [$tree insert $node end -text [file tail $f] \
-values [list $f $type] \
-open 0]

$tree insert $id 0 -text dummy ;# a dummy
$tree item $id -text [file tail $f]/

### this folder has sub-folders
### process them automatically
### so the user does not have to click on each one
### to find where actual files are
populateTree $tree $id $SHOW_TYPES

} elseif {($type eq "file") && \
([file extension $f] in $SHOW_TYPES)} {

### get basic info on the file to display

### Format the file size nicely
set size [file size $f]
if {$size >= 1024*1024*1024} {
set size [format %.1f\ GB [expr {$size/1024/1024/1024.}]]
} elseif {$size >= 1024*1024} {
set size [format %.1f\ MB [expr {$size/1024/1024.}]]
} elseif {$size >= 1024} {
set size [format %.1f\ kB [expr {$size/1024.}]]
} else {
append size " bytes"
}

### format the date and time nicely
set ttime [file mtime $f]
set fdate [clock format $ttime -format "%Y-%m-%d"]
set ftime [clock format $ttime -format "%H-%M-%S"]

### display the file in the tree
set id [$tree insert $node end \
-tags SHOW_FILE \
-text [file tail $f] \
-values [list $f $type $size $fdate $ftime]]

# set id [$tree insert $node end \
# -tags SHOW_FILE \
# -text [file tail $f] \
# -values [list $f $type $size $fdate $ftime] \
# -image ::img::cbu(0)]

### only open folders that are not empty
### THIS FOLDER HAS A DISPLAYABLE FILE IN IT
### AUTOMATICALLY OPEN IT
$tree set $id size $size
$tree item [$tree parent $id] -open 1 -tags FOLDER_HAS_ITEM

} else {
# a file type that will not be shown
} }

# Stop this code from rerunning on the current node
$tree set $node type processedDirectory
}

# ## Create the tree and set it up
proc display_tree {tw ROOT SHOW_TYPES} {
catch { destroy $tw.tree }
catch { destroy $tw.vsb }
catch { destroy $tw.hsb }
catch { destroy $tw.dummy }

ttk::treeview $tw.tree -columns {fullpath type size date time} \
-displaycolumns {size date time} \
-yscroll "$tw.vsb set" -xscroll "$tw.hsb set"
ttk::scrollbar $tw.vsb -orient vertical -command "$tw.tree yview"
ttk::scrollbar $tw.hsb -orient horizontal -command "$tw.tree xview"

$tw.tree heading \#0 -text "Directory Structure"
$tw.tree heading size -text "File Size" -anchor w
$tw.tree heading date -text "Last Mod Date" -anchor w
$tw.tree heading time -text "Last Mod Time" -anchor w

$tw.tree column size -stretch 1 -width 20
$tw.tree column date -stretch 1 -width 20
$tw.tree column time -stretch 1 -width 20

### you can make files and non-empty folders more visible
### by playing around with colors and fonts as below
### change or remove as needed
$tw.tree tag config SHOW_FILE -foreground blue -font bold
$tw.tree tag config FOLDER_HAS_ITEM -foreground red -font bold

populateRoots $tw.tree $ROOT $SHOW_TYPES
bind $tw.tree <<TreeviewOpen>> {populateTree %W [%W focus]
$SHOW_TYPES}

# ## Arrange the tree and its scrollbars in the toplevel
lower [ttk::frame $tw.dummy]

pack $tw.dummy -fill both -expand 1

grid $tw.tree $tw.vsb -sticky nsew -in $tw.dummy
grid $tw.hsb -sticky nsew -in $tw.dummy
grid columnconfigure $tw.dummy 0 -weight 1
grid rowconfigure $tw.dummy 0 -weight 1

}

proc run_test {} {

wm iconify .

### first window
set ROOT_1 "C:/Dev"
set SHOW_TYPES [list .ini .txt .docx]

catch {destroy .t1 }
toplevel .t1
wm title .t1 $ROOT_1
wm geom .t1 500x400

display_tree .t1 $ROOT_1 $SHOW_TYPES

### second window with different files to show
set ROOT_2 "C:/Windows/INF"
set SHOW_TYPES [list .ini .csv]

catch {destroy .t2 }
toplevel .t2
wm title .t2 $ROOT_2
wm geom .t2 800x600

display_tree .t2 $ROOT_2 $SHOW_TYPES
}

### start here
run_test

Re: Multi Selection in treeview

<th24ar$16sa$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.91.POSTED!not-for-mail
From: saitology9@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Multi Selection in treeview
Date: Wed, 28 Sep 2022 14:38:17 -0400
Organization: Aioe.org NNTP Server
Message-ID: <th24ar$16sa$1@gioia.aioe.org>
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="39818"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.2
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: saitology9 - Wed, 28 Sep 2022 18:38 UTC

On 9/28/22 11:43 AM, GeorgeB wrote:
> Is it possible to multi select and keep the selection persistent without holding Ctrl.
>
> Basically I would like to make selection easier for User (tree is has grown to 10 nodes each with several children).
>
> 1) select item
> 2) to deselect User will have to click item in tree again, until then it remains persistent.
>
> I'd prefer to have a checkbox facility where User can check/uncheck selection, but checkbox is not possible in treeview.
>

## put this bind inside display_tree with the other bind
bind $tw.tree <ButtonRelease-1> {manage_sel %W}

proc manage_sel {tw} {
set sel [$tw item {} -values]
set new [$tw focus]

if {$new eq ""} {
return
} elseif {[$tw set $new type] ne "file"} {
set sel [lremove $sel $new]
} elseif {$new in $sel} {
set sel [lremove $sel $new]
} else {
lappend sel $new
}

$tw item {} -values $sel
$tw selection set {}
$tw selection set $sel
}

Re: Multi Selection in treeview

<th24jc$16sa$2@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.91.POSTED!not-for-mail
From: saitology9@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Multi Selection in treeview
Date: Wed, 28 Sep 2022 14:42:50 -0400
Organization: Aioe.org NNTP Server
Message-ID: <th24jc$16sa$2@gioia.aioe.org>
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com>
<th24ar$16sa$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="39818"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.2
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: saitology9 - Wed, 28 Sep 2022 18:42 UTC

On 9/28/22 2:38 PM, saitology9 wrote:
>
>
> ## put this bind inside display_tree with the other bind
> bind $tw.tree <ButtonRelease-1> {manage_sel %W}
>

Or try these bindings to reduce flashing:

bind $tw.tree <Button-1> {}
bind $tw.tree <ButtonRelease-1> {manage_sel %W}

Re: Multi Selection in treeview

<abfa0a82-fd16-406b-ae26-47b3d94b3aebn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:5bcd:0:b0:35b:b56d:b5 with SMTP id b13-20020ac85bcd000000b0035bb56d00b5mr1399384qtb.462.1664440214079;
Thu, 29 Sep 2022 01:30:14 -0700 (PDT)
X-Received: by 2002:a0c:f3d3:0:b0:4a0:86d9:1807 with SMTP id
f19-20020a0cf3d3000000b004a086d91807mr1484055qvm.19.1664440213943; Thu, 29
Sep 2022 01:30:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 29 Sep 2022 01:30:13 -0700 (PDT)
In-Reply-To: <th24jc$16sa$2@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=147.161.166.87; posting-account=raWrPgoAAACs0CUtdroJeI3APEgMzJCg
NNTP-Posting-Host: 147.161.166.87
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com>
<th24ar$16sa$1@gioia.aioe.org> <th24jc$16sa$2@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <abfa0a82-fd16-406b-ae26-47b3d94b3aebn@googlegroups.com>
Subject: Re: Multi Selection in treeview
From: george.booth3182@gmail.com (GeorgeB)
Injection-Date: Thu, 29 Sep 2022 08:30:14 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1702
 by: GeorgeB - Thu, 29 Sep 2022 08:30 UTC

On Wednesday, September 28, 2022 at 7:42:56 PM UTC+1, saitology9 wrote:
> On 9/28/22 2:38 PM, saitology9 wrote:
> >
> >
> > ## put this bind inside display_tree with the other bind
> > bind $tw.tree <ButtonRelease-1> {manage_sel %W}
> >
> Or try these bindings to reduce flashing:
>
> bind $tw.tree <Button-1> {}
> bind $tw.tree <ButtonRelease-1> {manage_sel %W}

I seem to get error invalid command name "lremove"

Just a thought, can I use the same logic to change ::img::cbu(0) to ::img::cbc(1) upon selection of Item?

Re: Multi Selection in treeview

<th5ebi$pad$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.91.POSTED!not-for-mail
From: saitology9@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Multi Selection in treeview
Date: Thu, 29 Sep 2022 20:47:46 -0400
Organization: Aioe.org NNTP Server
Message-ID: <th5ebi$pad$1@gioia.aioe.org>
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com>
<th24ar$16sa$1@gioia.aioe.org> <th24jc$16sa$2@gioia.aioe.org>
<abfa0a82-fd16-406b-ae26-47b3d94b3aebn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="25933"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.2
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: saitology9 - Fri, 30 Sep 2022 00:47 UTC

On 9/29/22 4:30 AM, GeorgeB wrote:
> On Wednesday, September 28, 2022 at 7:42:56 PM UTC+1, saitology9 wrote:
>> On 9/28/22 2:38 PM, saitology9 wrote:
>>>
>>>
>>> ## put this bind inside display_tree with the other bind
>>> bind $tw.tree <ButtonRelease-1> {manage_sel %W}
>>>
>> Or try these bindings to reduce flashing:
>>
>> bind $tw.tree <Button-1> {}
>> bind $tw.tree <ButtonRelease-1> {manage_sel %W}
>
> I seem to get error invalid command name "lremove"
>

Interesting. Here is the definition from tkcon:

## lremove - remove items from a list
# OPTS:
# -all remove all instances of each item
# -glob remove all instances matching glob pattern
# -regexp remove all instances matching regexp pattern
# ARGS: l a list to remove items from
# args items to remove (these are 'join'ed together)
##
proc lremove {args} {
array set opts {-all 0 pattern -exact}
while {[string match -* [lindex $args 0]]} {
switch -glob -- [lindex $args 0] {
-a* { set opts(-all) 1 }
-g* { set opts(pattern) -glob }
-r* { set opts(pattern) -regexp }
-- { set args [lreplace $args 0 0]; break }
default {return -code error "unknown option \"[lindex $args 0]\""}
}
set args [lreplace $args 0 0]
}
set l [lindex $args 0]
foreach i [join [lreplace $args 0 0]] {
if {[set ix [lsearch $opts(pattern) $l $i]] == -1} continue
set l [lreplace $l $ix $ix]
if {$opts(-all)} {
while {[set ix [lsearch $opts(pattern) $l $i]] != -1} {
set l [lreplace $l $ix $ix]
}
}
}
return $l
}

Re: Multi Selection in treeview

<th5lbm$tbis$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Multi Selection in treeview
Date: Fri, 30 Sep 2022 02:47:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 4
Message-ID: <th5lbm$tbis$1@dont-email.me>
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com> <th24ar$16sa$1@gioia.aioe.org> <th24jc$16sa$2@gioia.aioe.org> <abfa0a82-fd16-406b-ae26-47b3d94b3aebn@googlegroups.com>
Injection-Date: Fri, 30 Sep 2022 02:47:18 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="2605be769621bdea78dbc1b31dd1ec52";
logging-data="962140"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+//no52MQzowkBK42Mo7jf"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:R/nbvDehgqNtKDltu325TD0Ip50=
 by: Rich - Fri, 30 Sep 2022 02:47 UTC

GeorgeB <george.booth3182@gmail.com> wrote:
> I seem to get error invalid command name "lremove"

What version of Tcl are you using?

Re: Multi Selection in treeview

<ab040cf7-19b2-43bb-a47f-fe3db30f9735n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:5c49:0:b0:4af:9203:8c75 with SMTP id a9-20020ad45c49000000b004af92038c75mr5682164qva.76.1664524256855;
Fri, 30 Sep 2022 00:50:56 -0700 (PDT)
X-Received: by 2002:ac8:580d:0:b0:35c:3fcc:2442 with SMTP id
g13-20020ac8580d000000b0035c3fcc2442mr5650937qtg.501.1664524256704; Fri, 30
Sep 2022 00:50:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 30 Sep 2022 00:50:56 -0700 (PDT)
In-Reply-To: <th5lbm$tbis$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=147.161.166.87; posting-account=raWrPgoAAACs0CUtdroJeI3APEgMzJCg
NNTP-Posting-Host: 147.161.166.87
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com>
<th24ar$16sa$1@gioia.aioe.org> <th24jc$16sa$2@gioia.aioe.org>
<abfa0a82-fd16-406b-ae26-47b3d94b3aebn@googlegroups.com> <th5lbm$tbis$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ab040cf7-19b2-43bb-a47f-fe3db30f9735n@googlegroups.com>
Subject: Re: Multi Selection in treeview
From: george.booth3182@gmail.com (GeorgeB)
Injection-Date: Fri, 30 Sep 2022 07:50:56 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1574
 by: GeorgeB - Fri, 30 Sep 2022 07:50 UTC

On Friday, September 30, 2022 at 3:47:23 AM UTC+1, Rich wrote:
> GeorgeB <george.b...@gmail.com> wrote:
> > I seem to get error invalid command name "lremove"
> What version of Tcl are you using?

@saitology9, thanks that got rid of the error message but the bandings seem to have disappeared.

@Rich, using TCL 8.6.9

Re: Multi Selection in treeview

<th6tkb$117sv$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Multi Selection in treeview
Date: Fri, 30 Sep 2022 14:14:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <th6tkb$117sv$1@dont-email.me>
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com> <th24ar$16sa$1@gioia.aioe.org> <th24jc$16sa$2@gioia.aioe.org> <abfa0a82-fd16-406b-ae26-47b3d94b3aebn@googlegroups.com> <th5lbm$tbis$1@dont-email.me> <ab040cf7-19b2-43bb-a47f-fe3db30f9735n@googlegroups.com>
Injection-Date: Fri, 30 Sep 2022 14:14:35 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="2605be769621bdea78dbc1b31dd1ec52";
logging-data="1089439"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cIC0asjXY0t5FMLCljied"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:mV6qEay+TyBQdYoIxB1sVvbn6UI=
 by: Rich - Fri, 30 Sep 2022 14:14 UTC

GeorgeB <george.booth3182@gmail.com> wrote:
> On Friday, September 30, 2022 at 3:47:23 AM UTC+1, Rich wrote:
>> GeorgeB <george.b...@gmail.com> wrote:
>> > I seem to get error invalid command name "lremove"
>> What version of Tcl are you using?
>
> @saitology9, thanks that got rid of the error message but the bandings seem to have disappeared.
>
> @Rich, using TCL 8.6.9

Ok, that explains why you saw no lremove, lremove was added in of 8.7.

Note, it is better to reply to each message, not "group replies" into a
single one. Most of us here are not using that absolutely awful google
groups interface, and doing "group replies" breaks the message
threading for everyone else.

Re: Multi Selection in treeview

<aacb8330-3c7f-4b06-86ec-2ec07ff13ee9n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:254f:b0:6cf:9b54:11dd with SMTP id s15-20020a05620a254f00b006cf9b5411ddmr6088063qko.55.1664549162074;
Fri, 30 Sep 2022 07:46:02 -0700 (PDT)
X-Received: by 2002:ac8:7f4c:0:b0:35c:ceb3:4409 with SMTP id
g12-20020ac87f4c000000b0035cceb34409mr6998624qtk.138.1664549161866; Fri, 30
Sep 2022 07:46:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 30 Sep 2022 07:46:01 -0700 (PDT)
In-Reply-To: <th6tkb$117sv$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=147.161.166.87; posting-account=raWrPgoAAACs0CUtdroJeI3APEgMzJCg
NNTP-Posting-Host: 147.161.166.87
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com>
<th24ar$16sa$1@gioia.aioe.org> <th24jc$16sa$2@gioia.aioe.org>
<abfa0a82-fd16-406b-ae26-47b3d94b3aebn@googlegroups.com> <th5lbm$tbis$1@dont-email.me>
<ab040cf7-19b2-43bb-a47f-fe3db30f9735n@googlegroups.com> <th6tkb$117sv$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <aacb8330-3c7f-4b06-86ec-2ec07ff13ee9n@googlegroups.com>
Subject: Re: Multi Selection in treeview
From: george.booth3182@gmail.com (GeorgeB)
Injection-Date: Fri, 30 Sep 2022 14:46:02 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 10256
 by: GeorgeB - Fri, 30 Sep 2022 14:46 UTC

On Friday, September 30, 2022 at 3:14:40 PM UTC+1, Rich wrote:
> GeorgeB <george.b...@gmail.com> wrote:
> > On Friday, September 30, 2022 at 3:47:23 AM UTC+1, Rich wrote:
> >> GeorgeB <george.b...@gmail.com> wrote:
> >> > I seem to get error invalid command name "lremove"
> >> What version of Tcl are you using?
> >
> > @saitology9, thanks that got rid of the error message but the bandings seem to have disappeared.
> >
> > @Rich, using TCL 8.6.9
> Ok, that explains why you saw no lremove, lremove was added in of 8.7.
>
> Note, it is better to reply to each message, not "group replies" into a
> single one. Most of us here are not using that absolutely awful google
> groups interface, and doing "group replies" breaks the message
> threading for everyone else.

Ahh, understood.

Btw in my earlier message I mentioned that banding i.e. highlighted row upon selection seemed to have disappeared. That does happen but only when I run the code with other parts of my GUI application.

If I run the code (shown below) in a fresh clean script and run it from command line....all is good.

So, where would I start looking if I had to debug. I think "$tw selection set $sel" is not being set hence I can not see selection on screen but if I print $sel to console, then it shows the items that I have clicked on the tree.

package req Tk

## lremove - remove items from a list
# OPTS:
# -all remove all instances of each item
# -glob remove all instances matching glob pattern
# -regexp remove all instances matching regexp pattern
# ARGS: l a list to remove items from
# args items to remove (these are 'join'ed together)
##
proc lremove {args} {
array set opts {-all 0 pattern -exact}
while {[string match -* [lindex $args 0]]} {
switch -glob -- [lindex $args 0] {
-a* { set opts(-all) 1 }
-g* { set opts(pattern) -glob }
-r* { set opts(pattern) -regexp }
-- { set args [lreplace $args 0 0]; break }
default {return -code error "unknown option \"[lindex $args 0]\""}
} set args [lreplace $args 0 0]
} set l [lindex $args 0]
foreach i [join [lreplace $args 0 0]] {
if {[set ix [lsearch $opts(pattern) $l $i]] == -1} continue
set l [lreplace $l $ix $ix]
if {$opts(-all)} {
while {[set ix [lsearch $opts(pattern) $l $i]] != -1} {
set l [lreplace $l $ix $ix]
} }
} return $l
}

image create photo ::img::cb(0) -data {
R0lGODlhDwAPANUAANnZ2Y6Pj/T09K6zua+0urS5vbu+wcvP1dDT2NXY3Nvd38HDxc3R1tLV2tjb
3t3f4eLj5MbHyM3R19DU2dTX2+Hi4+Xm5ujo6MzNzbK3vNrc3+Dh4+zs7O3t7dTV1ri7v+Tl5erq
6u/v7/Ly8tzd3ry/wuPk5enp6fX19eHi4sLExvDw8Pb29ubm5srLzNTU1dvb3ODh4ebn5+rr6+vs
7Ovr7Onp6v///////////////////////////////////yH5BAEAAAAALAAAAAAPAA8AAAZvQIBw
SCwCAsikMikMCJ7QqCDQFAyuWELBMK0ODuADIqFYdI9WMKPheEAiZ+dAMqEoKpYLJi7IJDQbFxwd
HR58Hw8gISIjjSR8JSYnHSMCKAIpfCqTKwIsny18Li8wMTIzNDU2fFJSVEdLsa9GtABBADs=}
image create photo ::img::cb(1) -data {
R0lGODlhDwAPAOYAANnZ2Y6Pj/T09Pj4+Pn5+fb29q6zucnM0J2nwHeGq9zf5PX19cvP1czQ1u3u
8VdqnURakrm/0M3R1uDi5q+4z0VakmV3pefn6NXZ3d/i5dXY3PLz9F5xoUdclLzD1tvc3MXJzcnP
3aOuyO3u7rrB1UlelmR2pdXV1t7g4W5/qs/U4md4p0tgl7e/1dzd3s3P0d7h6UhdlUlflmFzpPj5
+uHi4sbIyurs8IuZu0pfl0xhmLC50ebm5srLzNra29/i6YyZupCdvfLz9uzt7evr7Onp6v//////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////yH5
BAEAAAAALAAAAAAPAA8AAAeFgACCg4SFAAGIiYqJggECj5ACAwQFAgGNAgaamgcICQoLl4eZDKUN
Dg8QEQWijgalEhMUFRYXlpgGGBkaGxwdHh+3oyAhIiMkJSYDJ8KOKCkdKissLQUuzQIvMDEyLDM0
AjXYNjc4OTo7lDzYPT4/QEFCQ0RF2I8LBAMLka2L/qKGAgIIBAA7}

proc populateRoots {tree ROOT SHOW_TYPES} {
populateTree $tree \
[$tree insert {} end -text "Network File" \
-values [list $ROOT directory] \
-open 1] \
$SHOW_TYPES
}

## Code to populate a node of the tree
proc populateTree {tree node SHOW_TYPES} {

if {[$tree set $node type] ne "directory"} {
return
} set path [$tree set $node fullpath]
$tree delete [$tree children $node]

### display so that folders comes before files at the same level
### files and folders are displayed in alphabetical order
set folders [lsort -dictionary [glob -nocomplain -type d -dir \
$path *]]
set files [lsort -dictionary [glob -nocomplain -type f -dir \
$path *]]

foreach f [list {*}$folders {*}$files] {
set type [file type $f]
if {$type eq "directory"} {
### this is a folder
### Make it so that this node is openable
set id [$tree insert $node end -text [file tail $f] \
-values [list $f $type] \
-open 0]

$tree insert $id 0 -text dummy ;# a dummy
$tree item $id -text [file tail $f]/

### this folder has sub-folders
### process them automatically
### so the user does not have to click on each one
### to find where actual files are
populateTree $tree $id $SHOW_TYPES

} elseif {($type eq "file") && \
([file extension $f] in $SHOW_TYPES)} {

### get basic info on the file to display

### Format the file size nicely
set size [file size $f]
if {$size >= 1024*1024*1024} {
set size [format %.1f\ GB [expr {$size/1024/1024/1024.}]]
} elseif {$size >= 1024*1024} {
set size [format %.1f\ MB [expr {$size/1024/1024.}]]
} elseif {$size >= 1024} {
set size [format %.1f\ kB [expr {$size/1024.}]]
} else {
append size " bytes"
}

### format the date and time nicely
set ttime [file mtime $f]
set fdate [clock format $ttime -format "%Y-%m-%d"]
set ftime [clock format $ttime -format "%H-%M-%S"]

### display the file in the tree

set id [$tree insert $node end \
-tags SHOW_FILE \
-text [file tail $f] \
-values [list $f $type $size $fdate $ftime]]

# set id [$tree insert $node end \
# -tags SHOW_FILE \
# -text [file tail $f] \
# -values [list $f $type $size $fdate $ftime] \
# -image ::img::cb(0)]

### only open folders that are not empty
### THIS FOLDER HAS A DISPLAYABLE FILE IN IT
### AUTOMATICALLY OPEN IT
$tree set $id size $size
$tree item [$tree parent $id] -open 1 -tags FOLDER_HAS_ITEM

} else {
# a file type that will not be shown
} }

# Stop this code from rerunning on the current node
$tree set $node type processedDirectory
}

# ## Create the tree and set it up
proc display_tree {tw ROOT SHOW_TYPES} {
catch { destroy $tw.tree }
catch { destroy $tw.vsb }
catch { destroy $tw.hsb }
catch { destroy $tw.dummy }

ttk::treeview $tw.tree -columns {fullpath type size date time} \
-displaycolumns {size date time} \
-yscroll "$tw.vsb set" -xscroll "$tw.hsb set"
ttk::scrollbar $tw.vsb -orient vertical -command "$tw.tree yview"
ttk::scrollbar $tw.hsb -orient horizontal -command "$tw.tree xview"

$tw.tree heading \#0 -text "Directory Structure"
$tw.tree heading size -text "File Size" -anchor w
$tw.tree heading date -text "Last Mod Date" -anchor w
$tw.tree heading time -text "Last Mod Time" -anchor w

$tw.tree column size -stretch 1 -width 20
$tw.tree column date -stretch 1 -width 20
$tw.tree column time -stretch 1 -width 20

### you can make files and non-empty folders more visible
### by playing around with colors and fonts as below
### change or remove as needed
$tw.tree tag config SHOW_FILE -foreground blue -font bold
$tw.tree tag config FOLDER_HAS_ITEM -foreground red -font bold

populateRoots $tw.tree $ROOT $SHOW_TYPES
bind $tw.tree <<TreeviewOpen>> {populateTree %W [%W focus]
$SHOW_TYPES}

## put this bind inside display_tree with the other bind
bind $tw.tree <ButtonRelease-1> {manage_sel %W}
#bind $tw.tree <Button-1> {manage_sel %W}

# ## Arrange the tree and its scrollbars in the toplevel
lower [ttk::frame $tw.dummy]

pack $tw.dummy -fill both -expand 1

grid $tw.tree $tw.vsb -sticky nsew -in $tw.dummy
grid $tw.hsb -sticky nsew -in $tw.dummy
grid columnconfigure $tw.dummy 0 -weight 1
grid rowconfigure $tw.dummy 0 -weight 1

}

proc manage_sel {tw} {
set sel [$tw item {} -values]
set new [$tw focus]
#set img 0
if {$new eq ""} {
return
} elseif {[$tw set $new type] ne "file"} {
set sel [lremove $sel $new]
#set img 0
} elseif {$new in $sel} {
#set img 1
set sel [lremove $sel $new]
} else {
lappend sel $new
#set img 1
}

$tw item {} -values $sel
# try and change checkbutton image
#$tw item {} -values $sel -image ::img::cb($img)
#$tw item {} -image ::img::cb($img)
$tw selection set {}
$tw selection set $sel
}

proc run_test {} {

wm iconify .

### first window
set ROOT_1 "C:/Dev"
set SHOW_TYPES [list .ini .txt .docx]

catch {destroy .t1 }
toplevel .t1
wm title .t1 $ROOT_1
wm geom .t1 500x400

display_tree .t1 $ROOT_1 $SHOW_TYPES

### second window with different files to show
set ROOT_2 "C:/Windows/INF"
set SHOW_TYPES [list .ini .csv]

catch {destroy .t2 }
toplevel .t2
wm title .t2 $ROOT_2
wm geom .t2 800x600

display_tree .t2 $ROOT_2 $SHOW_TYPES
}


Click here to read the complete article
Re: Multi Selection in treeview

<th7b7q$12n6v$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Multi Selection in treeview
Date: Fri, 30 Sep 2022 18:06:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <th7b7q$12n6v$1@dont-email.me>
References: <7bcc4344-529a-461c-9f12-53a6ec586e57n@googlegroups.com> <th24ar$16sa$1@gioia.aioe.org> <th24jc$16sa$2@gioia.aioe.org> <abfa0a82-fd16-406b-ae26-47b3d94b3aebn@googlegroups.com> <th5lbm$tbis$1@dont-email.me> <ab040cf7-19b2-43bb-a47f-fe3db30f9735n@googlegroups.com> <th6tkb$117sv$1@dont-email.me> <aacb8330-3c7f-4b06-86ec-2ec07ff13ee9n@googlegroups.com>
Injection-Date: Fri, 30 Sep 2022 18:06:51 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="2605be769621bdea78dbc1b31dd1ec52";
logging-data="1137887"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/SjR1tgDBdfqcSaABOOsgr"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:n27GKCPxclOldT7y4HhIxr5xOaI=
 by: Rich - Fri, 30 Sep 2022 18:06 UTC

GeorgeB <george.booth3182@gmail.com> wrote:
> On Friday, September 30, 2022 at 3:14:40 PM UTC+1, Rich wrote:
>> GeorgeB <george.b...@gmail.com> wrote:
>> > On Friday, September 30, 2022 at 3:47:23 AM UTC+1, Rich wrote:
>> >> GeorgeB <george.b...@gmail.com> wrote:
>> >> > I seem to get error invalid command name "lremove"
>> >> What version of Tcl are you using?
>> >
>> > @saitology9, thanks that got rid of the error message but the
>> > bandings seem to have disappeared.
>> >
>> > @Rich, using TCL 8.6.9
>> >
>> Ok, that explains why you saw no lremove, lremove was added in of 8.7.
>>
>> Note, it is better to reply to each message, not "group replies" into a
>> single one. Most of us here are not using that absolutely awful google
>> groups interface, and doing "group replies" breaks the message
>> threading for everyone else.
>
> Ahh, understood.
>
> Btw in my earlier message I mentioned that banding i.e. highlighted
> row upon selection seemed to have disappeared. That does happen but
> only when I run the code with other parts of my GUI application.
>
> If I run the code (shown below) in a fresh clean script and run it
> from command line....all is good.
>
> So, where would I start looking if I had to debug. I think "$tw
> selection set $sel" is not being set hence I can not see selection on
> screen but if I print $sel to console, then it shows the items that I
> have clicked on the tree.

If the color highlight of selected rows disappears when you've run that
code along with the rest of the script, then 'where' is: "somewhere in
that other code". I.e. something is being done by that other code that
is causing you the troubles.

Some possibilities might include:

1) changing the default colors for 'highlights' to be the same as
'not highlighted'

2) mucking about with the event bindings that provide the abililty to
select rows and cause them to be highlighted.

You can see how the various 'interactions' between the mouse
cursor/buttons and keyboard keys work for the treeview widget by
looking at the bindings in the treeview.tcl file in your Tcl
installation.

For me, on Linux, that file is located at: /usr/lib/tk8.6/ttk/treeview.tcl

For you, on windows, it will obviously be somewhere else within the Tcl
installation location.


devel / comp.lang.tcl / Re: Multi Selection in treeview

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor