namespace eval DemoIMovie {}
treectrl .t -height 900 -width 900pack .tset ScriptDir [file normalize [file dirname [info script]]]set ::thisPlatform unixproc Path {args} { return [file normalize [eval [list file join $::ScriptDir] $args]]}proc DemoIMovie::Button1 {T x y} { focus $T set id [$T identify $x $y]# Click outside any item
if {$id eq ""} {# Click in header
} elseif {[lindex $id 0] eq "header"} { ::TreeCtrl::ButtonPress1 $T $x $y# Click in item
} elseif {[lindex $id 0] eq "item"} { ::TreeCtrl::ButtonPress1 $T $x $y update lassign $id where item arg1 arg2 arg3 arg4 switch $arg1 { column { set I [lindex $id 1] if {[llength $id] == 6} { set E [lindex $id end] if {$E eq "elemName"} { set exists [winfo exists $T.entry] ::TreeCtrl::EntryOpen $T $I C0 $E if {!$exists} { $T.entry configure -borderwidth 0 -justify center \ -background #ffdc5a scan [$T item bbox $I C0 $E] "%d %d %d %d" x1 y1 x2 y2 place $T.entry -y [expr {$y1 - 1}] } $T.entry selection clear scan [$T item bbox $I C0 elemImg] "%d %d %d %d" x1 y1 x2 y2 set left $x1 set right $x2 place $T.entry -x $left -width [expr {$right - $left}] $T.entry icursor [$T.entry index @[expr {$x - ($x1 + 1)}]] # Disable mouse tracking unset ::TreeCtrl::Priv(buttonMode) } } } } } return -code break}proc InitPics {args} { foreach pattern $args { if {[lsearch [image names] $pattern] == -1} { foreach file [glob -directory [Path pics] $pattern.gif] { set imageName [file root [file tail $file]] # I created an image called "file", which clobbered the # original Tcl command "file". Then I got confused. if {[llength [info commands $imageName]]} { error "don't want to create image called \"$imageName\"" } image create photo $imageName -file $file
# Hack -- Create a "selected" version too
image create photo ${imageName}Sel ${imageName}Sel copy $imageName # imagetint ${imageName}Sel $::SystemHighlight 128 } } } return}
.t configure -showroot no -showbuttons no -showlines no \
-selectmode browse -orient horizontal -wrap window \-showheader no -background #dcdcdc -yscrollsmoothing yes.t configure -canvaspadx 8 -canvaspady 8 \
-itemgapx 8 -itemgapy 8.t column create -tags C0
InitPics imovie-*
set font1 {Helvetica 12}
set font2 {Helvetica 14}.t element create elemTime text -font [list $font1]
.t element create elemName text -font [list $font2] -lines 1 -width 80.t element create elemRect rect -fill {#ffdc5a {selected} white {}} \ -outline #827878 -outlinewidth 1.t element create elemImg image.t element create elemShadow rect -outline gray -outlinewidth 1 -open wn set S [.t style create STYLE -orient vertical].t style elements $S {elemShadow elemRect elemTime elemImg elemName}.t style layout $S elemShadow -detach yes -padx {1 0} -pady {1 0} -iexpand xy.t style layout $S elemTime -padx {2 0}.t style layout $S elemImg -pady {0 1}.t style layout $S elemName -expand we -ipady {0 2} -padx {0 3} -squeeze x.t style layout $S elemRect -union {elemTime elemImg elemName} \ -ipadx 6 -padx {0 1} -pady {0 1}# Set default item style
.t column configure C0 -itemstyle $S bind DemoIMovie <ButtonPress-1> { DemoIMovie::Button1 %W %x %y }for {set i 0} {$i < 5} {incr i} {
foreach {time name image} { 15:20 "Clip 1" imovie-01 19:18 "Clip 2" imovie-02 07:20 "Clip 3" imovie-03 07:20 "Clip 4" imovie-04 07:20 "Clip 5" imovie-05 07:20 "Clip 6" imovie-06 07:20 "Clip 7" imovie-07 } { set I [.t item create] # $T item style set $I C0 $S .t item element configure $I C0 \ elemTime -text $time + \ elemImg -image $image + \ elemName -text $name .t item lastchild root $I } } bindtags .t [list .t DemoIMovie TreeCtrl [winfo toplevel .t] all]