source: branches/r9/gui/scripts/tempgauge.tcl @ 5106

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

Fixes for nanoHUB ticket #258058 and #258045 -- note within a group tab
doesn't fill out the area properly. Should work better now. Also fixed
tabs to contain the window, instead of floating above the cotents as they
have for a long time.

Fixed boolean controls to have a more obvious on/off switch instead of a
checkbox. Fixed integers and spinners to use larger +/- buttons that are
easier to press on an iPad. Fixed numbers and other gauges to have the
same relief style as entries and other widgets.

Added new layout styles to groups: horizontal, vertical, tabs, and sentence.
You can now explicitly make a layout vertical instead of tabs by setting
the layout to "vertical" instead of throwing in a separator. Updated the
zoo/groups example to show off new horizontal and sentence types.

Fixed the "drawing" example in the zoo to gray out the trapezoid top when
it is disabled.

File size: 5.5 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} { # defined below }
29
30    protected method _redraw {}
31    protected method _resize {}
32
33    # create a spectrum to use for all temperature widgets
34    private common _spectrum [Rappture::Spectrum [namespace current]::#auto {
35        0.0    blue
36        300.0  red
37        500.0  yellow
38    } -units K]
39}
40
41itk::usual TemperatureGauge {
42}
43
44# ----------------------------------------------------------------------
45# CONSTRUCTOR
46# ----------------------------------------------------------------------
47itcl::body Rappture::TemperatureGauge::constructor {args} {
48    eval itk_initialize -spectrum $_spectrum -units K $args
49}
50
51# ----------------------------------------------------------------------
52# USAGE: _redraw
53#
54# Used internally to redraw the gauge on the internal canvas based
55# on the current value and the size of the widget.  For this temperature
56# gauge, we draw something that looks like a thermometer.
57# ----------------------------------------------------------------------
58itcl::body Rappture::TemperatureGauge::_redraw {} {
59    set c $itk_component(icon)
60    set w [winfo width $c]
61    set h [winfo height $c]
62
63    if {"" == [$c find all]} {
64        # first time around, create the items
65        $c create oval 0 0 1 1 -outline "" -tags bulbfill
66        $c create oval 0 0 1 1 -outline black -tags bulboutline
67        $c create oval 0 0 1 1 -outline "" -fill "" -stipple gray50 -tags {bulbscreen screen}
68        $c create rect 0 0 1 1 -outline black -fill white -tags stickoutline
69        $c create rect 0 0 1 1 -outline "" -tags stickfill
70        $c create rect 0 0 1 1 -outline "" -fill "" -stipple gray50 -tags {stickscreen screen}
71        $c create image 0 0 -anchor w -image "" -tags bimage
72    }
73
74    if {"" != $itk_option(-spectrum)} {
75        set color [$itk_option(-spectrum) get [value]]
76        set frac [$itk_option(-spectrum) get -fraction [value]]
77    } else {
78        set color ""
79        set frac 0
80    }
81
82    # update the items based on current values
83    set x 1
84    set y [expr {0.5*$h}]
85    $c coords bimage 0 $y
86    if {$itk_option(-image) != ""} {
87        set x [expr {$x + [image width $itk_option(-image)] + 2}]
88    }
89
90    set avail [expr {$w-$x}]
91    if {$avail > 0} {
92        #
93        # If we have any space left over, draw the thermometer
94        # as a mercury bulb on the left and a stick to the right.
95        #
96        set bsize [expr {0.2*$avail}]
97        if {$bsize > 0.5*$h-2} {set bsize [expr {0.5*$h-2}]}
98        set ssize [expr {0.5*$bsize}]
99
100        $c coords bulboutline $x [expr {$y-$bsize}] \
101            [expr {$x+2*$bsize}] [expr {$y+$bsize}]
102        $c coords bulbscreen [expr {$x-1}] [expr {$y-$bsize-1}] \
103            [expr {$x+2*$bsize+1}] [expr {$y+$bsize+1}]
104        $c coords bulbfill $x [expr {$y-$bsize}] \
105            [expr {$x+2*$bsize}] [expr {$y+$bsize}]
106
107        set x0 [expr {$x+2*$bsize+1}]
108        set x1 [expr {$w-2}]
109        set xr [expr {($x1-$x0)*$frac + $x0}]
110        $c coords stickoutline [expr {$x0-2}] [expr {$y-$ssize}] \
111            $x1 [expr {$y+$ssize}]
112        $c coords stickscreen [expr {$x0-2}] [expr {$y-$ssize}] \
113            [expr {$x1+1}] [expr {$y+$ssize+1}]
114        $c coords stickfill [expr {$x0-2}] [expr {$y-$ssize+1}] \
115            $xr [expr {$y+$ssize}]
116
117        $c itemconfigure bulbfill -fill $color
118        $c itemconfigure stickfill -fill $color
119    }
120
121    if {$itk_option(-state) == "disabled"} {
122        $c itemconfigure screen -fill white
123    } else {
124        $c itemconfigure screen -fill ""
125    }
126}
127
128# ----------------------------------------------------------------------
129# USAGE: _resize
130#
131# Used internally to resize the internal canvas based on the -image
132# option or the size of the text.
133# ----------------------------------------------------------------------
134itcl::body Rappture::TemperatureGauge::_resize {} {
135    if {$itk_option(-samplewidth) > 0} {
136        set w $itk_option(-samplewidth)
137    } else {
138        set w [winfo reqheight $itk_component(value)]
139    }
140    if {$itk_option(-image) != ""} {
141        set w [expr {$w+[image width $itk_option(-image)]+4}]
142    }
143
144    if {$itk_option(-sampleheight) > 0} {
145        set h $itk_option(-sampleheight)
146    } else {
147        if {$itk_option(-image) != ""} {
148            set h [expr {[image height $itk_option(-image)]+4}]
149        } else {
150            set h [winfo reqheight $itk_component(value)]
151        }
152    }
153
154    $itk_component(icon) configure -width $w -height $h
155}
Note: See TracBrowser for help on using the repository browser.