/usr/lib/grass64/bwidget/spinbox.tcl is in grass-gui 6.4.3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | # ------------------------------------------------------------------------------
# spinbox.tcl
# This file is part of Unifix BWidget Toolkit
# ------------------------------------------------------------------------------
# Index of commands:
# - SpinBox::create
# - SpinBox::configure
# - SpinBox::cget
# - SpinBox::setvalue
# - SpinBox::_destroy
# - SpinBox::_modify_value
# - SpinBox::_test_options
# ------------------------------------------------------------------------------
namespace eval SpinBox {
ArrowButton::use
Entry::use
LabelFrame::use
Widget::bwinclude SpinBox LabelFrame .labf \
rename {-text -label} \
prefix {label -justify -width -anchor -height -font} \
remove {-focus} \
initialize {-relief sunken -borderwidth 2}
Widget::bwinclude SpinBox Entry .e \
remove {-relief -bd -borderwidth -fg -bg} \
rename {-foreground -entryfg -background -entrybg}
Widget::declare SpinBox {
{-range String "" 0}
{-values String "" 0}
{-modifycmd String "" 0}
{-repeatdelay Int 400 0 {=0}}
{-repeatinterval Int 100 0 {=0}}
}
Widget::addmap SpinBox "" :cmd {-background {}}
Widget::addmap SpinBox ArrowButton .arrup {
-foreground {} -background {} -disabledforeground {} -state {}
-repeatdelay {} -repeatinterval {}
}
Widget::addmap SpinBox ArrowButton .arrdn {
-foreground {} -background {} -disabledforeground {} -state {}
-repeatdelay {} -repeatinterval {}
}
Widget::syncoptions SpinBox Entry .e {-text {}}
Widget::syncoptions SpinBox LabelFrame .labf {-label -text -underline {}}
::bind BwSpinBox <FocusIn> {focus %W.labf}
::bind BwSpinBox <Destroy> {SpinBox::_destroy %W}
proc ::SpinBox { path args } { return [eval SpinBox::create $path $args] }
proc use {} {}
variable _widget
}
# ------------------------------------------------------------------------------
# Command SpinBox::create
# ------------------------------------------------------------------------------
proc SpinBox::create { path args } {
variable _widget
Widget::init SpinBox $path $args
_test_options $path
eval frame $path [Widget::subcget $path :cmd] \
-highlightthickness 0 -bd 0 -relief flat -takefocus 0
set labf [eval LabelFrame::create $path.labf [Widget::subcget $path .labf] \
-borderwidth 2 -relief sunken -focus $path.e]
set entry [eval Entry::create $path.e [Widget::subcget $path .e] \
-relief flat -borderwidth 0]
bindtags $path [list $path BwSpinBox [winfo toplevel $path] all]
set farr [frame $path.farr -relief flat -bd 0 -highlightthickness 0]
set height [expr {[winfo reqheight $path.e]/2-2}]
set width 11
set arrup [eval ArrowButton::create $path.arrup -dir top \
[Widget::subcget $path .arrup] \
-highlightthickness 0 -borderwidth 1 -takefocus 0 \
-type button \
-width $width -height $height \
-armcommand [list "SpinBox::_modify_value $path next arm"] \
-disarmcommand [list "SpinBox::_modify_value $path next disarm"]]
set arrdn [eval ArrowButton::create $path.arrdn -dir bottom \
[Widget::subcget $path .arrdn] \
-highlightthickness 0 -borderwidth 1 -takefocus 0 \
-type button \
-width $width -height $height \
-armcommand [list "SpinBox::_modify_value $path previous arm"] \
-disarmcommand [list "SpinBox::_modify_value $path previous disarm"]]
set frame [LabelFrame::getframe $path.labf]
# --- update -value ---
if { [set val [Entry::cget $path.e -text]] != "" } {
set _widget($path,curval) $val
} else {
if { [set var [Widget::getoption $path -textvariable]] != "" } {
GlobalVar::setvar $var $_widget($path,curval)
} else {
Entry::configure $path.e -text $_widget($path,curval)
}
}
Widget::setoption $path -text $_widget($path,curval)
grid $arrup -in $farr -column 0 -row 0 -sticky nsew
grid $arrdn -in $farr -column 0 -row 2 -sticky nsew
grid rowconfigure $farr 0 -weight 1
grid rowconfigure $farr 2 -weight 1
pack $farr -in $frame -side right -fill y
pack $entry -in $frame -side left -fill both -expand yes
pack $labf -fill both -expand yes
::bind $entry <Key-Up> "SpinBox::_modify_value $path next activate"
::bind $entry <Key-Down> "SpinBox::_modify_value $path previous activate"
::bind $entry <Key-Prior> "SpinBox::_modify_value $path last activate"
::bind $entry <Key-Next> "SpinBox::_modify_value $path first activate"
::bind $farr <Configure> {grid rowconfigure %W 1 -minsize [expr {%h%%2}]}
rename $path ::$path:cmd
proc ::$path { cmd args } "return \[eval SpinBox::\$cmd $path \$args\]"
return $path
}
# ------------------------------------------------------------------------------
# Command SpinBox::configure
# ------------------------------------------------------------------------------
proc SpinBox::configure { path args } {
set res [Widget::configure $path $args]
if { [Widget::hasChanged $path -values val] ||
[Widget::hasChanged $path -range val] } {
_test_options $path
}
return $res
}
# ------------------------------------------------------------------------------
# Command SpinBox::cget
# ------------------------------------------------------------------------------
proc SpinBox::cget { path option } {
return [Widget::cget $path $option]
}
# ------------------------------------------------------------------------------
# Command SpinBox::setvalue
# ------------------------------------------------------------------------------
proc SpinBox::setvalue { path index } {
variable _widget
set values [Widget::getoption $path -values]
set value [Entry::cget $path.e -text]
if { [llength $values] } {
# --- -values SpinBox ---
switch -- $index {
next {
if { [set idx [lsearch $values $value]] != -1 } {
incr idx
} elseif { [set idx [lsearch $values "$value*"]] == -1 } {
set idx [lsearch $values $_widget($path,curval)]
}
}
previous {
if { [set idx [lsearch $values $value]] != -1 } {
incr idx -1
} elseif { [set idx [lsearch $values "$value*"]] == -1 } {
set idx [lsearch $values $_widget($path,curval)]
}
}
first {
set idx 0
}
last {
set idx [expr {[llength $values]-1}]
}
default {
if { [string index $index 0] == "@" } {
set idx [string range $index 1 end]
if { [catch {string compare [expr {int($idx)}] $idx} res] || $res != 0 } {
return -code error "bad index \"$index\""
}
} else {
return -code error "bad index \"$index\""
}
}
}
if { $idx >= 0 && $idx < [llength $values] } {
set newval [lindex $values $idx]
} else {
return 0
}
} else {
# --- -range SpinBox ---
set range [Widget::getoption $path -range]
set vmin [lindex $range 0]
set vmax [lindex $range 1]
set incr [lindex $range 2]
switch -- $index {
next {
if { [catch {expr {double($value-$vmin)/$incr}} idx] } {
set newval $_widget($path,curval)
} else {
set newval [expr {$vmin+(round($idx)+1)*$incr}]
if { $newval < $vmin } {
set newval $vmin
} elseif { $newval > $vmax } {
set newval $vmax
}
}
}
previous {
if { [catch {expr {double($value-$vmin)/$incr}} idx] } {
set newval $_widget($path,curval)
} else {
set newval [expr {$vmin+(round($idx)-1)*$incr}]
if { $newval < $vmin } {
set newval $vmin
} elseif { $newval > $vmax } {
set newval $vmax
}
}
}
first {
set newval $vmin
}
last {
set newval $vmax
}
default {
if { [string index $index 0] == "@" } {
set idx [string range $index 1 end]
if { [catch {string compare [expr {int($idx)}] $idx} res] || $res != 0 } {
return -code error "bad index \"$index\""
}
set newval [expr {$vmin+int($idx)*$incr}]
if { $newval < $vmin || $newval > $vmax } {
return 0
}
} else {
return -code error "bad index \"$index\""
}
}
}
}
set _widget($path,curval) $newval
Widget::setoption $path -text $newval
if { [set varname [Entry::cget $path.e -textvariable]] != "" } {
GlobalVar::setvar $varname $newval
} else {
Entry::configure $path.e -text $newval
}
return 1
}
# ------------------------------------------------------------------------------
# Command SpinBox::getvalue
# ------------------------------------------------------------------------------
proc SpinBox::getvalue { path } {
variable _widget
set values [Widget::getoption $path -values]
set value [Entry::cget $path.e -text]
if { [llength $values] } {
# --- -values SpinBox ---
return [lsearch $values $value]
} else {
set range [Widget::getoption $path -range]
set vmin [lindex $range 0]
set vmax [lindex $range 1]
set incr [lindex $range 2]
if { ![catch {expr {double($value-$vmin)/$incr}} idx] &&
$idx == int($idx) } {
return [expr {int($idx)}]
}
return -1
}
}
# ------------------------------------------------------------------------------
# Command SpinBox::bind
# ------------------------------------------------------------------------------
proc SpinBox::bind { path args } {
return [eval ::bind $path.e $args]
}
# ------------------------------------------------------------------------------
# Command SpinBox::_destroy
# ------------------------------------------------------------------------------
proc SpinBox::_destroy { path } {
variable _widget
unset _widget($path,curval)
Widget::destroy $path
rename $path {}
}
# ------------------------------------------------------------------------------
# Command SpinBox::_modify_value
# ------------------------------------------------------------------------------
proc SpinBox::_modify_value { path direction reason } {
if { $reason == "arm" || $reason == "activate" } {
SpinBox::setvalue $path $direction
}
if { ($reason == "disarm" || $reason == "activate") &&
[set cmd [Widget::getoption $path -modifycmd]] != "" } {
uplevel \#0 $cmd
}
}
# ------------------------------------------------------------------------------
# Command SpinBox::_test_options
# ------------------------------------------------------------------------------
proc SpinBox::_test_options { path } {
variable _widget
set values [Widget::getoption $path -values]
if { [llength $values] } {
set _widget($path,curval) [lindex $values 0]
} else {
set range [Widget::getoption $path -range]
set vmin [lindex $range 0]
set vmax [lindex $range 1]
set incr [lindex $range 2]
if { [catch {expr {int($vmin)}}] } {
set vmin 0
}
if { [catch {expr {$vmax<$vmin}} res] || $res } {
set vmax $vmin
}
if { [catch {expr {$incr<0}} res] || $res } {
set incr 1
}
Widget::setoption $path -range [list $vmin $vmax $incr]
set _widget($path,curval) $vmin
}
}
|