tk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/MANUAL_tcltklib.eng +0 -2
- data/MANUAL_tcltklib.ja +0 -2
- data/README.ActiveTcl +1 -1
- data/README.md +43 -0
- data/ext/tk/extconf.rb +4 -2
- data/ext/tk/old-extconf.rb +0 -1
- data/ext/tk/tcltklib.c +46 -148
- data/ext/tk/tkutil/extconf.rb +0 -2
- data/ext/tk/tkutil/tkutil.c +6 -9
- data/lib/multi-tk.rb +95 -315
- data/lib/remote-tk.rb +6 -23
- data/lib/tk.rb +41 -122
- data/lib/tk/bgerror.rb +2 -2
- data/lib/tk/bindtag.rb +1 -1
- data/lib/tk/canvas.rb +6 -14
- data/lib/tk/canvastag.rb +8 -16
- data/lib/tk/font.rb +1 -1
- data/lib/tk/fontchooser.rb +1 -1
- data/lib/tk/image.rb +1 -1
- data/lib/tk/menu.rb +4 -4
- data/lib/tk/msgcat.rb +5 -5
- data/lib/tk/namespace.rb +12 -32
- data/lib/tk/optiondb.rb +3 -73
- data/lib/tk/scale.rb +2 -2
- data/lib/tk/scrollable.rb +4 -2
- data/lib/tk/selection.rb +5 -4
- data/lib/tk/text.rb +8 -16
- data/lib/tk/textmark.rb +1 -1
- data/lib/tk/texttag.rb +7 -15
- data/lib/tk/timer.rb +2 -2
- data/lib/tk/tk_mac.rb +18 -18
- data/lib/tk/validation.rb +4 -35
- data/lib/tk/variable.rb +7 -5
- data/lib/tk/virtevent.rb +1 -1
- data/lib/tkextlib/blt/barchart.rb +0 -17
- data/lib/tkextlib/blt/bitmap.rb +1 -1
- data/lib/tkextlib/blt/component.rb +34 -34
- data/lib/tkextlib/blt/dragdrop.rb +6 -6
- data/lib/tkextlib/blt/graph.rb +0 -17
- data/lib/tkextlib/blt/stripchart.rb +0 -17
- data/lib/tkextlib/blt/tabset.rb +16 -31
- data/lib/tkextlib/blt/tree.rb +5 -5
- data/lib/tkextlib/blt/treeview.rb +14 -14
- data/lib/tkextlib/blt/watch.rb +1 -1
- data/lib/tkextlib/bwidget/labelentry.rb +6 -14
- data/lib/tkextlib/bwidget/listbox.rb +13 -29
- data/lib/tkextlib/bwidget/notebook.rb +6 -14
- data/lib/tkextlib/bwidget/spinbox.rb +6 -14
- data/lib/tkextlib/bwidget/tree.rb +19 -35
- data/lib/tkextlib/itcl/incr_tcl.rb +2 -2
- data/lib/tkextlib/itk/incr_tk.rb +7 -29
- data/lib/tkextlib/iwidgets/calendar.rb +0 -15
- data/lib/tkextlib/iwidgets/entryfield.rb +0 -21
- data/lib/tkextlib/iwidgets/notebook.rb +2 -2
- data/lib/tkextlib/iwidgets/scrolledcanvas.rb +6 -14
- data/lib/tkextlib/iwidgets/tabnotebook.rb +2 -2
- data/lib/tkextlib/tcllib/ctext.rb +2 -2
- data/lib/tkextlib/tcllib/plotchart.rb +5 -5
- data/lib/tkextlib/tcllib/validator.rb +6 -6
- data/lib/tkextlib/tile.rb +1 -1
- data/lib/tkextlib/tile/style.rb +1 -1
- data/lib/tkextlib/tile/treeview.rb +13 -20
- data/lib/tkextlib/tkDND/tkdnd.rb +6 -22
- data/lib/tkextlib/tkHTML/htmlwidget.rb +1 -1
- data/lib/tkextlib/tktable/tktable.rb +1 -1
- data/lib/tkextlib/treectrl/tktreectrl.rb +12 -20
- data/lib/tkextlib/vu/pie.rb +1 -1
- data/sample/binding_sample.rb +2 -2
- data/sample/cmd_res_test.rb +1 -1
- data/sample/demos-en/widget +21 -21
- data/sample/demos-jp/widget +4 -4
- data/sample/multi-ip_sample.rb +0 -3
- data/sample/multi-ip_sample2.rb +1 -1
- data/sample/resource.en +3 -3
- data/sample/resource.ja +3 -3
- data/sample/tcltklib/sample1.rb +2 -2
- data/sample/tkballoonhelp.rb +2 -2
- data/sample/tkextlib/tkHTML/ss.rb +0 -6
- data/sample/tkmulticolumnlist.rb +2 -2
- data/sample/tkmultilistframe.rb +2 -2
- data/sample/tkoptdb.rb +14 -16
- data/tk.gemspec +4 -4
- metadata +6 -13
- data/ChangeLog.tkextlib +0 -949
- data/old-README.tcltklib.ja +0 -159
- data/sample/binstr_usage.rb +0 -46
- data/sample/remote-ip_sample2.rb +0 -57
- data/sample/safe-tk.rb +0 -132
- data/sample/tkoptdb-safeTk.rb +0 -74
- data/sample/tktree.rb +0 -104
- data/sample/tktree.tcl +0 -305
data/sample/tktree.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
##########################################################################
|
3
|
-
# TkTree widget class
|
4
|
-
#
|
5
|
-
# see <http://wiki.tcl.tk/10615>
|
6
|
-
#
|
7
|
-
# Note: optional argument '-font' of the Tcl library is changed to
|
8
|
-
# 'itemfont' on this Ruby library, because of avoiding font
|
9
|
-
# operation trouble in 'initialize' method ( see the following
|
10
|
-
# test script ).
|
11
|
-
#
|
12
|
-
##########################################################################
|
13
|
-
require 'tk'
|
14
|
-
|
15
|
-
class TkTree < TkCanvas
|
16
|
-
TCL_SCRIPT_PATH = File.join(File.dirname(__FILE__), 'tktree.tcl')
|
17
|
-
|
18
|
-
def create_self(keys)
|
19
|
-
args = [@path]
|
20
|
-
if keys.kind_of?(Hash)
|
21
|
-
font = keys.delete('itemfont')
|
22
|
-
# font = hash_kv(font) if font.kind_of?(Hash)
|
23
|
-
keys['font'] = font if font
|
24
|
-
# args.concat(hash_kv(keys))
|
25
|
-
args << keys
|
26
|
-
end
|
27
|
-
begin
|
28
|
-
tk_call('::tktree::treecreate', *args)
|
29
|
-
rescue NameError, RuntimeError
|
30
|
-
Tk.load_tclscript(TkTree::TCL_SCRIPT_PATH)
|
31
|
-
tk_call('::tktree::treecreate', *args)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def newitem(itempath, keys = nil)
|
36
|
-
if keys.kind_of?(Hash)
|
37
|
-
keys = _symbolkey2str(keys)
|
38
|
-
font = keys.delete('itemfont')
|
39
|
-
# font = hash_kv(font) if font.kind_of?(Hash)
|
40
|
-
keys['font'] = font if font
|
41
|
-
# tk_call('::tktree::newitem', @path, itempath, *hash_kv(keys))
|
42
|
-
tk_call('::tktree::newitem', @path, itempath, keys)
|
43
|
-
else
|
44
|
-
tk_call('::tktree::newitem', @path, itempath)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def delitem(itempath)
|
49
|
-
tk_call('::tktree::delitem', @path, itempath)
|
50
|
-
end
|
51
|
-
|
52
|
-
def labelat(xpos, ypos)
|
53
|
-
tk_call('::tktree::delitem', @path, xpos, ypos)
|
54
|
-
end
|
55
|
-
|
56
|
-
def getselection
|
57
|
-
tk_call('::tktree::getselection', @path)
|
58
|
-
end
|
59
|
-
|
60
|
-
def setselection(itempath)
|
61
|
-
tk_call('::tktree::getselection', @path, itempath)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
##########################################################################
|
67
|
-
# test script
|
68
|
-
##########################################################################
|
69
|
-
if __FILE__ == $0
|
70
|
-
TkLabel.new(:text=><<EOL, :relief=>:ridge, :justify=>:left).pack
|
71
|
-
|
72
|
-
This is a sample to use a Tcl library script on Ruby/Tk.
|
73
|
-
This sample loads tktree.tcl (see <http://wiki.tcl.tk/10615>)
|
74
|
-
and calls functions of the Tcl script.
|
75
|
-
EOL
|
76
|
-
|
77
|
-
items = %w(/group1/item1 /group1/item2 /group1/subgroup/item1 /group2/item1 /item1)
|
78
|
-
|
79
|
-
tr1 = TkTree.new.pack(:expand=>true, :fill=>:both)
|
80
|
-
tr1.focus
|
81
|
-
|
82
|
-
items.each{|item|
|
83
|
-
tr1.newitem(item,
|
84
|
-
:command=>proc{Tk.messageBox(:message=>"#{item} executed")})
|
85
|
-
}
|
86
|
-
|
87
|
-
f = TkFrame.new.pack(:expand=>true, :fill=>:both)
|
88
|
-
tr2 = TkTree.new(f, :bg=>'black', #:itemfont=>{:family=>'Times', :size=>14},
|
89
|
-
:textcolor=>'red', :bd=>4, :relief=>:ridge,
|
90
|
-
:selectbackground=>'darkBlue', :selectforeground=>'yellow',
|
91
|
-
:selectborderwidth=>3, :linecolor=>'yellow') {
|
92
|
-
yscrollbar(TkScrollbar.new(f, :width=>10).pack(:side=>:right, :fill=>:y))
|
93
|
-
xscrollbar(TkScrollbar.new(f, :width=>10).pack(:side=>:bottom, :fill=>:x))
|
94
|
-
pack(:expand=>true, :fill=>:both)
|
95
|
-
}
|
96
|
-
|
97
|
-
items.each{|item|
|
98
|
-
tr2.newitem(item, :textcolor=>'green', :image=>'',
|
99
|
-
:itemfont=>{:family=>'Times', :size=>10},
|
100
|
-
:command=>proc{Tk.messageBox(:message=>"#{item} executed")})
|
101
|
-
}
|
102
|
-
|
103
|
-
Tk.mainloop
|
104
|
-
end
|
data/sample/tktree.tcl
DELETED
@@ -1,305 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# This Tcl/Tk script is quoted from <http://wiki.tcl.tk/10615>.
|
3
|
-
#
|
4
|
-
package require Tk
|
5
|
-
namespace eval ::tktree {
|
6
|
-
|
7
|
-
# Images used for open and close state of subgroups
|
8
|
-
set ::tktree::imgcollapse [image create photo .tktreeopenbm -data {
|
9
|
-
R0lGODdhCQAJAIAAAAEBAf///ywAAAAACQAJAAACEISPoRvG614D80x5ZXyogwIAOw==}]
|
10
|
-
set ::tktree::imgexpand [image create photo .tktreeclosebm -data {
|
11
|
-
R0lGODdhCQAJAIAAAAEBAf///ywAAAAACQAJAAACEYSPoRu28KCSDSJLc44s3lMAADs=}]
|
12
|
-
###Default images for groups and children
|
13
|
-
set ::tktree::imgsubgroups [image create photo .tktreeimgfolder -data {
|
14
|
-
R0lGODlhEAANAKIAANnZ2Xh4eLi4uPj4APj4+AAAAP///////yH5BAEAAAAA
|
15
|
-
LAAAAAAQAA0AAANkCIChiqDLITgyEgi6GoIjIyMYugCBpMsaWBA0giMjIzgy
|
16
|
-
UYBBMjIoIyODEgVBODIygiMjE1gQJIMyMjIoI1GAQSMjODIyghMFQSgjI4My
|
17
|
-
MhJYEDSCIyMjODJRgKHLXAiApcsMmAA7}]
|
18
|
-
set ::tktree::imgchildren [image create photo .tktreeimgfile -data {
|
19
|
-
R0lGODlhDQAQAKIAANnZ2Xh4ePj4+Li4uAAAAP///////////yH5BAEAAAAA
|
20
|
-
LAAAAAANABAAAANSGLoLgACBoqsRCBAoujqCASGDojtESCEihCREIjgUKLo8
|
21
|
-
hCGCpCsySIGiy0MYIki6IoMUKLo8hCGCpCsySIGiy0MYKLo8hIGiy0MYOLo8
|
22
|
-
SLrMCQA7}]
|
23
|
-
|
24
|
-
#### Swtich all subgroups of a layer to open or close
|
25
|
-
proc ::tktree::switchlayer {win opn {layer /}} {
|
26
|
-
variable cfg
|
27
|
-
foreach child $cfg($win,$layer:subgroups) {
|
28
|
-
set cfg($win,$child:open) $opn
|
29
|
-
switchlayer $win $opn $child
|
30
|
-
}
|
31
|
-
buildwhenidle $win
|
32
|
-
}
|
33
|
-
|
34
|
-
#### will open or close the item given
|
35
|
-
proc ::tktree::switchstate {win item} {
|
36
|
-
set ::tktree::cfg($win,$item:open) [expr ! $::tktree::cfg($win,$item:open)]
|
37
|
-
buildwhenidle $win
|
38
|
-
}
|
39
|
-
|
40
|
-
#### Select the next item up or down
|
41
|
-
proc ::tktree::updown {win down} {
|
42
|
-
variable cfg
|
43
|
-
set index [lsearch -exact $cfg($win,sortlist) $cfg($win,selection)]
|
44
|
-
if {$down} {incr index} {incr index -1}
|
45
|
-
if {$index < 0} {set index end} elseif {$index >= [llength $cfg($win,sortlist)]} {set index 0}
|
46
|
-
setselection $win [lindex $cfg($win,sortlist) $index]
|
47
|
-
}
|
48
|
-
|
49
|
-
#### left-right button binding commands
|
50
|
-
proc ::tktree::leftright {win right} {
|
51
|
-
variable cfg
|
52
|
-
set item $cfg($win,selection)
|
53
|
-
set index [lsearch -exact $cfg($win,sortlist) $item]
|
54
|
-
set parentindex [lsearch -exact $cfg($win,sortlist) [file dirname $item]]
|
55
|
-
if {$parentindex == -1} {set parentindex [expr $index - 1]}
|
56
|
-
if {$cfg($win,$item:group)} {
|
57
|
-
if {$right} {
|
58
|
-
if {$cfg($win,$item:open)} {incr index} {set cfg($win,$item:open) 1}
|
59
|
-
} else {
|
60
|
-
if {$cfg($win,$item:open)} {set cfg($win,$item:open) 0} {set index $parentindex}
|
61
|
-
}
|
62
|
-
} else {
|
63
|
-
if {$right} {incr index} {set index $parentindex}
|
64
|
-
}
|
65
|
-
if {$index < 0} {set index end} elseif {$index >= [llength $cfg($win,sortlist)]} {set index 0}
|
66
|
-
setselection $win [lindex $cfg($win,sortlist) $index]
|
67
|
-
buildwhenidle $win
|
68
|
-
}
|
69
|
-
|
70
|
-
#### will return the pathname of the item at x and y cooridinates
|
71
|
-
proc ::tktree::labelat {win x y} {
|
72
|
-
set x [$win canvasx $x]; set y [$win canvasy $y]
|
73
|
-
foreach m [$win find overlapping $x $y $x $y] {
|
74
|
-
if {[info exists ::tktree::cfg($win,tag:$m)]} {return $::tktree::cfg($win,tag:$m)}
|
75
|
-
}
|
76
|
-
return ""
|
77
|
-
}
|
78
|
-
|
79
|
-
#### will return the path of the current selection in the given tree widget
|
80
|
-
proc ::tktree::getselection {win} {
|
81
|
-
return $::tktree::cfg($win,selection)
|
82
|
-
}
|
83
|
-
|
84
|
-
#### adjust the scrollview to show the selected item as needed
|
85
|
-
proc ::tktree::scrolladjust {win tag} {
|
86
|
-
update
|
87
|
-
set item [$win bbox $tag]
|
88
|
-
set region [$win cget -scrollregion]
|
89
|
-
foreach {axis idx1 idx2} {yview 1 3 xview 0 2} {
|
90
|
-
set range [expr abs([lindex $region $idx2]) - abs([lindex $region $idx1])]
|
91
|
-
set itemtop [lindex $item $idx1]; set itembot [lindex $item $idx2]
|
92
|
-
set viewtop [expr $range * [lindex [$win $axis] 0]]
|
93
|
-
set viewbot [expr $range * [lindex [$win $axis] 1]]
|
94
|
-
if {$itembot > $viewbot} {$win $axis moveto [expr ($itembot. - $viewbot + $viewtop) / $range]}
|
95
|
-
if {$itemtop < $viewtop} {$win $axis moveto [expr $itemtop. / $range]}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
#### will set the current selection to the given item on the given tree
|
100
|
-
proc ::tktree::setselection {win item} {
|
101
|
-
variable cfg
|
102
|
-
if {![llength $cfg($win,sortlist)]} {return}
|
103
|
-
if {$item eq ""} {set item [lindex $cfg($win,sortlist) 0]}
|
104
|
-
if {![info exists cfg($win,$item:tag)]} {set item [lindex $cfg($win,sortlist) 0]}
|
105
|
-
if {[$win gettags $cfg($win,$item:tag)] ne ""} {
|
106
|
-
$win select from $cfg($win,$item:tag) 0
|
107
|
-
$win select to $cfg($win,$item:tag) end
|
108
|
-
set cfg($win,selection) $item
|
109
|
-
scrolladjust $win $cfg($win,$item:tag)
|
110
|
-
} {
|
111
|
-
setselection $win "/[lindex $cfg($win,/:sortlist) 0]"
|
112
|
-
}
|
113
|
-
}
|
114
|
-
|
115
|
-
#### will delete the item given from the tree given
|
116
|
-
proc ::tktree::delitem {win item} {
|
117
|
-
variable cfg
|
118
|
-
if {$item eq "/"} {
|
119
|
-
array unset cfg $win,* ; catch {destroy $win}
|
120
|
-
} {
|
121
|
-
set group [file dirname $item]
|
122
|
-
if {$cfg($win,$item:group)} {set type subgroups} {set type children}
|
123
|
-
set index [lsearch -exact $cfg($win,$group:$type) $item]
|
124
|
-
set cfg($win,$group:$type) [lreplace $cfg($win,$group:$type) $index $index]
|
125
|
-
array unset cfg $win,$item*
|
126
|
-
buildwhenidle $win
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
#### create a new item in the tree and rebuild the widget
|
131
|
-
proc ::tktree::newitem {win item args} {
|
132
|
-
variable cfg
|
133
|
-
if {[string index $item 0] ne "/"} {set item /$item}
|
134
|
-
if {[string index $item end] eq "/"} {
|
135
|
-
set subgroup 1
|
136
|
-
set type subgroups
|
137
|
-
set item [string range $item 0 end-1]
|
138
|
-
set cfg($win,$item:command) [list ::tktree::switchstate $win $item]
|
139
|
-
} {
|
140
|
-
set subgroup 0
|
141
|
-
set type children
|
142
|
-
set cfg($win,$item:command) {}
|
143
|
-
}
|
144
|
-
#Build parent group if needed
|
145
|
-
set group [file dirname $item]
|
146
|
-
if {![info exists cfg($win,$group:open)]} {newitem $win "$group\/"}
|
147
|
-
lappend cfg($win,$group:$type) $item
|
148
|
-
#Configure the new item
|
149
|
-
set cfg($win,$item:group) $subgroup
|
150
|
-
set cfg($win,$item:subgroups) {}
|
151
|
-
set cfg($win,$item:children) {}
|
152
|
-
set cfg($win,$item:sortlist) {}
|
153
|
-
set cfg($win,$item:tags) {}
|
154
|
-
set cfg($win,$item:open) 0
|
155
|
-
set cfg($win,$item:image) {}
|
156
|
-
set cfg($win,$item:textcolor) $cfg($win,textcolor)
|
157
|
-
set cfg($win,$item:font) $cfg($win,font)
|
158
|
-
if {$cfg($win,images)} {set cfg($win,$item:image) [eval list \$::tktree::img$type]}
|
159
|
-
foreach {confitem confval} $args {
|
160
|
-
switch -exact -- $confitem {
|
161
|
-
-textcolor {set cfg($win,$item:textcolor) $confval}
|
162
|
-
-command {set cfg($win,$item:command) $confval}
|
163
|
-
-image {set cfg($win,$item:image) $confval}
|
164
|
-
-font {set cfg($win,$item:font) $confval}
|
165
|
-
}
|
166
|
-
}
|
167
|
-
buildwhenidle $win
|
168
|
-
}
|
169
|
-
|
170
|
-
#### Draw the given layer of the tree on the canvas starting at xposition
|
171
|
-
proc ::tktree::buildlayer {win layer xpos} {
|
172
|
-
variable cfg
|
173
|
-
#Record y positions for vertical line later on
|
174
|
-
set ystart $cfg($win,y); set yend $cfg($win,y)
|
175
|
-
if {$layer eq "/"} {set cfg($win,sortlist) ""}
|
176
|
-
foreach child $cfg($win,$layer:sortlist) {
|
177
|
-
lappend cfg($win,sortlist) $child
|
178
|
-
#Check spacing required for images
|
179
|
-
set imgwidth 0; set imgheight 0
|
180
|
-
if {[string length $cfg($win,$child:image)]} {
|
181
|
-
set imgwidth [expr ([image width $cfg($win,$child:image)] + 2) / 2]
|
182
|
-
set imgheight [expr ([image height $cfg($win,$child:image)] + 2) / 2]
|
183
|
-
}
|
184
|
-
#find X-axis points for image, horiz line, and text
|
185
|
-
if {$imgwidth} {
|
186
|
-
set centerX [expr $imgwidth + $xpos + 7]
|
187
|
-
set rightX [expr $xpos + 7]
|
188
|
-
set textX [expr ($imgwidth * 2) + $xpos + 10]
|
189
|
-
} {
|
190
|
-
set centerX [expr $xpos + 10]
|
191
|
-
set rightX [expr $centerX + 4]
|
192
|
-
set textX [expr $rightX + 1]
|
193
|
-
}
|
194
|
-
#Find the proper amount to increment the y axis
|
195
|
-
set fontheight [lindex [font metrics $cfg($win,$child:font)] 5]
|
196
|
-
set yincr [expr ($fontheight + 1) / 2]
|
197
|
-
if {$imgheight > $yincr} {set yincr $imgheight}
|
198
|
-
incr cfg($win,y) $yincr
|
199
|
-
#Draw the horizonal line
|
200
|
-
$win create line $xpos $cfg($win,y) $rightX $cfg($win,y) -fill $cfg($win,linecolor)
|
201
|
-
set yend $cfg($win,y)
|
202
|
-
#Draw the image, if it exists
|
203
|
-
if {$imgwidth} {
|
204
|
-
set it [$win create image $centerX $cfg($win,y) -image $cfg($win,$child:image)]
|
205
|
-
$win bind $it <1> [list ::tktree::setselection $win $child]
|
206
|
-
}
|
207
|
-
#Draw text and store tags for reference
|
208
|
-
set cfg($win,$child:tag) [$win create text $textX $cfg($win,y) \
|
209
|
-
-text [file tail $child] -font $cfg($win,$child:font) -anchor w -tags x -fill $cfg($win,$child:textcolor)]
|
210
|
-
set cfg($win,tag:$cfg($win,$child:tag)) $child
|
211
|
-
#Command binding
|
212
|
-
$win bind $cfg($win,$child:tag) <1> [list ::tktree::setselection $win $child]
|
213
|
-
$win bind $cfg($win,$child:tag) <Double-1> $cfg($win,$child:command)
|
214
|
-
#next step up on the y axis
|
215
|
-
incr cfg($win,y) $yincr
|
216
|
-
#If its a group, add open-close functionality
|
217
|
-
if {$cfg($win,$child:group)} {
|
218
|
-
if {$cfg($win,$child:open)} {set img collapse} {set img expand}
|
219
|
-
set ocimg [$win create image $xpos [expr $cfg($win,y) - $yincr] -image [eval list \$::tktree::img$img]]
|
220
|
-
$win bind $ocimg <1> [list ::tktree::switchstate $win $child]
|
221
|
-
if {$cfg($win,$child:open)} {buildlayer $win $child $centerX}
|
222
|
-
}
|
223
|
-
}
|
224
|
-
#Vertical line
|
225
|
-
$win lower [$win create line $xpos [expr $ystart - 7] $xpos $yend -fill $cfg($win,linecolor)]
|
226
|
-
}
|
227
|
-
|
228
|
-
#### sort the layer by subgroups then children
|
229
|
-
proc ::tktree::sortlayer {win {layer /}} {
|
230
|
-
variable cfg
|
231
|
-
set cfg($win,$layer:subgroups) [lsort -dictionary $cfg($win,$layer:subgroups)]
|
232
|
-
set cfg($win,$layer:children) [lsort -dictionary $cfg($win,$layer:children)]
|
233
|
-
set cfg($win,$layer:sortlist) [join [list $cfg($win,$layer:subgroups) $cfg($win,$layer:children)]]
|
234
|
-
foreach group $cfg($win,$layer:subgroups) {sortlayer $win $group}
|
235
|
-
}
|
236
|
-
|
237
|
-
#### build the tree at the given path
|
238
|
-
proc ::tktree::buildtree {win} {
|
239
|
-
variable cfg
|
240
|
-
$win delete all
|
241
|
-
sortlayer $win
|
242
|
-
set xpos 5
|
243
|
-
set cfg($win,y) 5
|
244
|
-
#Draw global expand/contract button, if needed
|
245
|
-
if {[string length $cfg($win,/:subgroups)] && $cfg($win,expandall)} {
|
246
|
-
set exp 0
|
247
|
-
foreach subgroup $cfg($win,/:subgroups) {incr exp $cfg($win,$subgroup:open)}
|
248
|
-
if {$exp} {set type collapse} {set type expand}
|
249
|
-
set ocimg [$win create image 1 1 -image [eval list \$::tktree::img$type] -anchor w]
|
250
|
-
$win bind $ocimg <1> [list ::tktree::switchlayer $win [expr ! $exp]]
|
251
|
-
}
|
252
|
-
#Build the layers and set initial selection
|
253
|
-
buildlayer $win / $xpos
|
254
|
-
$win config -scrollregion [$win bbox all]
|
255
|
-
setselection $win $cfg($win,selection)
|
256
|
-
}
|
257
|
-
|
258
|
-
#### internal use - set up a handle to build the tree when everything is idle
|
259
|
-
proc ::tktree::buildwhenidle {win} {
|
260
|
-
catch {after cancel $::tktree::cfg($win,buildHandle)}
|
261
|
-
set ::tktree::cfg($win,buildHandle) [after idle [list ::tktree::buildtree $win]]
|
262
|
-
}
|
263
|
-
|
264
|
-
#### will create a new tree widget at the given path
|
265
|
-
proc ::tktree::treecreate {win args} {
|
266
|
-
variable cfg
|
267
|
-
#Default configuration for new tree
|
268
|
-
set cfg($win,selection) {}
|
269
|
-
set cfg($win,selidx) {}
|
270
|
-
set cfg($win,/:subgroups) {}
|
271
|
-
set cfg($win,/:children) {}
|
272
|
-
set cfg($win,/:open) 1
|
273
|
-
set cfg($win,images) 1
|
274
|
-
set cfg($win,expandall) 1
|
275
|
-
set cfg($win,linecolor) black
|
276
|
-
set cfg($win,textcolor) black
|
277
|
-
set cfg($win,font) {-family Helvetica -size 10}
|
278
|
-
#Parse and setup custom configuration options
|
279
|
-
set canvascfg ""
|
280
|
-
foreach {item val} $args {
|
281
|
-
switch -- $item {
|
282
|
-
-linecolor {set cfg($win,linecolor) $val}
|
283
|
-
-textcolor {set cfg($win,textcolor) $val}
|
284
|
-
-font {set cfg($win,font) $val}
|
285
|
-
-images {set cfg($win,images) $val}
|
286
|
-
-expandall {set cfg($win,expandall) $val}
|
287
|
-
default {lappend canvascfg $item $val}
|
288
|
-
}
|
289
|
-
}
|
290
|
-
#Build the canvas
|
291
|
-
eval {canvas $win -takefocus 1} $canvascfg
|
292
|
-
bind $win <Destroy> [list ::tktree::delitem $win /]
|
293
|
-
bind $win <1> [list focus $win]
|
294
|
-
bind $win <Return> {eval $::tktree::cfg(%W,[::tktree::getselection %W]:command)}
|
295
|
-
bind $win <space> {eval $::tktree::cfg(%W,[::tktree::getselection %W]:command)}
|
296
|
-
bind $win <Up> [list ::tktree::updown $win 0]
|
297
|
-
bind $win <Down> [list ::tktree::updown $win 1]
|
298
|
-
bind $win <Left> [list ::tktree::leftright $win 0]
|
299
|
-
bind $win <Right> [list ::tktree::leftright $win 1]
|
300
|
-
|
301
|
-
#Build the tree when idle
|
302
|
-
buildwhenidle $win
|
303
|
-
}
|
304
|
-
}
|
305
|
-
|