head	1.5;
access;
symbols
	core-8-5-9:1.4
	core-8-5-8:1.4
	macosx-cocoa-merge:1.5
	macosx-cocoa-premerge:1.5
	macosx-carbon-freeze:1.5
	core-8-5-7:1.4
	core-8-5-6:1.4
	core-8-6-b1:1.5
	core-8-6-a3:1.4
	core-8-5-5:1.4
	core-8-6-a2:1.4
	core-8-5-4:1.4
	core-8-5-3:1.4
	core-8-6-a1:1.4
	core-8-5-branch:1.4.0.2
	core-8-5-2:1.4
	core-8-5-1:1.4
	core-8-5-0:1.4
	core-8-5-b3:1.3
	core-8-5-b2:1.2
	core-stabilizer-branch:1.2.0.2
	core-stabilizer-merge:1.4;
locks; strict;
comment	@# @;


1.5
date	2008.12.11.18.13.08;	author jenglish;	state Exp;
branches;
next	1.4;

1.4
date	2007.12.13.15.27.07;	author dgp;	state Exp;
branches;
next	1.3;

1.3
date	2007.11.04.10.38.09;	author das;	state Exp;
branches;
next	1.2;

1.2
date	2007.10.23.06.31.16;	author das;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	2007.10.22.14.21.11;	author dkf;	state Exp;
branches;
next	;

1.2.2.1
date	2007.10.23.06.31.16;	author dgp;	state dead;
branches;
next	1.2.2.2;

1.2.2.2
date	2007.10.24.12.59.33;	author dgp;	state Exp;
branches;
next	1.2.2.3;

1.2.2.3
date	2007.11.05.14.24.18;	author dgp;	state Exp;
branches;
next	;


desc
@@


