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-2012 HUBzero Foundation, LLC |
---|
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 | value -tooltip "" |
---|
17 | } |
---|
18 | |
---|
19 | Rappture::Combobox $win.val -width 10 -editable no |
---|
20 | pack $win.val -side left |
---|
21 | $win.val choices insert end 1 "True" 0 "False" |
---|
22 | |
---|
23 | Rappture::Tooltip::for $win.val $params(-tooltip) |
---|
24 | |
---|
25 | set _win $win |
---|
26 | } |
---|
27 | |
---|
28 | public method check {} { |
---|
29 | set val [$_win.val translate [$_win.val value]] |
---|
30 | if {![string is boolean -strict $val]} { |
---|
31 | return [list error "Bad value \"$val\": should be Boolean"] |
---|
32 | } |
---|
33 | return "" |
---|
34 | } |
---|
35 | |
---|
36 | public method load {val} { |
---|
37 | if {![string is boolean -strict $val] || $val} { |
---|
38 | $_win.val value "True" |
---|
39 | } else { |
---|
40 | $_win.val value "False" |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | public method save {var} { |
---|
45 | upvar $var value |
---|
46 | set str [$_win.val translate [$_win.val value]] |
---|
47 | if {[string is boolean -strict $str] && $str} { |
---|
48 | set value "yes" |
---|
49 | } else { |
---|
50 | set value "no" |
---|
51 | } |
---|
52 | return 1 |
---|
53 | } |
---|
54 | |
---|
55 | public method edit {} { |
---|
56 | focus -force $_win.val |
---|
57 | } |
---|
58 | |
---|
59 | public proc import {xmlobj path} { |
---|
60 | set val [$xmlobj get $path] |
---|
61 | if {[string is boolean -strict $val] && $val} { |
---|
62 | set val "yes" |
---|
63 | } else { |
---|
64 | set val "no" |
---|
65 | } |
---|
66 | return $val |
---|
67 | } |
---|
68 | |
---|
69 | public proc export {xmlobj path value} { |
---|
70 | if {$value} { |
---|
71 | $xmlobj put $path "yes" |
---|
72 | } else { |
---|
73 | $xmlobj put $path "no" |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | private variable _win "" ;# containing frame |
---|
78 | } |
---|