summaryrefslogtreecommitdiffstats
path: root/library/demos/check.tcl
diff options
context:
space:
mode:
authorhobbs <hobbs>2004-02-18 00:40:23 (GMT)
committerhobbs <hobbs>2004-02-18 00:40:23 (GMT)
commitf349a3827b7c3d5876b0531780396c6acda15450 (patch)
tree7f16efd14fa17fc03ce82796e8314678aa3d6e1e /library/demos/check.tcl
parent4549e3fbc8a24a6ba2228d48dcea4dba5e49c506 (diff)
downloadtk-f349a3827b7c3d5876b0531780396c6acda15450.zip
tk-f349a3827b7c3d5876b0531780396c6acda15450.tar.gz
tk-f349a3827b7c3d5876b0531780396c6acda15450.tar.bz2
* doc/checkbutton.n: TIP#110 implementation
* doc/radiobutton.n: Tristate Checkbutton and Radiobuttons * generic/tkButton.c: * generic/tkButton.h: * library/demos/check.tcl: * library/demos/radio.tcl: * macosx/tkMacOSXButton.c: * macosx/tkMacOSXDefault.h: * tests/button.test: * unix/tkUnixButton.c: * unix/tkUnixDefault.h: * win/tkWinButton.c: * win/tkWinDefault.h:
Diffstat (limited to 'library/demos/check.tcl')
-rw-r--r--library/demos/check.tcl47
1 files changed, 43 insertions, 4 deletions
diff --git a/library/demos/check.tcl b/library/demos/check.tcl
index 82c5d18..ef8c5c3 100644
--- a/library/demos/check.tcl
+++ b/library/demos/check.tcl
@@ -3,7 +3,7 @@
# This demonstration script creates a toplevel window containing
# several checkbuttons.
#
-# RCS: @(#) $Id: check.tcl,v 1.3 2003/08/20 23:02:18 hobbs Exp $
+# RCS: @(#) $Id: check.tcl,v 1.4 2004/02/18 00:40:24 hobbs Exp $
if {![info exists widgetDemo]} {
error "This script should be run from the \"widget\" demo."
@@ -16,14 +16,53 @@ wm title $w "Checkbutton Demonstration"
wm iconname $w "check"
positionWindow $w
-label $w.msg -font $font -wraplength 4i -justify left -text "Three checkbuttons are displayed below. If you click on a button, it will toggle the button's selection state and set a Tcl variable to a value indicating the state of the checkbutton. Click the \"See Variables\" button to see the current values of the variables."
+label $w.msg -font $font -wraplength 4i -justify left -text "Four checkbuttons are displayed below. If you click on a button, it will toggle the button's selection state and set a Tcl variable to a value indicating the state of the checkbutton. The first button also follows the state of the other three. If only some of the three are checked, the first button will display the tri-state mode. Click the \"See Variables\" button to see the current values of the variables."
pack $w.msg -side top
## See Code / Dismiss buttons
-set btns [addSeeDismiss $w.buttons $w [list wipers brakes sober]]
+set btns [addSeeDismiss $w.buttons $w [list safety wipers brakes sober]]
pack $btns -side bottom -fill x
+checkbutton $w.b0 -text "Safety Check" -variable safety -relief flat \
+ -onvalue "all" \
+ -offvalue "none" \
+ -tristatevalue "partial"
checkbutton $w.b1 -text "Wipers OK" -variable wipers -relief flat
checkbutton $w.b2 -text "Brakes OK" -variable brakes -relief flat
checkbutton $w.b3 -text "Driver Sober" -variable sober -relief flat
-pack $w.b1 $w.b2 $w.b3 -side top -pady 2 -anchor w
+pack $w.b0 -side top -pady 2 -anchor w
+pack $w.b1 $w.b2 $w.b3 -side top -pady 2 -anchor w -padx 15
+
+set in_check 0
+proc tristate_check {n1 n2 op} {
+ global safety wipers brakes sober in_check
+ if {$in_check} {
+ return
+ }
+ set in_check 1
+ if {$n1 eq "safety"} {
+ if {$safety eq "none"} {
+ set wipers 0
+ set brakes 0
+ set sober 0
+ } elseif {$safety eq "all"} {
+ set wipers 1
+ set brakes 1
+ set sober 1
+ }
+ } else {
+ if {$wipers == 1 && $brakes == 1 && $sober == 1} {
+ set safety all
+ } elseif {$wipers == 1 || $brakes == 1 || $sober == 1} {
+ set safety partial
+ } else {
+ set safety none
+ }
+ }
+ set in_check 0
+}
+
+trace variable wipers w tristate_check
+trace variable brakes w tristate_check
+trace variable sober w tristate_check
+trace variable safety w tristate_check