1 # vim: foldmarker=<<<,>>>
3 proc tlc::tools {pathName args} {
4 uplevel tlc::Tools $pathName $args
9 inherit tlc::Border tlc::Tooltips tlc::Baselog
14 itk_option define -orient orient Text "h" need_repack
15 itk_option define -midslot midSlot Integer 20 need_repack
16 itk_option define -gap gap Integer 4 need_repack
17 itk_option define -buttonwidth buttonWidth Integer 7
18 if {$::tcl_platform(platform) == "windows"} {
19 itk_option define -padx padX PadX 10
20 itk_option define -pady padY PadY 2
22 itk_option define -padx padX PadX 3m
23 itk_option define -pady padY PadY 2
27 variable type "text"; # or "bitmap", "image"
30 method add {name cmd {side "left"} args}
32 method attach_signal {name signal {sense normal}}
33 method item_focus {name}
35 method toggle_ref {name}
36 method separator {{side left} args}
46 method getcell {slotnum}
48 method tableadd {path myslot}
54 configbody tlc::Tools::buttonwidth { #<<<1
56 foreach c [winfo children $w] {
57 $c configure -width $itk_option(-buttonwidth)
62 body tlc::Tools::constructor {args} { #<<<1
68 eval itk_initialize $args
72 body tlc::Tools::destructor {} { #<<<1
74 after cancel $repack_id; set repack_id ""
78 body tlc::Tools::add {name cmd {side "left"} args} { #<<<1
81 left - right - top - bottom {}
83 error "Unknown side specification: ($side)"
87 set padd [string tolower $name]
88 set padd [string map {" " "_" "." "_"} $padd]
89 set padd [string trim $padd]
92 if {[winfo exists $path]} {
93 error "pathname $path already exists"
96 set myslot [incr slot]
100 incr myslot $itk_option(-midslot)
104 set pathmap($name) $path
105 set slotmap($path) $myslot
107 set toggle {-state {disabled normal}}
108 log debug "Adding type $type \"$name\" as $path"
111 eval [list button $path -text $name -command $cmd \
112 -width $itk_option(-buttonwidth) \
113 -padx $itk_option(-padx) -pady $itk_option(-pady)] $args
117 eval [list button $path -bitmap $name -command $cmd \
118 -width $itk_option(-buttonwidth)] $args
122 eval [list button $path -image $name -command $cmd \
123 -width $itk_option(-buttonwidth)] $args
127 error "Unknown type: ($type)"
130 eval [list tlc::StateToggle #auto toggles($name) $path] $toggle
131 $toggles($name) configure -default 1 -debugmode $debug
132 tableadd $path $myslot
139 body tlc::Tools::tableadd {path myslot} { #<<<1
141 if {$myslot < $itk_option(-midslot)} {
149 set padx [list 0 $itk_option(-gap)]
153 set padx [list $itk_option(-gap) 0]
157 switch $itk_option(-orient) {
161 blt::table configure $w c$myslot -resize none
162 blt::table configure $w r$myslot -resize both
168 blt::table configure $w r$myslot -resize none
169 blt::table configure $w c$myslot -resize both
173 blt::table $w $path [getcell $myslot] -$pad_type $padx -fill $fill_type
177 body tlc::Tools::path {name} { #<<<1
179 if {![info exists pathmap($name)]} {
180 error "No button called ($name), choose from ([array names pathmap])"
182 return $pathmap($name)
186 body tlc::Tools::getcell {slotnum} { #<<<1
188 switch $itk_option(-orient) {
200 body tlc::Tools::repack {} { #<<<1
202 after cancel $repack_id; set repack_id ""
203 foreach c [winfo children $w] {
204 tableadd $c $slotmap($c)
206 if {$itk_option(-orient) == "h"} {
207 blt::table configure $w c$itk_option(-midslot) -resize both
208 blt::table configure $w r$itk_option(-midslot) -resize none
210 blt::table configure $w r$itk_option(-midslot) -resize both
211 blt::table configure $w c$itk_option(-midslot) -resize none
216 body tlc::Tools::attach_signal {name signal {sense normal}} { #<<<1
218 $toggles($name) attach_signal $signal $sense
222 body tlc::Tools::need_repack {} { #<<<1
224 if {$repack_id != ""} return
226 set repack_id [after idle [code $this repack]]
230 body tlc::Tools::item_focus {name} { #<<<1
236 body tlc::Tools::explain {name} { #<<<1
238 return [$toggles($name) explain]
242 body tlc::Tools::toggle_ref {name} { #<<<1
244 return $toggles($name)
248 body tlc::Tools::separator {{side left} args} { #<<<1
251 left - right - top - bottom {}
253 error "Unknown side specification: ($side)"
257 set myslot [incr slot]
261 incr myslot $itk_option(-midslot)
265 set name "sep$myslot"
267 set path [string tolower $w.$name]
268 regsub { +} $path {} path
269 set path [string map {" " _} $path]
270 set path [string trim $path]
272 if {[winfo exists $path]} {
273 error "pathname $path already exists"
276 set pathmap($name) $path
277 set slotmap($path) $myslot
279 set toggle {-state {disabled normal}}
284 eval [list frame $path -borderwidth 2 -relief ridge -width 2 -height 2] $args
288 error "Unknown type: ($type)"
291 eval [list tlc::StateToggle #auto toggles($name) $path] $toggle
292 $toggles($name) configure -default 1
293 tableadd $path $myslot