source: branches/blt4/lang/tcl/scripts/types/atomactive.tcl @ 3959

Last change on this file since 3959 was 3959, checked in by gah, 11 years ago

sync with trunk

File size: 3.9 KB
Line 
1# ----------------------------------------------------------------------
2#  EDITOR: atom active/inactive settings
3#
4#  Used within the Instant Rappture builder to edit the active/inactve
5#  property used by a <periodicelement> object.  This determines what
6#  parts of the periodic table are allowed or forbidden.
7#
8# ======================================================================
9#  AUTHOR:  Michael McLennan, Purdue University
10#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
11#
12#  See the file "license.terms" for information on usage and
13#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14# ======================================================================
15itcl::class AttrAtomactive {
16    constructor {win args} {
17        Rappture::getopts args params {
18            value -tooltip ""
19        }
20
21        Rappture::Combobox $win.how -width 17 -editable no
22        pack $win.how -side left
23        $win.how choices insert end \
24            "all" "All elements" \
25            "active" "Only these:" \
26            "inactive" "Everything except:"
27
28        bind $win.how <<Value>> [itcl::code $this _react]
29        $win.how value [$win.how label "all"]
30
31        Rappture::Combochecks $win.which
32        $win.which choices insert end \
33            "actinoid" "Actinoid" \
34            "alkali-metal" "Alkali metal" \
35            "alkaline-earth-metal" "Alkaline earth metal" \
36            "halogen" "Halogen" \
37            "lanthanoid" "Lanthanoid" \
38            "metalloid" "Metalloid" \
39            "noble-gas" "Noble gas" \
40            "other-non-metal" "Other non-metal" \
41            "post-transition-metal" "Post-transition metal" \
42            "transition-metal" "Transition metal" \
43            "unknown" "Unknown"
44
45        Rappture::Tooltip::for $win.how $params(-tooltip)
46        Rappture::Tooltip::for $win.which $params(-tooltip)
47
48        set _win $win
49    }
50
51    public method check {} {
52        # user can't enter anything bad
53        return ""
54    }
55
56    public method load {val} {
57        if {[regexp {^(active|inactive): (.+)} $val match which vlist]} {
58            $_win.how value [$_win.how label $which]
59            $_win.which value [split $vlist ,]
60        } elseif {$val eq ""} {
61            $_win.how value [$_win.how label "all"]
62        }
63        _react
64    }
65
66    public method save {var} {
67        upvar $var value
68        switch -- [$_win.how translate [$_win.how value]] {
69            active {
70                set value "active: [join [$_win.which value] ,]"
71            }
72            inactive {
73                set value "inactive: [join [$_win.which value] ,]"
74            }
75            default {
76                set value ""
77            }
78        }
79        return 1
80    }
81
82    public method edit {} {
83        focus -force $_win.how
84    }
85
86    public proc import {xmlobj path} {
87        # attribute is associated with .active, but we need to look
88        # at both .active and .inactive
89        set path [join [lrange [split $path .] 0 end-1] .]
90
91        set aval [string trim [$xmlobj get $path.active]]
92        set ival [string trim [$xmlobj get $path.inactive]]
93        if {$aval ne ""} {
94            set val "active: [join $aval ,]"
95        } elseif {$ival ne ""} {
96            set val "inactive: [join $ival ,]"
97        } else {
98            set val ""
99        }
100        return $val
101    }
102
103    public proc export {xmlobj path value} {
104        # attribute is associated with .active, but we need to look
105        # at both .active and .inactive
106        set path [join [lrange [split $path .] 0 end-1] .]
107
108        if {[regexp {^(active|inactive): (.+)} $value match which vlist]} {
109            $xmlobj put $path.$which [split $vlist ,]
110        }
111    }
112
113    private method _react {} {
114        if {[$_win.how translate [$_win.how value]] eq "all"} {
115            pack forget $_win.which
116        } else {
117            pack $_win.which -side left -expand yes -fill x
118        }
119    }
120
121    private variable _win ""       ;# containing frame
122}
Note: See TracBrowser for help on using the repository browser.