Ignore:
Timestamp:
Mar 14, 2011 10:58:06 AM (13 years ago)
Author:
mmc
Message:

Major upgrade in the object definitions for the regression tester.
Added "storage" along with "import" and "export" to load/save objects
to/from strings and XML. Also added "compare" method for comparing
the value of one object versus another.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lang/tcl/scripts/objects/boolean/boolean.rp

    r2080 r2134  
    11object boolean -extends base {
    22    palettes "Inputs"
     3
    34    help http://rappture.org/wiki/rp_xml_ele_boolean
     5
    46    attr default -title "Default Value" -type boolean -path default
    57
    6     check label {
    7         if {[string length [string trim $attr(label)]] == 0} {
    8             return [list warning "Should set a label that describes this value."]
     8    storage {
     9        private variable _val   ;# boolean value
     10    }
     11
     12    import xml {xmlobj path} {
     13        import_string [$xmlobj get $path.current]
     14    }
     15
     16    export xml {xmlobj path} {
     17        set v [expr {($_val) ? "true" : "false"}]
     18        $xmlobj put $path $v
     19    }
     20
     21    import string {val} {
     22        if {[string is boolean -strict $val]} {
     23            set _val $val
     24        } else {
     25            error "don't recognize value"
    926        }
    1027    }
    11     check description {
    12         set desc [string trim $attr(description)]
    13         if {[string length $desc] == 0} {
    14             return [list warning "Should include a description of what this value represents, typical settings, etc."]
    15         } elseif {[string equal $desc $attr(label)]} {
    16             return [list warning "Description should be different from the label and give additional information about the value."]
     28
     29    export string {var} {
     30        upvar $var v
     31        set v [expr {($_val) ? "true" : "false"}]
     32    }
     33
     34    compare {
     35        if {$_val && !$_val2} {
     36            return 1
     37        } elseif {!$_val && $_val} {
     38            return -1
    1739        }
     40        return 0
    1841    }
    1942}
Note: See TracChangeset for help on using the changeset viewer.