source: branches/1.3/lang/tcl/scripts/objects/boolean/boolean.rp @ 3827

Last change on this file since 3827 was 3827, checked in by ldelgass, 11 years ago

Merge mmc's fixes from r3770 in the trunk

File size: 1.8 KB
Line 
1# ----------------------------------------------------------------------
2#  RAPPTURE OBJECT: boolean
3#
4#  A logical on/off value.  It is usually used as an input, but it
5#  can also be an output from a simulation.
6#
7# ======================================================================
8#  AUTHOR:  Michael McLennan, Purdue University
9#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
10#
11#  See the file "license.terms" for information on usage and
12#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13# ======================================================================
14
15object boolean -extends base {
16    palettes "Inputs" "Outputs"
17
18    help http://rappture.org/wiki/rp_xml_ele_boolean
19
20    attr default -title "Default Value" -type boolean -path default -only input -tooltip "Sets the value that this input has when the program first starts.  This value is used by default unless the user explicitly changes it."
21
22    check default {
23        if {[string length [string trim $attr(default)]] == 0} {
24            return [list error "Must have a default value for this boolean value."]
25        }
26    }
27
28    storage {
29        private variable _val   ;# boolean value
30    }
31
32    import xml {xmlobj path} {
33        attr import $xmlobj $path
34        import_string [$xmlobj get $path.current]
35    }
36
37    export xml {xmlobj path} {
38        set v [expr {($_val) ? "true" : "false"}]
39        $xmlobj put $path $v
40    }
41
42    import string {val} {
43        if {[string is boolean -strict $val]} {
44            set _val $val
45        } else {
46            error "don't recognize value"
47        }
48    }
49
50    export string {var} {
51        upvar $var v
52        set v [expr {($_val) ? "true" : "false"}]
53    }
54
55    compare {
56        if {$_val && !$_val2} {
57            return 1
58        } elseif {!$_val && $_val2} {
59            return -1
60        }
61        return 0
62    }
63}
Note: See TracBrowser for help on using the repository browser.