It is sometimes desirable to invoke the code associated with a spinbox's
-command option directly such as in a validation routine. % substitutions
prevent this from being done with something like:
eval [$sb cget -command]
This patch adds "none" as a value identifier to the spinbox's invoke subcommand.
Code like:
$sb invoke none
will perform % substitutions and invoke the command but will not change the value
of the spinbox. I've used this in code like:
proc spinboxCmd { w } {
# Do something here to make the application react to the value.
puts " new value:[$w get]"
}
proc spinboxVal { w v } {
if { ! [string is integer $v]} {
return 0
} elseif {[string length $v]} {
set values [$w cget -values]
if {[llength $values]} {
if {[lsearch $values $v] == -1} {
return 0
}
} else {
if {$v < [$w cget -from]
|| $v > [$w cget -to]} {
return 0
}
# WUZ - worry about increment?
}
}
# OK, the new value is OK, invoke the command
after idle $w invoke none
# It's valid.
return 1
}
spinbox .sb -width 5 \ -from 0 -to 10 -increment 1 \ -command [list spinboxCmd %W] \ -vcmd [list spinboxVal %W %P] \ -validate key
Allow none as identifier to spinbox's invoke subcommand