1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#
#
#
#
Widget:DefineClass ButtonBox LabelFrame bbox:create bbox:config bbox_proc
set bbox_proc(get) bbox:get
set bbox_proc(subwidget) bbox:subwidget
proc bbox:create {w a} {
global bbox_conf bbox_change
set bbox_conf($w,buttons) {}
set bbox_conf($w,orient) horizontal
set bbox_conf($w,row) 1
set bbox_conf($w,state) normal
set bbox_change(place) 0
set bbox_change(state) 0
}
proc bbox:config {w opt val} {
global bbox_conf bbox_change
switch -- $opt {
-buttons {
bbox:set_buttons $w $val
set bbox_change(place) 1
set bbox_change(state) 1
}
-orient {
set bbox_conf($w,orient) $val
set bbox_change(place) 1
}
-row {
set bbox_conf($w,row) $val
set bbox_change(place) 1
}
-variable {}
-state {
set bbox_conf($w,state) $val
set bbox_change(state) 1
}
default {
return 1
}
}
if $bbox_change(place) {
bbox:place_buttons $w
set bbox_change(place) 0
}
if $bbox_change(state) {
bbox:set_state $w
set bbox_change(state) 0
}
return 0
}
proc bbox:set_buttons {w buttons} {
global bbox_conf
set bbox_conf($w,buttons) {}
foreach i $buttons {
set btn [eval $i]
lappend bbox_conf($w,buttons) $btn
}
}
proc bbox:place_buttons {w} {
global bbox_conf
set f [$w subwidget frame]
set orient $bbox_conf($w,orient)
set maxrow $bbox_conf($w,row)
set col 0
set row 0
foreach b $bbox_conf($w,buttons) {
grid $b -in $f -column $col -row $row -sticky w
if {$orient == "horizontal"} {
incr col
if {$col >= $maxrow} {
set col 0
incr row
}
} else {
incr row
if {$row >= $maxrow} {
set row 0
incr col
}
}
}
}
proc bbox:set_state {w} {
global bbox_conf
set state $bbox_conf($w,state)
foreach b $bbox_conf($w,buttons) {
$b configure -state $state
}
}
proc bbox:get {w a} {
return {}
}
proc bbox:subwidget {w a} {
global bbox_conf
switch -- $a {
buttons {return $bbox_conf($w,buttons)}
default {return [eval Widget:Super ButtonBox $w subwidget $a]}
}
}
proc bbox:test {} {
option add *aho.text aho
option add *baka.text baka
option add *tawake.text tawake
ButtonBox .b1 -buttons {
{checkbutton .b1.aho}
{checkbutton .b1.baka}
{checkbutton .b1.tawake}
}
pack .b1
}
|