OSDN Git Service

Add hostdepend/X86MAC64
[eos/hostdependX86LINUX64.git] / hostdepend / X86MAC64 / util / X86MAC64 / lib / tk8.5 / demos / mclist.tcl
1 # mclist.tcl --
2 #
3 # This demonstration script creates a toplevel window containing a Ttk
4 # tree widget configured as a multi-column listbox.
5 #
6 # RCS: @(#) $Id: mclist.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp $
7
8 if {![info exists widgetDemo]} {
9     error "This script should be run from the \"widget\" demo."
10 }
11
12 package require Tk
13 package require Ttk
14
15 set w .mclist
16 catch {destroy $w}
17 toplevel $w
18 wm title $w "Multi-Column List"
19 wm iconname $w "mclist"
20 positionWindow $w
21
22 ## Explanatory text
23 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 can be configured to display multiple columns of informational data without displaying the tree itself. This is a simple way to build a listbox that has multiple columns. Clicking on the heading for a column will sort the data by that column. You can also change the width of the columns by dragging the boundary between them."
24 pack $w.msg -fill x
25
26 ## See Code / Dismiss
27 pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x
28
29 ttk::frame $w.container
30 ttk::treeview $w.tree -columns {country capital currency} -show headings \
31     -yscroll "$w.vsb set" -xscroll "$w.hsb set"
32 if {[tk windowingsystem] ne "aqua"} {
33     ttk::scrollbar $w.vsb -orient vertical -command "$w.tree yview"
34     ttk::scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
35 } else {
36     scrollbar $w.vsb -orient vertical -command "$w.tree yview"
37     scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
38 }
39 pack $w.container -fill both -expand 1
40 grid $w.tree $w.vsb -in $w.container -sticky nsew
41 grid $w.hsb         -in $w.container -sticky nsew
42 grid column $w.container 0 -weight 1
43 grid row    $w.container 0 -weight 1
44
45 ## The data we're going to insert
46 set data {
47     Argentina           {Buenos Aires}          ARS
48     Australia           Canberra                AUD
49     Brazil              Brazilia                BRL
50     Canada              Ottawa                  CAD
51     China               Beijing                 CNY
52     France              Paris                   EUR
53     Germany             Berlin                  EUR
54     India               {New Delhi}             INR
55     Italy               Rome                    EUR
56     Japan               Tokyo                   JPY
57     Mexico              {Mexico City}           MXN
58     Russia              Moscow                  RUB
59     {South Africa}      Pretoria                ZAR
60     {United Kingdom}    London                  GBP
61     {United States}     {Washington, D.C.}      USD
62 }
63
64 ## Code to insert the data nicely
65 set font [ttk::style lookup [$w.tree cget -style] -font]
66 foreach col {country capital currency} name {Country Capital Currency} {
67     $w.tree heading $col -command [list SortBy $w.tree $col 0] -text $name
68     $w.tree column $col -width [font measure $font $name]
69 }
70 foreach {country capital currency} $data {
71     $w.tree insert {} end -values [list $country $capital $currency]
72     foreach col {country capital currency} {
73         set len [font measure $font "[set $col]  "]
74         if {[$w.tree column $col -width] < $len} {
75             $w.tree column $col -width $len
76         }
77     }
78 }
79
80 ## Code to do the sorting of the tree contents when clicked on
81 proc SortBy {tree col direction} {
82     # Build something we can sort
83     set data {}
84     foreach row [$tree children {}] {
85         lappend data [list [$tree set $row $col] $row]
86     }
87
88     set dir [expr {$direction ? "-decreasing" : "-increasing"}]
89     set r -1
90
91     # Now reshuffle the rows into the sorted order
92     foreach info [lsort -dictionary -index 0 $dir $data] {
93         $tree move [lindex $info 1] {} [incr r]
94     }
95
96     # Switch the heading so that it will sort in the opposite direction
97     $tree heading $col -command [list SortBy $tree $col [expr {!$direction}]]
98 }