source: trunk/gui/scripts/booleanentry.tcl @ 13

Last change on this file since 13 was 13, checked in by mmc, 19 years ago

Many improvements, including a new energy level viewer
for Huckel-IV. Added support for a new <boolean> type.
Fixed the cloud/field stuff so that when a cloud is 1D,
it reverts to BLT vectors so it will plot correctly.
Fixed the install script to work better on Windows.

File size: 5.4 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: BooleanEntry - widget for entering boolean values
3#
4#  This widget represents a <boolean> entry on a control panel.
5#  It is used to enter yes/no or on/off values.
6# ======================================================================
7#  AUTHOR:  Michael McLennan, Purdue University
8#  Copyright (c) 2004-2005
9#  Purdue Research Foundation, West Lafayette, IN
10# ======================================================================
11package require Itk
12
13itcl::class Rappture::BooleanEntry {
14    inherit itk::Widget
15
16    constructor {xmlobj path args} { # defined below }
17
18    public method value {args}
19
20    public method label {}
21    public method tooltip {}
22
23    protected method _newValue {}
24
25    private variable _xmlobj ""   ;# XML containing description
26    private variable _path ""     ;# path in XML to this number
27}
28
29itk::usual BooleanEntry {
30    keep -cursor -font
31    keep -foreground -background
32    keep -textbackground
33    keep -selectbackground -selectforeground -selectborderwidth
34}
35
36# ----------------------------------------------------------------------
37# CONSTRUCTOR
38# ----------------------------------------------------------------------
39itcl::body Rappture::BooleanEntry::constructor {xmlobj path args} {
40    if {![Rappture::library isvalid $xmlobj]} {
41        error "bad value \"$xmlobj\": should be Rappture::library"
42    }
43    set _xmlobj $xmlobj
44    set _path $path
45
46    #
47    # Create the widget and configure it properly based on other
48    # hints in the XML.
49    #
50    itk_component add switch {
51        Rappture::Switch $itk_interior.switch
52    }
53    pack $itk_component(switch) -expand yes -fill both
54    bind $itk_component(switch) <<Value>> [itcl::code $this _newValue]
55
56    set color [$xmlobj get $path.about.color]
57    if {$color != ""} {
58        $itk_component(switch) configure -oncolor $color
59    }
60
61    # if the control has an icon, plug it in
62    set str [$xmlobj get $path.about.icon]
63    if {$str != ""} {
64        $itk_component(switch) configure -onimage \
65            [image create photo -data $str]
66    }
67
68    eval itk_initialize $args
69
70    #
71    # Assign the default value to this widget, if there is one.
72    #
73    set str [$xmlobj get $path.default]
74    if {"" != $str != ""} { $itk_component(switch) value $str }
75}
76
77# ----------------------------------------------------------------------
78# USAGE: value ?-check? ?<newval>?
79#
80# Clients use this to query/set the value for this widget.  With
81# no args, it returns the current value for the widget.  If the
82# <newval> is specified, it sets the value of the widget and
83# sends a <<Value>> event.  If the -check flag is included, the
84# new value is not actually applied, but just checked for correctness.
85# ----------------------------------------------------------------------
86itcl::body Rappture::BooleanEntry::value {args} {
87    set onlycheck 0
88    set i [lsearch -exact $args -check]
89    if {$i >= 0} {
90        set onlycheck 1
91        set args [lreplace $args $i $i]
92    }
93
94    if {[llength $args] == 1} {
95        if {$onlycheck} {
96            # someday we may add validation...
97            return
98        }
99        set newval [lindex $args 0]
100        $itk_component(switch) value $newval
101        return $newval
102
103    } elseif {[llength $args] != 0} {
104        error "wrong # args: should be \"value ?-check? ?newval?\""
105    }
106
107    #
108    # Query the value and return.
109    #
110    return [$itk_component(switch) value]
111}
112
113# ----------------------------------------------------------------------
114# USAGE: label
115#
116# Clients use this to query the label associated with this widget.
117# Reaches into the XML and pulls out the appropriate label string.
118# ----------------------------------------------------------------------
119itcl::body Rappture::BooleanEntry::label {} {
120    set label [$_xmlobj get $_path.about.label]
121    if {"" == $label} {
122        set label "Boolean"
123    }
124    return $label
125}
126
127# ----------------------------------------------------------------------
128# USAGE: tooltip
129#
130# Clients use this to query the tooltip associated with this widget.
131# Reaches into the XML and pulls out the appropriate description
132# string.  Returns the string that should be used with the
133# Rappture::Tooltip facility.
134# ----------------------------------------------------------------------
135itcl::body Rappture::BooleanEntry::tooltip {} {
136    set str [$_xmlobj get $_path.about.description]
137
138    set units [$_xmlobj get $_path.units]
139    set min [$_xmlobj get $_path.min]
140    set max [$_xmlobj get $_path.max]
141
142    if {$units != "" || $min != "" || $max != ""} {
143        append str "\n\nEnter a number"
144
145        if {$min != "" && $max != ""} {
146            append str " between $min and $max"
147        } elseif {$min != ""} {
148            append str " greater than $min"
149        } elseif {$max != ""} {
150            append str " less than $max"
151        }
152
153        if {$units != ""} {
154            set desc [Rappture::Units::description $units]
155            append str " with units of $desc"
156        }
157    }
158    return [string trim $str]
159}
160
161# ----------------------------------------------------------------------
162# USAGE: _newValue
163#
164# Invoked automatically whenever the value in the gauge changes.
165# Sends a <<Value>> event to notify clients of the change.
166# ----------------------------------------------------------------------
167itcl::body Rappture::BooleanEntry::_newValue {} {
168    event generate $itk_component(hull) <<Value>>
169}
Note: See TracBrowser for help on using the repository browser.