source: trunk/gui/scripts/numberentry.tcl @ 11

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

Major reorganization of the entire package. The config.xml file
is now irrelevant. All the action is in the tool.xml file. The
main program now organizes all input into 1) side-by-side pages,
2) input/result (wizard-style) pages, or 3) a series of wizard-
style pages. The <input> can have <phase> parts representing
the various pages.

Added a new ContourResult? widget based on Swaroop's vtk plotting
code.

Also, added easymesh and showmesh to the "tools" directory.
We need these for Eric Polizzi's code.

File size: 6.5 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: NumberEntry - widget for entering numeric values
3#
4#  This widget represents a <number> entry on a control panel.
5#  It is used to enter numeric 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::NumberEntry {
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 NumberEntry {
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::NumberEntry::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    # Figure out what sort of control to create
48    #
49    set presets ""
50    foreach pre [$xmlobj children -type preset $path] {
51        lappend presets \
52            [$xmlobj get $path.$pre.value] \
53            [$xmlobj get $path.$pre.label]
54    }
55
56    set class Rappture::Gauge
57    set units [$xmlobj get $path.units]
58    if {$units != ""} {
59        set desc [Rappture::Units::description $units]
60        if {[string match temperature* $desc]} {
61            set class Rappture::TemperatureGauge
62        }
63    }
64
65    #
66    # Create the widget and configure it properly based on other
67    # hints in the XML.
68    #
69    itk_component add gauge {
70        $class $itk_interior.gauge -units $units -presets $presets
71    }
72    pack $itk_component(gauge) -expand yes -fill both
73    bind $itk_component(gauge) <<Value>> [itcl::code $this _newValue]
74
75    set min [$xmlobj get $path.min]
76    if {"" != $min} { $itk_component(gauge) configure -minvalue $min }
77
78    set max [$xmlobj get $path.max]
79    if {"" != $max} { $itk_component(gauge) configure -maxvalue $max }
80
81    if {$class == "Rappture::Gauge" && "" != $min && "" != $max} {
82        set color [$xmlobj get $path.color]
83        if {$color == ""} {
84            set color blue
85        }
86        if {$units != ""} {
87            set min [Rappture::Units::convert $min -to $units -units off]
88            set max [Rappture::Units::convert $max -to $units -units off]
89        }
90        $itk_component(gauge) configure \
91            -spectrum [Rappture::Spectrum ::#auto [list \
92                $min white $max $color] -units $units]
93    }
94
95    # if the control has an icon, plug it in
96    set str [$xmlobj get $path.about.icon]
97    if {$str != ""} {
98        $itk_component(gauge) configure -image [image create photo -data $str]
99    }
100
101    eval itk_initialize $args
102
103    #
104    # Assign the default value to this widget, if there is one.
105    #
106    set str [$xmlobj get $path.default]
107    if {"" != $str != ""} { $itk_component(gauge) value $str }
108}
109
110# ----------------------------------------------------------------------
111# USAGE: value ?-check? ?<newval>?
112#
113# Clients use this to query/set the value for this widget.  With
114# no args, it returns the current value for the widget.  If the
115# <newval> is specified, it sets the value of the widget and
116# sends a <<Value>> event.  If the -check flag is included, the
117# new value is not actually applied, but just checked for correctness.
118# ----------------------------------------------------------------------
119itcl::body Rappture::NumberEntry::value {args} {
120    set onlycheck 0
121    set i [lsearch -exact $args -check]
122    if {$i >= 0} {
123        set onlycheck 1
124        set args [lreplace $args $i $i]
125    }
126
127    if {[llength $args] == 1} {
128        if {$onlycheck} {
129            # someday we may add validation...
130            return
131        }
132        set newval [lindex $args 0]
133        $itk_component(gauge) value $newval
134        return $newval
135
136    } elseif {[llength $args] != 0} {
137        error "wrong # args: should be \"value ?-check? ?newval?\""
138    }
139
140    #
141    # Query the value and return.
142    #
143    return [$itk_component(gauge) value]
144}
145
146# ----------------------------------------------------------------------
147# USAGE: label
148#
149# Clients use this to query the label associated with this widget.
150# Reaches into the XML and pulls out the appropriate label string.
151# ----------------------------------------------------------------------
152itcl::body Rappture::NumberEntry::label {} {
153    set label [$_xmlobj get $_path.about.label]
154    if {"" == $label} {
155        set label "Number"
156    }
157    return $label
158}
159
160# ----------------------------------------------------------------------
161# USAGE: tooltip
162#
163# Clients use this to query the tooltip associated with this widget.
164# Reaches into the XML and pulls out the appropriate description
165# string.  Returns the string that should be used with the
166# Rappture::Tooltip facility.
167# ----------------------------------------------------------------------
168itcl::body Rappture::NumberEntry::tooltip {} {
169    set str [$_xmlobj get $_path.about.description]
170
171    set units [$_xmlobj get $_path.units]
172    set min [$_xmlobj get $_path.min]
173    set max [$_xmlobj get $_path.max]
174
175    if {$units != "" || $min != "" || $max != ""} {
176        append str "\n\nEnter a number"
177
178        if {$min != "" && $max != ""} {
179            append str " between $min and $max"
180        } elseif {$min != ""} {
181            append str " greater than $min"
182        } elseif {$max != ""} {
183            append str " less than $max"
184        }
185
186        if {$units != ""} {
187            set desc [Rappture::Units::description $units]
188            append str " with units of $desc"
189        }
190    }
191    return [string trim $str]
192}
193
194# ----------------------------------------------------------------------
195# USAGE: _newValue
196#
197# Invoked automatically whenever the value in the gauge changes.
198# Sends a <<Value>> event to notify clients of the change.
199# ----------------------------------------------------------------------
200itcl::body Rappture::NumberEntry::_newValue {} {
201    event generate $itk_component(hull) <<Value>>
202}
Note: See TracBrowser for help on using the repository browser.