1.5
log
@library/demos/*.tcl: Omit contraindicated [package require Ttk].
Remove logic that switches [ttk::scrollbar]s to [tk::scrollbar]s
based on [tk windowingsystem]; this is already handled in
library/ttk/scrollbar.tcl.
@
text
@# tree.tcl --
#
# This demonstration script creates a toplevel window containing a Ttk
# tree widget.
#
# RCS: @@(#) $Id: tree.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp $

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require Tk

set w .tree
catch {destroy $w}
toplevel $w
wm title $w "Directory Browser"
wm iconname $w "tree"
positionWindow $w

## Explanatory text
ttk::label $w.msg -font $font -wraplength 4i -justify left -anchor n -padding {10 2 10 6} -text "Ttk is the new Tk themed widget set. One of the widgets it includes is a tree widget, which allows the user to browse a hierarchical data-set such as a filesystem. The tree widget not only allows for the tree part itself, but it also supports an arbitrary number of additional columns which can show additional data (in this case, the size of the files found in your filesystem). You can also change the width of the columns by dragging the boundary between them."
pack $w.msg -fill x

## See Code / Dismiss
pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x

## Code to populate the roots of the tree (can be more than one on Windows)
proc populateRoots {tree} {
    foreach dir [lsort -dictionary [file volumes]] {
	populateTree $tree [$tree insert {} end -text $dir \
		-values [list $dir directory]]
    }
}

## Code to populate a node of the tree
proc populateTree {tree node} {
    if {[$tree set $node type] ne "directory"} {
	return
    }
    set path [$tree set $node fullpath]
    $tree delete [$tree children $node]
    foreach f [lsort -dictionary [glob -nocomplain -dir $path *]] {
	set type [file type $f]
	set id [$tree insert $node end -text [file tail $f] \
		-values [list $f $type]]

	if {$type eq "directory"} {
	    ## Make it so that this node is openable
	    $tree insert $id 0 -text dummy ;# a dummy
	    $tree item $id -text [file tail $f]/

	} elseif {$type eq "file"} {
	    set size [file size $f]
	    ## Format the file size nicely
	    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"
	    }
	    $tree set $id size $size
	}
    }

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

## Create the tree and set it up
ttk::treeview $w.tree -columns {fullpath type size} -displaycolumns {size} \
	-yscroll "$w.vsb set" -xscroll "$w.hsb set"
ttk::scrollbar $w.vsb -orient vertical -command "$w.tree yview"
ttk::scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
$w.tree heading \#0 -text "Directory Structure"
$w.tree heading size -text "File Size"
$w.tree column size -stretch 0 -width 70
populateRoots $w.tree
bind $w.tree <<TreeviewOpen>> {populateTree %W [%W focus]}

## Arrange the tree and its scrollbars in the toplevel
lower [ttk::frame $w.dummy]
pack $w.dummy -fill both -expand 1
grid $w.tree $w.vsb -sticky nsew -in $w.dummy
grid $w.hsb -sticky nsew -in $w.dummy
grid columnconfigure $w.dummy 0 -weight 1
grid rowconfigure $w.dummy 0 -weight 1
@


1.4
log
@merge stable branch onto HEAD
@
text
@d6 1
a6 1
# RCS: @@(#) $Id: tree.tcl,v 1.2.2.3 2007/11/05 14:24:18 dgp Exp $
a12 1
package require Ttk
d76 2
a77 7
if {[tk windowingsystem] ne "aqua"} {
    ttk::scrollbar $w.vsb -orient vertical -command "$w.tree yview"
    ttk::scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
} else {
    scrollbar $w.vsb -orient vertical -command "$w.tree yview"
    scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
}
@


1.3
log
@	* library/demos/mclist.tcl:	Aqua GOOBE.
	* library/demos/tree.tcl:
	* library/demos/ttknote.tcl:
	* library/demos/widget:
@
text
@d6 1
a6 1
# RCS: @@(#) $Id: tree.tcl,v 1.2 2007/10/23 06:31:16 das Exp $
@


1.2
log
@	* library/demos/combo.tcl:	Aqua GOOBE.
	* library/demos/toolbar.tcl:
	* library/demos/tree.tcl:
	* library/demos/ttknote.tcl:
	* library/demos/ttkprogress.tcl:
	* library/demos/widget:
@
text
@d6 1
a6 1
# RCS: @@(#) $Id: tree.tcl,v 1.1 2007/10/22 14:21:11 dkf Exp $
d23 1
a23 1
ttk::label $w.msg -font $font -wraplength 4i -justify left -anchor n -text "Ttk is the new Tk themed widget set. One of the widgets it includes is a tree widget, which allows the user to browse a hierarchical data-set such as a filesystem. The tree widget not only allows for the tree part itself, but it also supports an arbitrary number of additional columns which can show additional data (in this case, the size of the files found in your filesystem). You can also change the width of the columns by dragging the boundary between them."
@


1.2.2.1
log
@file tree.tcl was added on branch core-stabilizer-branch on 2007-10-24 12:59:33 +0000
@
text
@d1 96
@


1.2.2.2
log
@merge updates from HEAD
@
text
@a0 96
# tree.tcl --
#
# This demonstration script creates a toplevel window containing a Ttk
# tree widget.
#
# RCS: @@(#) $Id: tree.tcl,v 1.2 2007/10/23 06:31:16 das Exp $

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require Tk
package require Ttk

set w .tree
catch {destroy $w}
toplevel $w
wm title $w "Directory Browser"
wm iconname $w "tree"
positionWindow $w

## Explanatory text
ttk::label $w.msg -font $font -wraplength 4i -justify left -anchor n -text "Ttk is the new Tk themed widget set. One of the widgets it includes is a tree widget, which allows the user to browse a hierarchical data-set such as a filesystem. The tree widget not only allows for the tree part itself, but it also supports an arbitrary number of additional columns which can show additional data (in this case, the size of the files found in your filesystem). You can also change the width of the columns by dragging the boundary between them."
pack $w.msg -fill x

## See Code / Dismiss
pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x

## Code to populate the roots of the tree (can be more than one on Windows)
proc populateRoots {tree} {
    foreach dir [lsort -dictionary [file volumes]] {
	populateTree $tree [$tree insert {} end -text $dir \
		-values [list $dir directory]]
    }
}

## Code to populate a node of the tree
proc populateTree {tree node} {
    if {[$tree set $node type] ne "directory"} {
	return
    }
    set path [$tree set $node fullpath]
    $tree delete [$tree children $node]
    foreach f [lsort -dictionary [glob -nocomplain -dir $path *]] {
	set type [file type $f]
	set id [$tree insert $node end -text [file tail $f] \
		-values [list $f $type]]

	if {$type eq "directory"} {
	    ## Make it so that this node is openable
	    $tree insert $id 0 -text dummy ;# a dummy
	    $tree item $id -text [file tail $f]/

	} elseif {$type eq "file"} {
	    set size [file size $f]
	    ## Format the file size nicely
	    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"
	    }
	    $tree set $id size $size
	}
    }

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

## Create the tree and set it up
ttk::treeview $w.tree -columns {fullpath type size} -displaycolumns {size} \
	-yscroll "$w.vsb set" -xscroll "$w.hsb set"
if {[tk windowingsystem] ne "aqua"} {
    ttk::scrollbar $w.vsb -orient vertical -command "$w.tree yview"
    ttk::scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
} else {
    scrollbar $w.vsb -orient vertical -command "$w.tree yview"
    scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
}
$w.tree heading \#0 -text "Directory Structure"
$w.tree heading size -text "File Size"
$w.tree column size -stretch 0 -width 70
populateRoots $w.tree
bind $w.tree <<TreeviewOpen>> {populateTree %W [%W focus]}

## Arrange the tree and its scrollbars in the toplevel
lower [ttk::frame $w.dummy]
pack $w.dummy -fill both -expand 1
grid $w.tree $w.vsb -sticky nsew -in $w.dummy
grid $w.hsb -sticky nsew -in $w.dummy
grid columnconfigure $w.dummy 0 -weight 1
grid rowconfigure $w.dummy 0 -weight 1
@


1.2.2.3
log
@merge updates from HEAD
@
text
@d6 1
a6 1
# RCS: @@(#) $Id: tree.tcl,v 1.2.2.2 2007/10/24 12:59:33 dgp Exp $
d23 1
a23 1
ttk::label $w.msg -font $font -wraplength 4i -justify left -anchor n -padding {10 2 10 6} -text "Ttk is the new Tk themed widget set. One of the widgets it includes is a tree widget, which allows the user to browse a hierarchical data-set such as a filesystem. The tree widget not only allows for the tree part itself, but it also supports an arbitrary number of additional columns which can show additional data (in this case, the size of the files found in your filesystem). You can also change the width of the columns by dragging the boundary between them."
@


1.1
log
@More widget demos!
@
text
@d6 1
a6 1
# RCS: @@(#) $Id$
d24 1
a24 1
pack $w.msg
d77 7
a83 2
ttk::scrollbar $w.vsb -orient vertical -command "$w.tree yview"
ttk::scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
@

