1 | # ---------------------------------------------------------------------- |
---|
2 | # EDITOR: boolean attribute values |
---|
3 | # |
---|
4 | # Used within the Instant Rappture builder to edit boolean values. |
---|
5 | # |
---|
6 | # ====================================================================== |
---|
7 | # AUTHOR: Michael McLennan, Purdue University |
---|
8 | # Copyright (c) 2004-2010 Purdue Research Foundation |
---|
9 | # |
---|
10 | # See the file "license.terms" for information on usage and |
---|
11 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
12 | # ====================================================================== |
---|
13 | itcl::class AttrBoolean { |
---|
14 | constructor {win args} { |
---|
15 | Rappture::getopts args params { |
---|
16 | } |
---|
17 | |
---|
18 | Rappture::Combobox $win.val -width 10 -editable no |
---|
19 | pack $win.val -side left |
---|
20 | $win.val choices insert end 1 "True" 0 "False" |
---|
21 | set _win $win |
---|
22 | } |
---|
23 | |
---|
24 | public method check {} { |
---|
25 | set val [$_win.val translate [$_win.val value]] |
---|
26 | if {![string is boolean -strict $val]} { |
---|
27 | return [list error "Bad value \"$val\": should be Boolean"] |
---|
28 | } |
---|
29 | return "" |
---|
30 | } |
---|
31 | |
---|
32 | public method load {val} { |
---|
33 | if {![string is boolean -strict $val] || $val} { |
---|
34 | $_win.val value "True" |
---|
35 | } else { |
---|
36 | $_win.val value "False" |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | public method save {var} { |
---|
41 | upvar $var value |
---|
42 | set str [$_win.val translate [$_win.val value]] |
---|
43 | if {[string is boolean -strict $str] && $str} { |
---|
44 | set value "yes" |
---|
45 | } else { |
---|
46 | set value "no" |
---|
47 | } |
---|
48 | return 1 |
---|
49 | } |
---|
50 | |
---|
51 | public method edit {} { |
---|
52 | focus $_win.val |
---|
53 | } |
---|
54 | |
---|
55 | public proc import {xmlobj path} { |
---|
56 | set val [$xmlobj get $path] |
---|
57 | if {[string is boolean -strict $val] && $val} { |
---|
58 | set val "yes" |
---|
59 | } else { |
---|
60 | set val "no" |
---|
61 | } |
---|
62 | return $val |
---|
63 | } |
---|
64 | |
---|
65 | public proc export {xmlobj path value} { |
---|
66 | if {$value} { |
---|
67 | $xmlobj put $path "yes" |
---|
68 | } else { |
---|
69 | $xmlobj put $path "no" |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | private variable _win "" ;# containing frame |
---|
74 | } |
---|