博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
treectrl
阅读量:5326 次
发布时间:2019-06-14

本文共 3692 字,大约阅读时间需要 12 分钟。

namespace eval DemoIMovie {}

treectrl .t  -height 900 -width 900
pack .t
set ScriptDir [file normalize [file dirname [info script]]]
set ::thisPlatform unix
proc 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]

 

转载于:https://www.cnblogs.com/greencolor/archive/2011/09/18/2180684.html

你可能感兴趣的文章
练习10-1 使用递归函数计算1到n之和(10 分
查看>>
Oracle MySQL yaSSL 不明细节缓冲区溢出漏洞2
查看>>
windows编程ASCII问题
查看>>
.net webService代理类
查看>>
Code Snippet
查看>>
Node.js Express项目搭建
查看>>
zoj 1232 Adventure of Super Mario
查看>>
Oracle 序列的应用
查看>>
1201 网页基础--JavaScript(DOM)
查看>>
组合数学 UVa 11538 Chess Queen
查看>>
oracle job
查看>>
Redis常用命令
查看>>
XML学习笔记(二)-- DTD格式规范
查看>>
IOS开发学习笔记026-UITableView的使用
查看>>
[转载]电脑小绝技
查看>>
windos系统定时执行批处理文件(bat文件)
查看>>
thinkphp如何实现伪静态
查看>>
BZOJ 2243: [SDOI2011]染色( 树链剖分 )
查看>>
BZOJ 1925: [Sdoi2010]地精部落( dp )
查看>>
c++中的string常用函数用法总结!
查看>>