source: branches/1.6/gui/scripts/tempgauge.tcl @ 6131

Last change on this file since 6131 was 5710, checked in by mmh, 9 years ago

add support for xml uq tags

File size: 5.4 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: tempgauge - gauge for temperature values
4#
5#  This is a specialize form of the more general gauge, used for
6#  displaying temperature values.
7# ======================================================================
8#  AUTHOR:  Michael McLennan, Purdue University
9#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
10#
11#  See the file "license.terms" for information on usage and
12#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13# ======================================================================
14package require Itk
15
16option add *TemperatureGauge.sampleWidth 30 widgetDefault
17option add *TemperatureGauge.sampleHeight 20 widgetDefault
18option add *TemperatureGauge.borderWidth 2 widgetDefault
19option add *TemperatureGauge.relief sunken widgetDefault
20option add *TemperatureGauge.textBackground #cccccc widgetDefault
21option add *TemperatureGauge.valuePosition "right" widgetDefault
22option add *TemperatureGauge.editable yes widgetDefault
23option add *TemperatureGauge.state normal widgetDefault
24
25itcl::class Rappture::TemperatureGauge {
26    inherit Rappture::Gauge
27
28    constructor {args} {
29        array set attrs $args
30        Rappture::Gauge::constructor -uq $attrs(-uq)
31    } {
32        eval itk_initialize -spectrum $_spectrum -units K $args
33    }
34    protected method _redraw {}
35    protected method _resize {}
36
37    # create a spectrum to use for all temperature widgets
38    private common _spectrum [Rappture::Spectrum [namespace current]::#auto {
39        0.0    blue
40        300.0  red
41        500.0  yellow
42    } -units K]
43}
44
45itk::usual TemperatureGauge {
46}
47
48# ----------------------------------------------------------------------
49# USAGE: _redraw
50#
51# Used internally to redraw the gauge on the internal canvas based
52# on the current value and the size of the widget.  For this temperature
53# gauge, we draw something that looks like a thermometer.
54# ----------------------------------------------------------------------
55itcl::body Rappture::TemperatureGauge::_redraw {} {
56    set c $itk_component(icon)
57    set w [winfo width $c]
58    set h [winfo height $c]
59
60    if {"" == [$c find all]} {
61        # first time around, create the items
62        $c create oval 0 0 1 1 -outline "" -tags bulbfill
63        $c create oval 0 0 1 1 -outline black -tags bulboutline
64        $c create oval 0 0 1 1 -outline "" -fill "" -stipple gray50 -tags {bulbscreen screen}
65        $c create rect 0 0 1 1 -outline black -fill white -tags stickoutline
66        $c create rect 0 0 1 1 -outline "" -tags stickfill
67        $c create rect 0 0 1 1 -outline "" -fill "" -stipple gray50 -tags {stickscreen screen}
68        $c create image 0 0 -anchor w -image "" -tags bimage
69    }
70
71    if {"" != $itk_option(-spectrum)} {
72        set color [$itk_option(-spectrum) get [value]]
73        set frac [$itk_option(-spectrum) get -fraction [value]]
74    } else {
75        set color ""
76        set frac 0
77    }
78
79    # update the items based on current values
80    set x 1
81    set y [expr {0.5*$h}]
82    $c coords bimage 0 $y
83    if {$itk_option(-image) != ""} {
84        set x [expr {$x + [image width $itk_option(-image)] + 2}]
85    }
86
87    set avail [expr {$w-$x}]
88    if {$avail > 0} {
89        #
90        # If we have any space left over, draw the thermometer
91        # as a mercury bulb on the left and a stick to the right.
92        #
93        set bsize [expr {0.2*$avail}]
94        if {$bsize > 0.5*$h-2} {set bsize [expr {0.5*$h-2}]}
95        set ssize [expr {0.5*$bsize}]
96
97        $c coords bulboutline $x [expr {$y-$bsize}] \
98            [expr {$x+2*$bsize}] [expr {$y+$bsize}]
99        $c coords bulbscreen [expr {$x-1}] [expr {$y-$bsize-1}] \
100            [expr {$x+2*$bsize+1}] [expr {$y+$bsize+1}]
101        $c coords bulbfill $x [expr {$y-$bsize}] \
102            [expr {$x+2*$bsize}] [expr {$y+$bsize}]
103
104        set x0 [expr {$x+2*$bsize+1}]
105        set x1 [expr {$w-2}]
106        set xr [expr {($x1-$x0)*$frac + $x0}]
107        $c coords stickoutline [expr {$x0-2}] [expr {$y-$ssize}] \
108            $x1 [expr {$y+$ssize}]
109        $c coords stickscreen [expr {$x0-2}] [expr {$y-$ssize}] \
110            [expr {$x1+1}] [expr {$y+$ssize+1}]
111        $c coords stickfill [expr {$x0-2}] [expr {$y-$ssize+1}] \
112            $xr [expr {$y+$ssize}]
113
114        $c itemconfigure bulbfill -fill $color
115        $c itemconfigure stickfill -fill $color
116    }
117
118    if {$itk_option(-state) == "disabled"} {
119        $c itemconfigure screen -fill white
120    } else {
121        $c itemconfigure screen -fill ""
122    }
123}
124
125# ----------------------------------------------------------------------
126# USAGE: _resize
127#
128# Used internally to resize the internal canvas based on the -image
129# option or the size of the text.
130# ----------------------------------------------------------------------
131itcl::body Rappture::TemperatureGauge::_resize {} {
132    if {$itk_option(-samplewidth) > 0} {
133        set w $itk_option(-samplewidth)
134    } else {
135        set w [winfo reqheight $itk_component(value)]
136    }
137    if {$itk_option(-image) != ""} {
138        set w [expr {$w+[image width $itk_option(-image)]+4}]
139    }
140
141    if {$itk_option(-sampleheight) > 0} {
142        set h $itk_option(-sampleheight)
143    } else {
144        if {$itk_option(-image) != ""} {
145            set h [expr {[image height $itk_option(-image)]+4}]
146        } else {
147            set h [winfo reqheight $itk_component(value)]
148        }
149    }
150
151    $itk_component(icon) configure -width $w -height $h
152}
Note: See TracBrowser for help on using the repository browser.