source: branches/1.4/gui/scripts/gauge.tcl @ 5660

Last change on this file since 5660 was 5660, checked in by ldelgass, 9 years ago

Merge r5657:5659 from trunk (whitespace/style)

File size: 26.4 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: gauge - compact readout for real values
4#
5#  This widget is a readout for a real value.  It has a little glyph
6#  filled with color according to the value, followed by a numeric
7#  representation of the value itself.  The value can be edited, and
8#  a list of predefined values can be associated with a menu that
9#  drops down from the value.
10# ======================================================================
11#  AUTHOR:  Michael McLennan, Purdue University
12#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
13#
14#  See the file "license.terms" for information on usage and
15#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16# ======================================================================
17package require Itk
18package require BLT
19
20option add *Gauge.sampleWidth 30 widgetDefault
21option add *Gauge.sampleHeight 20 widgetDefault
22option add *Gauge.borderWidth 2 widgetDefault
23option add *Gauge.relief sunken widgetDefault
24option add *Gauge.valuePosition "right" widgetDefault
25option add *Gauge.textBackground #cccccc widgetDefault
26option add *Gauge.editable yes widgetDefault
27
28itcl::class Rappture::Gauge {
29    inherit itk::Widget
30
31    itk_option define -editable editable Editable ""
32    itk_option define -state state State "normal"
33    itk_option define -spectrum spectrum Spectrum ""
34    itk_option define -type type Type "real"
35    itk_option define -units units Units ""
36    itk_option define -minvalue minValue MinValue ""
37    itk_option define -maxvalue maxValue MaxValue ""
38    itk_option define -presets presets Presets ""
39    itk_option define -valueposition valuePosition ValuePosition ""
40    itk_option define -image image Image ""
41    itk_option define -samplewidth sampleWidth SampleWidth 0
42    itk_option define -sampleheight sampleHeight SampleHeight 0
43    itk_option define -log log Log ""
44    itk_option define -validatecommand validateCommand ValidateCommand ""
45
46    constructor {args} { # defined below }
47
48    public method value {args}
49    public method edit {option}
50    public method bump {delta}
51
52    protected method _redraw {}
53    protected method _resize {}
54    protected method _hilite {comp state}
55    protected method _editor {option args}
56    protected method _presets {option}
57    protected method _layout {}
58    protected method _log {event args}
59
60    private variable _value 0  ;# value for this widget
61
62    blt::bitmap define GaugeArrow {
63        #define arrow_width 9
64        #define arrow_height 4
65        static unsigned char arrow_bits[] = {
66           0x7f, 0x00, 0x3e, 0x00, 0x1c, 0x00, 0x08, 0x00};
67    }
68}
69
70itk::usual Gauge {
71    keep -cursor -font -foreground -background
72    keep -selectbackground -selectforeground -selectborderwidth
73}
74
75# ----------------------------------------------------------------------
76# CONSTRUCTOR
77# ----------------------------------------------------------------------
78itcl::body Rappture::Gauge::constructor {args} {
79    itk_option remove hull.borderwidth hull.relief
80    component hull configure -borderwidth 0
81
82    itk_component add icon {
83        canvas $itk_interior.icon -width 1 -height 1 \
84            -borderwidth 0 -highlightthickness 0
85    } {
86        usual
87        ignore -highlightthickness -highlightbackground -highlightcolor
88        ignore -borderwidth -relief
89    }
90    bind $itk_component(icon) <Configure> [itcl::code $this _redraw]
91
92    itk_component add -protected vframe {
93        frame $itk_interior.vframe
94    } {
95        keep -borderwidth -relief
96    }
97
98    itk_component add value {
99        label $itk_component(vframe).value -width 7 \
100            -borderwidth 1 -relief flat -textvariable [itcl::scope _value]
101    } {
102        keep -font
103        rename -background -textbackground textBackground Background
104    }
105    pack $itk_component(value) -side left -expand yes -fill both
106
107    bind $itk_component(value) <Enter> [itcl::code $this _hilite value on]
108    bind $itk_component(value) <Leave> [itcl::code $this _hilite value off]
109
110    bind $itk_component(value) <<Cut>> [itcl::code $this edit cut]
111    bind $itk_component(value) <<Copy>> [itcl::code $this edit copy]
112    bind $itk_component(value) <<Paste>> [itcl::code $this edit paste]
113
114    itk_component add emenu {
115        menu $itk_component(value).menu -tearoff 0
116    } {
117        usual
118        ignore -tearoff
119    }
120    $itk_component(emenu) add command -label "Cut" -accelerator "^X" \
121        -command [list event generate $itk_component(value) <<Cut>>]
122    $itk_component(emenu) add command -label "Copy" -accelerator "^C" \
123        -command [list event generate $itk_component(value) <<Copy>>]
124    $itk_component(emenu) add command -label "Paste" -accelerator "^V" \
125        -command [list event generate $itk_component(value) <<Paste>>]
126    bind $itk_component(value) <<PopupMenu>> \
127        [itcl::code $this _editor menu %X %Y]
128
129    itk_component add editor {
130        Rappture::Editor $itk_interior.editor \
131            -activatecommand [itcl::code $this _editor activate] \
132            -validatecommand [itcl::code $this _editor validate] \
133            -applycommand [itcl::code $this _editor apply]
134    }
135    bind $itk_component(value) <ButtonPress> \
136        [itcl::code $this _editor popup]
137
138
139    itk_component add spinner {
140        frame $itk_component(vframe).spinner
141    }
142
143    itk_component add spinup {
144        button $itk_component(spinner).up -image [Rappture::icon intplus] \
145            -borderwidth 1 -relief raised -highlightthickness 0 \
146            -command [itcl::code $this bump 1]
147    } {
148        usual
149        ignore -borderwidth -highlightthickness
150        rename -background -buttonbackground buttonBackground Background
151    }
152    pack $itk_component(spinup) -side left -expand yes -fill both
153
154    itk_component add spindn {
155        button $itk_component(spinner).down -image [Rappture::icon intminus] \
156            -borderwidth 1 -relief raised -highlightthickness 0 \
157            -command [itcl::code $this bump -1]
158    } {
159        usual
160        ignore -borderwidth -highlightthickness
161        rename -background -buttonbackground buttonBackground Background
162    }
163    pack $itk_component(spindn) -side right -expand yes -fill both
164
165    itk_component add presets {
166        button $itk_component(vframe).psbtn -bitmap GaugeArrow \
167            -borderwidth 1 -highlightthickness 0 -relief raised
168    } {
169        usual
170        ignore -borderwidth -relief -highlightthickness
171    }
172
173    bind $itk_component(presets) <Enter> [itcl::code $this _hilite presets on]
174    bind $itk_component(presets) <Leave> [itcl::code $this _hilite presets off]
175
176    itk_component add presetlist {
177        Rappture::Dropdownlist $itk_component(presets).plist \
178            -postcommand [itcl::code $this _presets post] \
179            -unpostcommand [itcl::code $this _presets unpost] \
180    }
181
182    bind $itk_component(presetlist) <<DropdownlistSelect>> \
183        [itcl::code $this _presets select]
184
185    $itk_component(presets) configure -command \
186        [list $itk_component(presetlist) post $itk_component(vframe) left]
187
188    eval itk_initialize $args
189}
190
191# ----------------------------------------------------------------------
192# USAGE: value ?-check? ?<newval>?
193#
194# Clients use this to query/set the value for this widget.  With
195# no args, it returns the current value for the widget.  If the
196# <newval> is specified, it sets the value of the widget and
197# sends a <<Value>> event.  If the -check flag is included, the
198# new value is not actually applied, but just checked for correctness.
199# ----------------------------------------------------------------------
200itcl::body Rappture::Gauge::value {args} {
201    set onlycheck 0
202    set i [lsearch -exact $args -check]
203    if {$i >= 0} {
204        set onlycheck 1
205        set args [lreplace $args $i $i]
206    }
207
208    if {[llength $args] == 1} {
209        #
210        # If this gauge has -units, try to convert the incoming
211        # value to that system of units.  Also, make sure that
212        # the value is bound by any min/max value constraints.
213        #
214        # Keep track of the inputted units so we can give a
215        # response about min and max values in familiar units.
216        #
217        set newval [set nv [string trim [lindex $args 0]]]
218        set units $itk_option(-units)
219        if {"" != $units} {
220            set newval [Rappture::Units::convert $newval -context $units]
221            set nvUnits [Rappture::Units::Search::for $newval]
222            if { "" == $nvUnits} {
223                set msg [Rappture::Units::description $units]
224                error "unrecognized units in value \"$newval\": should be value with units of $msg"
225            }
226            set nv [Rappture::Units::convert $nv \
227                -context $units -to $units -units off]
228
229            # Normalize the units name
230            set newval [Rappture::Units::convert $newval -units off]$nvUnits
231        }
232
233        switch -- $itk_option(-type) {
234            integer {
235                if { [scan $nv "%g" value] != 1 || int($nv) != $value } {
236                    error "bad value \"$nv\": should be an integer value"
237                }
238            }
239            real {
240                # "scan" will reject the number if the string is "NaN" or
241                # "Inf" or the empty string.  It also is accepts large numbers
242                # (e.g. 111111111111111111111) that "string is double"
243                # rejects.  The problem with "scan" is that it doesn't care if
244                # there are extra characters trailing the number (eg. "123a").
245                # The extra %s substitution is used to detect this case.
246                if { [scan $nv "%g%s" dummy1 dummy2] != 1 } {
247                    error "bad value \"$nv\": should be a real number"
248                }
249            }
250        }
251
252        if {"" != $itk_option(-minvalue)} {
253            set convMinVal [set minv $itk_option(-minvalue)]
254            if {"" != $units} {
255                set minv [Rappture::Units::convert $minv \
256                    -context $units -to $units -units off]
257                set convMinVal [Rappture::Units::convert \
258                    $itk_option(-minvalue) -context $units -to $nvUnits]
259            } else {
260                set newval [format "%g" $newval]
261            }
262
263            # fix for the case when the user tries to
264            # compare values like minv=-500 nv=-0600
265            set nv [format "%g" $nv]
266            set minv [format "%g" $minv]
267
268            if {$nv < $minv} {
269                error "minimum value allowed here is $convMinVal"
270            }
271        }
272
273        if {"" != $itk_option(-maxvalue)} {
274            set convMaxVal [set maxv $itk_option(-maxvalue)]
275            if {"" != $units} {
276                set maxv [Rappture::Units::convert $maxv \
277                    -context $units -to $units -units off]
278                set convMaxVal [Rappture::Units::convert \
279                    $itk_option(-maxvalue) -context $units -to $nvUnits]
280            } else {
281                set newval [format "%g" $newval]
282            }
283
284            # fix for the case when the user tries to
285            # compare values like maxv=500 nv=0600
286            set nv [format "%g" $nv]
287            set maxv [format "%g" $maxv]
288
289            if {$nv > $maxv} {
290                error "maximum value allowed here is $convMaxVal"
291            }
292        }
293
294        #
295        # If there's a -validatecommand option, then invoke the code
296        # now to check the new value.
297        #
298        if {[string length $itk_option(-validatecommand)] > 0} {
299            set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]"
300            set result [eval $cmd]
301        }
302
303        if {$onlycheck} {
304            return
305        }
306
307        set _value $newval
308
309        _redraw
310        event generate $itk_component(hull) <<Value>>
311
312    } elseif {[llength $args] != 0} {
313        error "wrong # args: should be \"value ?-check? ?newval?\""
314    }
315    return $_value
316}
317
318# ----------------------------------------------------------------------
319# USAGE: edit cut
320# USAGE: edit copy
321# USAGE: edit paste
322#
323# Used internally to handle cut/copy/paste operations for the current
324# value.  Usually invoked by <<Cut>>, <<Copy>>, <<Paste>> events, but
325# can also be called directly through this method.
326# ----------------------------------------------------------------------
327itcl::body Rappture::Gauge::edit {option} {
328    if {$itk_option(-state) == "disabled"} {
329        return  ;# disabled? then bail out here!
330    }
331    switch -- $option {
332        cut {
333            edit copy
334            _editor popup
335            $itk_component(editor) value ""
336            $itk_component(editor) deactivate
337        }
338        copy {
339            clipboard clear
340            clipboard append $_value
341        }
342        paste {
343            _editor popup
344            $itk_component(editor) value [clipboard get]
345            $itk_component(editor) deactivate
346        }
347        default {
348            error "bad option \"$option\": should be cut, copy, paste"
349        }
350    }
351}
352
353# ----------------------------------------------------------------------
354# USAGE: bump <delta>
355#
356# Changes the current value up/down by the <delta> value.  Used
357# internally by the up/down spinner buttons when the value is
358# -type integer.
359# ----------------------------------------------------------------------
360itcl::body Rappture::Gauge::bump {delta} {
361    set val $_value
362    if {$val == ""} {
363        set val 0
364    }
365    if {[catch {value [expr {$val+$delta}]} result]} {
366        if {[regexp {allowed here is (.+)} $result match newval]} {
367            set _value $newval
368            $itk_component(value) configure -text $newval
369        }
370        if {[regexp {^bad.*: +(.)(.+)} $result match first tail]
371              || [regexp {(.)(.+)} $result match first tail]} {
372            set result "[string toupper $first]$tail"
373        }
374        bell
375        Rappture::Tooltip::cue $itk_component(value) $result
376        _log warning $result
377        return 0
378    }
379    _log input [value]
380}
381
382# ----------------------------------------------------------------------
383# USAGE: _redraw
384#
385# Used internally to redraw the gauge on the internal canvas based
386# on the current value and the size of the widget.  In this simple
387# base class, the gauge is drawn as a colored block, with an optional
388# image in the middle of it.
389# ----------------------------------------------------------------------
390itcl::body Rappture::Gauge::_redraw {} {
391    set c $itk_component(icon)
392    set w [winfo width $c]
393    set h [winfo height $c]
394
395    if {"" == [$c find all]} {
396        # first time around, create the items
397        $c create rectangle 0 0 1 1 -outline black -tags block
398        $c create image 0 0 -anchor center -image "" -tags bimage
399        $c create rectangle 0 0 1 1 -outline "" -fill "" -stipple gray50 -tags screen
400    }
401
402    if {"" != $itk_option(-spectrum)} {
403        set color [$itk_option(-spectrum) get $_value]
404    } else {
405        set color ""
406    }
407
408    # update the items based on current values
409    $c coords block 0 0 [expr {$w-1}] [expr {$h-1}]
410    $c coords screen 0 0 $w $h
411    $c itemconfigure block -fill $color
412
413    $c coords bimage [expr {0.5*$w}] [expr {0.5*$h}]
414
415    if {$itk_option(-state) == "disabled"} {
416        $c itemconfigure screen -fill white
417    } else {
418        $c itemconfigure screen -fill ""
419    }
420}
421
422# ----------------------------------------------------------------------
423# USAGE: _resize
424#
425# Used internally to resize the internal canvas based on the -image
426# option or the size of the text.
427# ----------------------------------------------------------------------
428itcl::body Rappture::Gauge::_resize {} {
429    set w 0
430    set h 0
431
432    if {"" != $itk_option(-image) || "" != $itk_option(-spectrum)} {
433        if {$itk_option(-samplewidth) > 0} {
434            set w $itk_option(-samplewidth)
435        } else {
436            if {$itk_option(-image) != ""} {
437                set w [expr {[image width $itk_option(-image)]+4}]
438            } else {
439                set w [winfo reqheight $itk_component(value)]
440            }
441        }
442
443        if {$itk_option(-sampleheight) > 0} {
444            set h $itk_option(-sampleheight)
445        } else {
446            if {$itk_option(-image) != ""} {
447                set h [expr {[image height $itk_option(-image)]+4}]
448            } else {
449                set h [winfo reqheight $itk_component(value)]
450            }
451        }
452    }
453
454    if {$w > 0 && $h > 0} {
455        $itk_component(icon) configure -width $w -height $h
456    }
457}
458
459# ----------------------------------------------------------------------
460# USAGE: _hilite <component> <state>
461#
462# Used internally to resize the internal canvas based on the -image
463# option or the size of the text.
464# ----------------------------------------------------------------------
465itcl::body Rappture::Gauge::_hilite {comp state} {
466    if {$itk_option(-state) == "disabled"} {
467        set state 0  ;# disabled? then don't hilite
468    }
469    if {$comp == "value" && !$itk_option(-editable)} {
470        $itk_component(value) configure -relief flat
471        return
472    }
473
474    if {$state} {
475        $itk_component($comp) configure -relief flat
476    } else {
477        if {$comp eq "presets"} {
478            $itk_component($comp) configure -relief raised
479        } else {
480            $itk_component($comp) configure -relief flat
481        }
482    }
483}
484
485# ----------------------------------------------------------------------
486# USAGE: _editor popup
487# USAGE: _editor activate
488# USAGE: _editor validate <value>
489# USAGE: _editor apply <value>
490# USAGE: _editor menu <rootx> <rooty>
491#
492# Used internally to handle the various functions of the pop-up
493# editor for the value of this gauge.
494# ----------------------------------------------------------------------
495itcl::body Rappture::Gauge::_editor {option args} {
496    if {$itk_option(-state) == "disabled"} {
497        return  ;# disabled? then bail out here!
498    }
499    switch -- $option {
500        popup {
501            if {$itk_option(-editable)} {
502                $itk_component(editor) activate
503            }
504        }
505        activate {
506            return [list text $_value \
507                x [winfo rootx $itk_component(value)] \
508                y [winfo rooty $itk_component(value)] \
509                w [winfo width $itk_component(value)] \
510                h [winfo height $itk_component(value)]]
511        }
512        validate {
513            if {[llength $args] != 1} {
514                error "wrong # args: should be \"_editor validate val\""
515            }
516            set val [lindex $args 0]
517
518            if {[catch {value -check $val} result]} {
519                if {[regexp {allowed here is (.+)} $result match newval]} {
520                    $itk_component(editor) value $newval
521                }
522                if {[regexp {^bad.*: +(.)(.+)} $result match first tail]
523                      || [regexp {(.)(.+)} $result match first tail]} {
524                    set result "[string toupper $first]$tail"
525                }
526                bell
527                Rappture::Tooltip::cue $itk_component(editor) $result
528                _log warning $result
529                return 0
530            }
531        }
532        apply {
533            if {[llength $args] != 1} {
534                error "wrong # args: should be \"_editor apply val\""
535            }
536            set newval [lindex $args 0]
537            value $newval
538            _log input $newval
539        }
540        menu {
541            eval tk_popup $itk_component(emenu) $args
542        }
543        default {
544            error "bad option \"$option\": should be popup, activate, validate, apply, and menu"
545        }
546    }
547}
548
549# ----------------------------------------------------------------------
550# USAGE: _presets post
551# USAGE: _presets unpost
552# USAGE: _presets select
553#
554# Used internally to handle the list of presets for this gauge.  The
555# post/unpost options are invoked when the list is posted or unposted
556# to manage the relief of the controlling button.  The select option
557# is invoked whenever there is a selection from the list, to assign
558# the value back to the gauge.
559# ----------------------------------------------------------------------
560itcl::body Rappture::Gauge::_presets {option} {
561    switch -- $option {
562        post {
563            set i [$itk_component(presetlist) index $_value]
564            if {$i >= 0} {
565                $itk_component(presetlist) select clear 0 end
566                $itk_component(presetlist) select set $i
567            }
568            after 10 [list $itk_component(presets) configure -relief sunken]
569        }
570        unpost {
571            $itk_component(presets) configure -relief raised
572        }
573        select {
574            set val [$itk_component(presetlist) current]
575            if {"" != $val} {
576                value $val
577                _log input $val
578            }
579        }
580        default {
581            error "bad option \"$option\": should be post, unpost, select"
582        }
583    }
584}
585
586# ----------------------------------------------------------------------
587# USAGE: _layout
588#
589# Used internally to fix the layout of widgets whenever there is a
590# change in the options that affect layout.  Puts the value in the
591# proper position according to the -valueposition option.  Also,
592# adds or removes the icon if it needs to be shown.
593# ----------------------------------------------------------------------
594itcl::body Rappture::Gauge::_layout {} {
595    foreach w [pack slaves $itk_component(hull)] {
596        pack forget $w
597    }
598
599    array set side2anchor {
600        left   e
601        right  w
602        top    s
603        bottom n
604    }
605    set pos $itk_option(-valueposition)
606    pack $itk_component(vframe) -side $pos \
607        -expand yes -fill both -ipadx 2
608    $itk_component(value) configure -anchor $side2anchor($pos)
609
610    if {"" != $itk_option(-image) || "" != $itk_option(-spectrum)} {
611        pack $itk_component(icon) -side $pos -padx 2
612    }
613}
614
615# ----------------------------------------------------------------------
616# USAGE: _log event ?arg arg...?
617#
618# Used internally to send info to the logging mechanism.  If the -log
619# argument is set, then this calls the Rappture::Logger mechanism to
620# log the rest of the arguments as an action.  Otherwise, it does
621# nothing.
622# ----------------------------------------------------------------------
623itcl::body Rappture::Gauge::_log {event args} {
624    if {$itk_option(-log) ne ""} {
625        eval Rappture::Logger::log $event [list $itk_option(-log)] $args
626    }
627}
628
629# ----------------------------------------------------------------------
630# CONFIGURATION OPTION: -editable
631# ----------------------------------------------------------------------
632itcl::configbody Rappture::Gauge::editable {
633    if {![string is boolean -strict $itk_option(-editable)]} {
634        error "bad value \"$itk_option(-editable)\": should be boolean"
635    }
636    if {!$itk_option(-editable) && [winfo ismapped $itk_component(editor)]} {
637        $itk_component(editor) deactivate -abort
638    }
639}
640
641# ----------------------------------------------------------------------
642# CONFIGURATION OPTION: -state
643# ----------------------------------------------------------------------
644itcl::configbody Rappture::Gauge::state {
645    set valid {normal disabled}
646    if {[lsearch -exact $valid $itk_option(-state)] < 0} {
647        error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
648    }
649    $itk_component(value) configure -state $itk_option(-state)
650    $itk_component(spinup) configure -state $itk_option(-state)
651    $itk_component(spindn) configure -state $itk_option(-state)
652    $itk_component(presets) configure -state $itk_option(-state)
653    _redraw  ;# fix gauge
654}
655
656# ----------------------------------------------------------------------
657# CONFIGURATION OPTION: -spectrum
658# ----------------------------------------------------------------------
659itcl::configbody Rappture::Gauge::spectrum {
660    if {$itk_option(-spectrum) != ""
661          && ([catch {$itk_option(-spectrum) isa ::Rappture::Spectrum} valid]
662               || !$valid)} {
663        error "bad option \"$itk_option(-spectrum)\": should be Rappture::Spectrum object"
664    }
665    _resize
666    _layout
667    _redraw
668}
669
670# ----------------------------------------------------------------------
671# CONFIGURATION OPTION: -image
672# ----------------------------------------------------------------------
673itcl::configbody Rappture::Gauge::image {
674    if {$itk_option(-image) != ""
675          && [catch {image width $itk_option(-image)}]} {
676        error "bad value \"$itk_option(-image)\": should be Tk image"
677    }
678    _resize
679    _layout
680    $itk_component(icon) itemconfigure bimage -image $itk_option(-image)
681}
682
683# ----------------------------------------------------------------------
684# CONFIGURATION OPTION: -units
685# ----------------------------------------------------------------------
686itcl::configbody Rappture::Gauge::units {
687    if {$itk_option(-units) != ""
688          && [::Rappture::Units::System::for $itk_option(-units)] == ""} {
689        error "unrecognized system of units \"$itk_option(-units)\""
690    }
691}
692
693# ----------------------------------------------------------------------
694# CONFIGURATION OPTION: -valueposition
695# ----------------------------------------------------------------------
696itcl::configbody Rappture::Gauge::valueposition {
697    set pos $itk_option(-valueposition)
698    set opts {left right top bottom}
699    if {[lsearch -exact $opts $pos] < 0} {
700        error "bad value \"$pos\": should be [join $opts {, }]"
701    }
702    _layout
703}
704
705# ----------------------------------------------------------------------
706# CONFIGURATION OPTION: -presets
707# ----------------------------------------------------------------------
708itcl::configbody Rappture::Gauge::presets {
709    if {"" == $itk_option(-presets)} {
710        pack forget $itk_component(presets)
711    } else {
712        if {$itk_option(-valueposition) == "left"} {
713            set s "left"
714        } else {
715            set s "right"
716        }
717        set first [lindex [pack slaves $itk_component(vframe)] 0]
718        pack $itk_component(presets) -before $first -side $s -fill y
719
720        $itk_component(presetlist) delete 0 end
721        $itk_component(presetlist) insert end $itk_option(-presets)
722    }
723}
724
725# ----------------------------------------------------------------------
726# CONFIGURATION OPTION: -type
727# ----------------------------------------------------------------------
728itcl::configbody Rappture::Gauge::type {
729    switch -- $itk_option(-type) {
730        integer {
731            set first [lindex [pack slaves $itk_component(vframe)] 0]
732            if {$first == $itk_component(presets)} {
733                pack $itk_component(spinner) -after $first -side left -fill y
734            } else {
735                pack $itk_component(spinner) -before $first -side right -fill y
736            }
737        }
738        real {
739            pack forget $itk_component(spinner)
740        }
741        default {
742            error "bad number type \"$itk_option(-type)\": should be integer or real"
743        }
744    }
745}
Note: See TracBrowser for help on using the repository browser.