source: trunk/gui/scripts/tempgauge.tcl @ 111

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

Lots of changes to support Huckel-IV:

  • Support for embedded <tool> declarations
  • New <integer> entry
  • Support for numbers and structures as output elements
  • Atom numbers/symbols in MoleculeViewer?
File size: 4.7 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: tempgauge - gauge for temperature values
3#
4#  This is a specialize form of the more general gauge, used for
5#  displaying temperature 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
13option add *TemperatureGauge.sampleWidth 30 widgetDefault
14option add *TemperatureGauge.sampleHeight 20 widgetDefault
15option add *TemperatureGauge.textBackground #cccccc widgetDefault
16option add *TemperatureGauge.valuePosition "right" widgetDefault
17option add *TemperatureGauge.editable yes widgetDefault
18
19itcl::class Rappture::TemperatureGauge {
20    inherit Rappture::Gauge
21
22    constructor {args} { # defined below }
23
24    protected method _redraw {}
25    protected method _resize {}
26
27    # create a spectrum to use for all temperature widgets
28    private common _spectrum [Rappture::Spectrum [namespace current]::#auto {
29        0.0    blue
30        300.0  red
31        500.0  yellow
32    } -units K]
33}
34
35itk::usual TemperatureGauge {
36}
37
38# ----------------------------------------------------------------------
39# CONSTRUCTOR
40# ----------------------------------------------------------------------
41itcl::body Rappture::TemperatureGauge::constructor {args} {
42    eval itk_initialize -spectrum $_spectrum -units K $args
43}
44
45# ----------------------------------------------------------------------
46# USAGE: _redraw
47#
48# Used internally to redraw the gauge on the internal canvas based
49# on the current value and the size of the widget.  For this temperature
50# gauge, we draw something that looks like a thermometer.
51# ----------------------------------------------------------------------
52itcl::body Rappture::TemperatureGauge::_redraw {} {
53    set c $itk_component(icon)
54    set w [winfo width $c]
55    set h [winfo height $c]
56
57    if {"" == [$c find all]} {
58        # first time around, create the items
59        $c create oval 0 0 1 1 -outline "" -tags bulbfill
60        $c create oval 0 0 1 1 -outline black -tags bulboutline
61        $c create rect 0 0 1 1 -outline black -fill white -tags stickoutline
62        $c create rect 0 0 1 1 -outline "" -tags stickfill
63        $c create image 0 0 -anchor w -image "" -tags bimage
64    }
65
66    if {"" != $itk_option(-spectrum)} {
67        set color [$itk_option(-spectrum) get [value]]
68        set frac [$itk_option(-spectrum) get -fraction [value]]
69    } else {
70        set color ""
71        set frac 0
72    }
73
74    # update the items based on current values
75    set x 1
76    set y [expr {0.5*$h}]
77    $c coords bimage 0 $y
78    if {$itk_option(-image) != ""} {
79        set x [expr {$x + [image width $itk_option(-image)] + 2}]
80    }
81
82    set avail [expr {$w-$x}]
83    if {$avail > 0} {
84        #
85        # If we have any space left over, draw the thermometer
86        # as a mercury bulb on the left and a stick to the right.
87        #
88        set bsize [expr {0.2*$avail}]
89        if {$bsize > 0.5*$h-2} {set bsize [expr {0.5*$h-2}]}
90        set ssize [expr {0.5*$bsize}]
91
92        $c coords bulboutline $x [expr {$y-$bsize}] \
93            [expr {$x+2*$bsize}] [expr {$y+$bsize}]
94        $c coords bulbfill $x [expr {$y-$bsize}] \
95            [expr {$x+2*$bsize}] [expr {$y+$bsize}]
96
97        set x0 [expr {$x+2*$bsize+1}]
98        set x1 [expr {$w-2}]
99        set xr [expr {($x1-$x0)*$frac + $x0}]
100        $c coords stickoutline [expr {$x0-2}] [expr {$y-$ssize}] \
101            $x1 [expr {$y+$ssize}]
102        $c coords stickfill [expr {$x0-2}] [expr {$y-$ssize+1}] \
103            $xr [expr {$y+$ssize}]
104
105        $c itemconfigure bulbfill -fill $color
106        $c itemconfigure stickfill -fill $color
107    }
108}
109
110# ----------------------------------------------------------------------
111# USAGE: _resize
112#
113# Used internally to resize the internal canvas based on the -image
114# option or the size of the text.
115# ----------------------------------------------------------------------
116itcl::body Rappture::TemperatureGauge::_resize {} {
117    if {$itk_option(-samplewidth) > 0} {
118        set w $itk_option(-samplewidth)
119    } else {
120        set w [winfo reqheight $itk_component(value)]
121    }
122    if {$itk_option(-image) != ""} {
123        set w [expr {$w+[image width $itk_option(-image)]+4}]
124    }
125
126    if {$itk_option(-sampleheight) > 0} {
127        set h $itk_option(-sampleheight)
128    } else {
129        if {$itk_option(-image) != ""} {
130            set h [expr {[image height $itk_option(-image)]+4}]
131        } else {
132            set h [winfo reqheight $itk_component(value)]
133        }
134    }
135
136    $itk_component(icon) configure -width $w -height $h
137}
Note: See TracBrowser for help on using the repository browser.