source: trunk/instant/types/boolean.tcl @ 1728

Last change on this file since 1728 was 1728, checked in by mmc, 14 years ago

Initial version of the "instant rappture" gui builder. To run this,
just say "irappture" or "irappture -tool path/to/tool.xml". It will
bring up an editor that lets you specify inputs/outputs and preview
the tool.

Made two fixes along the way to the scroller, so that it handles
automatic scrollbars better, and to the grab stack, so that it avoids
pushing the same window on the grab stack twice. Both of these fixes
solved problems in iRappture, and they'll probably fix strange behaviors
in the main rappture as well.

File size: 2.0 KB
Line 
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# ======================================================================
13itcl::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}
Note: See TracBrowser for help on using the repository browser.