Changeset 1850 for trunk/gui


Ignore:
Timestamp:
Jul 30, 2010, 8:34:57 AM (14 years ago)
Author:
dkearney
Message:

adding perl wrapper example to configure and make scripts

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/editor.tcl

    r1342 r1850  
    5858    protected variable _loc   ;# array of editor location parameters
    5959}
    60                                                                                
     60                                                                               
    6161itk::usual Editor {
    6262    keep -cursor -font
     
    7474
    7575    itk_component add editor {
    76         entry $itk_interior.editor -highlightthickness 0
     76        entry $itk_interior.editor -highlightthickness 0
    7777    } {
    78         usual
    79         keep -relief
    80         ignore -highlightthickness
    81         ignore -highlightcolor
    82         ignore -highlightbackground
     78        usual
     79        keep -relief
     80        ignore -highlightthickness
     81        ignore -highlightcolor
     82        ignore -highlightbackground
    8383    }
    8484    pack $itk_component(editor) -expand yes -fill both
    8585
    8686    bind $itk_component(editor) <KeyPress> \
    87         [itcl::code $this _resize]
     87        [itcl::code $this _resize]
    8888    bind $itk_component(editor) <KeyPress-Return> \
    89         [itcl::code $this deactivate]
     89        [itcl::code $this deactivate]
    9090    bind $itk_component(editor) <KeyPress-Escape> \
    91         [itcl::code $this deactivate -abort]
     91        [itcl::code $this deactivate -abort]
    9292    bind $itk_component(editor) <ButtonPress> \
    93         [itcl::code $this _click %X %Y]
     93        [itcl::code $this _click %X %Y]
    9494
    9595    itk_component add emenu {
    96         menu $itk_component(editor).menu -tearoff 0
     96        menu $itk_component(editor).menu -tearoff 0
    9797    } {
    98         usual
    99         ignore -tearoff
    100         ignore -background -foreground
     98        usual
     99        ignore -tearoff
     100        ignore -background -foreground
    101101    }
    102102    $itk_component(emenu) add command -label "Cut" -accelerator "^X" \
    103         -command [list event generate $itk_component(editor) <<Cut>>]
     103        -command [list event generate $itk_component(editor) <<Cut>>]
    104104    $itk_component(emenu) add command -label "Copy" -accelerator "^C" \
    105         -command [list event generate $itk_component(editor) <<Copy>>]
     105        -command [list event generate $itk_component(editor) <<Copy>>]
    106106    $itk_component(emenu) add command -label "Paste" -accelerator "^V" \
    107         -command [list event generate $itk_component(editor) <<Paste>>]
     107        -command [list event generate $itk_component(editor) <<Paste>>]
    108108    bind $itk_component(editor) <<PopupMenu>> {
    109         tk_popup %W.menu %X %Y
     109        tk_popup %W.menu %X %Y
    110110    }
    111111
     
    124124    set e $itk_component(editor)
    125125    if {[winfo ismapped $e]} {
    126         return  ;# already mapped -- nothing to do
     126        return  ;# already mapped -- nothing to do
    127127    }
    128128
    129129    set info ""
    130130    if {[string length $itk_option(-activatecommand)] > 0} {
    131         set status [catch {uplevel #0 $itk_option(-activatecommand)} info]
    132         if {$status != 0} {
    133             bgerror $info
    134             return
    135         }
     131        set status [catch {uplevel #0 $itk_option(-activatecommand)} info]
     132        if {$status != 0} {
     133            bgerror $info
     134            return
     135        }
    136136    }
    137137
     
    145145    array set vals $info
    146146    if {![info exists vals(x)] || ![info exists vals(y)]} {
    147         return
     147        return
    148148    }
    149149    set _loc(x) $vals(x)
     
    154154    $itk_component(editor) delete 0 end
    155155    if {[info exists vals(text)]} {
    156         $itk_component(editor) insert end $vals(text)
     156        $itk_component(editor) insert end $vals(text)
    157157    }
    158158    $itk_component(editor) select from 0
     
    167167    update
    168168    while {[catch {grab set -global $itk_component(editor)}]} {
    169         after 100
     169        after 100
    170170    }
    171171}
     
    188188
    189189    if {$args == "-abort"} {
    190         grab release $itk_component(editor)
    191         wm withdraw $itk_component(hull)
    192         return
     190        grab release $itk_component(editor)
     191        wm withdraw $itk_component(hull)
     192        return
    193193    }
    194194
     
    200200    #
    201201    if {[string length $itk_option(-validatecommand)] > 0} {
    202         set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $str]]"
    203         if {[catch $cmd result]} {
    204             bgerror $result
    205             set result 1
    206         }
    207         if {$result == 0} {
    208             bell
    209             $itk_component(editor) select from 0
    210             $itk_component(editor) select to end
    211             $itk_component(editor) icursor end
    212             focus $itk_component(editor)
    213             return
    214         }
     202        set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $str]]"
     203        if {[catch $cmd result]} {
     204            bgerror $result
     205            set result 1
     206        }
     207        if {$result == 0} {
     208            bell
     209            $itk_component(editor) select from 0
     210            $itk_component(editor) select to end
     211            $itk_component(editor) icursor end
     212            focus $itk_component(editor)
     213            return
     214        }
    215215    }
    216216
     
    223223    #
    224224    if {[string length $itk_option(-applycommand)] > 0} {
    225         set cmd "uplevel #0 [list $itk_option(-applycommand) [list $str]]"
    226         if {[catch $cmd result]} {
    227             bgerror $result
    228             return
    229         }
     225        set cmd "uplevel #0 [list $itk_option(-applycommand) [list $str]]"
     226        if {[catch $cmd result]} {
     227            bgerror $result
     228            return
     229        }
    230230    }
    231231}
     
    255255itcl::body Rappture::Editor::_click {x y} {
    256256    if {[winfo containing $x $y] != $itk_component(editor)} {
    257         deactivate
     257        deactivate
    258258    } else {
    259         # make sure the editor has keyboard focus!
    260         # it loses focus sometimes during cut/copy/paste operations
    261         focus -force $itk_component(editor)
     259        # make sure the editor has keyboard focus!
     260        # it loses focus sometimes during cut/copy/paste operations
     261        focus -force $itk_component(editor)
    262262    }
    263263}
     
    278278    set w [expr {($w < $_loc(w)) ? $_loc(w) : $w}]
    279279    if {$w+$_loc(x) >= [winfo screenwidth $e]} {
    280         set w [expr {[winfo screenwidth $e]-$_loc(x)}]
     280        set w [expr {[winfo screenwidth $e]-$_loc(x)}]
    281281    }
    282282
     
    284284    set h [expr {($h < $_loc(h)) ? $_loc(h) : $h}]
    285285    if {$h+$_loc(y) >= [winfo screenheight $e]} {
    286         set h [expr {[winfo screenheight $e]-$_loc(y)}]
    287     }                                   
     286        set h [expr {[winfo screenheight $e]-$_loc(y)}]
     287    }                                       
    288288    # Temporary fix to prevent Opps. Don't deal with negative dimensions.
    289289    if { $w <= 0 || $h <= 0 } {
    290         wm geometry $itk_component(hull) "+$_loc(x)+$_loc(y)"
     290        wm geometry $itk_component(hull) "+$_loc(x)+$_loc(y)"
    291291    } else {
    292         wm geometry $itk_component(hull) "${w}x${h}+$_loc(x)+$_loc(y)"
     292        wm geometry $itk_component(hull) "${w}x${h}+$_loc(x)+$_loc(y)"
    293293    }
    294294}
  • trunk/gui/scripts/gauge.tcl

    r1483 r1850  
    5555
    5656    blt::bitmap define GaugeArrow-up {
    57         #define up_width 8
    58         #define up_height 4
    59         static unsigned char up_bits[] = {
    60            0x10, 0x38, 0x7c, 0xfe};
     57        #define up_width 8
     58        #define up_height 4
     59        static unsigned char up_bits[] = {
     60           0x10, 0x38, 0x7c, 0xfe};
    6161    }
    6262    blt::bitmap define GaugeArrow-down {
    63         #define arrow_width 8
    64         #define arrow_height 4
    65         static unsigned char arrow_bits[] = {
    66            0xfe, 0x7c, 0x38, 0x10};
     63        #define arrow_width 8
     64        #define arrow_height 4
     65        static unsigned char arrow_bits[] = {
     66           0xfe, 0x7c, 0x38, 0x10};
    6767    }
    6868
    6969    blt::bitmap define GaugeArrow {
    70         #define arrow_width 9
    71         #define arrow_height 4
    72         static unsigned char arrow_bits[] = {
    73            0x7f, 0x00, 0x3e, 0x00, 0x1c, 0x00, 0x08, 0x00};
    74     }
    75 }
    76                                                                                
     70        #define arrow_width 9
     71        #define arrow_height 4
     72        static unsigned char arrow_bits[] = {
     73           0x7f, 0x00, 0x3e, 0x00, 0x1c, 0x00, 0x08, 0x00};
     74    }
     75}
     76                                                                               
    7777itk::usual Gauge {
    7878    keep -cursor -font -foreground -background
     
    8585itcl::body Rappture::Gauge::constructor {args} {
    8686    itk_component add icon {
    87         canvas $itk_interior.icon -width 1 -height 1 \
    88             -borderwidth 0 -highlightthickness 0
     87        canvas $itk_interior.icon -width 1 -height 1 \
     88            -borderwidth 0 -highlightthickness 0
    8989    } {
    90         usual
    91         ignore -highlightthickness -highlightbackground -highlightcolor
     90        usual
     91        ignore -highlightthickness -highlightbackground -highlightcolor
    9292    }
    9393    pack $itk_component(icon) -side left
     
    9595
    9696    itk_component add -protected vframe {
    97         frame $itk_interior.vframe
     97        frame $itk_interior.vframe
    9898    }
    9999
    100100    itk_component add value {
    101         label $itk_component(vframe).value -borderwidth 1 -width 7 \
    102             -textvariable [itcl::scope _value]
     101        label $itk_component(vframe).value -borderwidth 1 -width 7 \
     102            -textvariable [itcl::scope _value]
    103103    } {
    104         rename -background -textbackground textBackground Background
     104        rename -background -textbackground textBackground Background
    105105    }
    106106    pack $itk_component(value) -side left -expand yes -fill both
     
    114114
    115115    itk_component add emenu {
    116         menu $itk_component(value).menu -tearoff 0
     116        menu $itk_component(value).menu -tearoff 0
    117117    } {
    118         usual
    119         ignore -tearoff
     118        usual
     119        ignore -tearoff
    120120    }
    121121    $itk_component(emenu) add command -label "Cut" -accelerator "^X" \
    122         -command [list event generate $itk_component(value) <<Cut>>]
     122        -command [list event generate $itk_component(value) <<Cut>>]
    123123    $itk_component(emenu) add command -label "Copy" -accelerator "^C" \
    124         -command [list event generate $itk_component(value) <<Copy>>]
     124        -command [list event generate $itk_component(value) <<Copy>>]
    125125    $itk_component(emenu) add command -label "Paste" -accelerator "^V" \
    126         -command [list event generate $itk_component(value) <<Paste>>]
     126        -command [list event generate $itk_component(value) <<Paste>>]
    127127    bind $itk_component(value) <<PopupMenu>> \
    128         [itcl::code $this _editor menu %X %Y]
     128        [itcl::code $this _editor menu %X %Y]
    129129
    130130    itk_component add editor {
    131         Rappture::Editor $itk_interior.editor \
    132             -activatecommand [itcl::code $this _editor activate] \
    133             -validatecommand [itcl::code $this _editor validate] \
    134             -applycommand [itcl::code $this _editor apply]
     131        Rappture::Editor $itk_interior.editor \
     132            -activatecommand [itcl::code $this _editor activate] \
     133            -validatecommand [itcl::code $this _editor validate] \
     134            -applycommand [itcl::code $this _editor apply]
    135135    }
    136136    bind $itk_component(value) <ButtonPress> \
    137         [itcl::code $this _editor popup]
     137        [itcl::code $this _editor popup]
    138138
    139139
    140140    itk_component add spinner {
    141         frame $itk_component(vframe).spinner
     141        frame $itk_component(vframe).spinner
    142142    }
    143143
    144144    itk_component add spinup {
    145         button $itk_component(spinner).up -bitmap GaugeArrow-up \
    146             -borderwidth 1 -relief raised -highlightthickness 0 \
    147             -command [itcl::code $this bump 1]
     145        button $itk_component(spinner).up -bitmap GaugeArrow-up \
     146            -borderwidth 1 -relief raised -highlightthickness 0 \
     147            -command [itcl::code $this bump 1]
    148148    } {
    149         usual
    150         ignore -borderwidth -highlightthickness
     149        usual
     150        ignore -borderwidth -highlightthickness
    151151    }
    152152    pack $itk_component(spinup) -side top -expand yes -fill both
    153153
    154154    itk_component add spindn {
    155         button $itk_component(spinner).down -bitmap GaugeArrow-down \
    156             -borderwidth 1 -relief raised -highlightthickness 0 \
    157             -command [itcl::code $this bump -1]
     155        button $itk_component(spinner).down -bitmap GaugeArrow-down \
     156            -borderwidth 1 -relief raised -highlightthickness 0 \
     157            -command [itcl::code $this bump -1]
    158158    } {
    159         usual
    160         ignore -borderwidth -highlightthickness
     159        usual
     160        ignore -borderwidth -highlightthickness
    161161    }
    162162    pack $itk_component(spindn) -side bottom -expand yes -fill both
     
    164164
    165165    itk_component add presets {
    166         button $itk_component(vframe).psbtn -bitmap GaugeArrow \
    167             -borderwidth 1 -highlightthickness 0 -relief flat
     166        button $itk_component(vframe).psbtn -bitmap GaugeArrow \
     167            -borderwidth 1 -highlightthickness 0 -relief flat
    168168    } {
    169         usual
    170         ignore -borderwidth -relief -highlightthickness
    171         rename -background -textbackground textBackground Background
     169        usual
     170        ignore -borderwidth -relief -highlightthickness
     171        rename -background -textbackground textBackground Background
    172172    }
    173173
     
    176176
    177177    itk_component add presetlist {
    178         Rappture::Dropdownlist $itk_component(presets).plist \
    179             -postcommand [itcl::code $this _presets post] \
    180             -unpostcommand [itcl::code $this _presets unpost] \
     178        Rappture::Dropdownlist $itk_component(presets).plist \
     179            -postcommand [itcl::code $this _presets post] \
     180            -unpostcommand [itcl::code $this _presets unpost] \
    181181    }
    182182
    183183    bind $itk_component(presetlist) <<DropdownlistSelect>> \
    184         [itcl::code $this _presets select]
     184        [itcl::code $this _presets select]
    185185
    186186    $itk_component(presets) configure -command \
    187         [list $itk_component(presetlist) post $itk_component(vframe) left]
     187        [list $itk_component(presetlist) post $itk_component(vframe) left]
    188188
    189189    eval itk_initialize $args
     
    203203    set i [lsearch -exact $args -check]
    204204    if {$i >= 0} {
    205         set onlycheck 1
    206         set args [lreplace $args $i $i]
     205        set onlycheck 1
     206        set args [lreplace $args $i $i]
    207207    }
    208208
    209209    if {[llength $args] == 1} {
    210         #
    211         # If this gauge has -units, try to convert the incoming
    212         # value to that system of units.  Also, make sure that
    213         # the value is bound by any min/max value constraints.
    214         #
    215         # Keep track of the inputted units so we can give a
    216         # response about min and max values in familiar units.
    217         #
    218         set newval [set nv [lindex $args 0]]
    219         set units $itk_option(-units)
    220         if {"" != $units} {
    221             set newval [Rappture::Units::convert $newval -context $units]
    222             set nvUnits [Rappture::Units::Search::for $newval]
    223             if { "" == $nvUnits} {
    224                 set msg [Rappture::Units::description $units]
    225                 error "Unrecognized units: $newval\nEnter value with units of $msg"
    226             }
    227             set nv [Rappture::Units::convert $nv \
    228                 -context $units -to $units -units off]
    229 
    230             # Normalize the units name
    231             set newval [Rappture::Units::convert $newval -units off]$nvUnits
    232         }
    233 
    234         switch -- $itk_option(-type) {
    235             integer {
    236                 if { [scan $nv "%g" value] != 1 || int($nv) != $value } {
    237                     error "bad value \"$nv\": should be an integer value"
    238                 }
    239             }
    240             real {
    241                 if {[string length $nv] <= 0
    242                       || ![string is double $nv]
    243                       || [regexp -nocase {^(inf|nan)$} $nv]} {
    244                     error "bad value \"$nv\": should be a real number"
    245                 }
    246             }
    247         }
    248 
    249         if {"" != $itk_option(-minvalue)} {
    250             set convMinVal [set minv $itk_option(-minvalue)]
    251             if {"" != $units} {
    252                 set minv [Rappture::Units::convert $minv \
    253                     -context $units -to $units -units off]
    254                 set convMinVal [Rappture::Units::convert \
    255                     $itk_option(-minvalue) -context $units -to $nvUnits]
    256             } else {
    257                 set newval [format "%g" $newval]
    258             }
    259 
    260             # fix for the case when the user tries to
    261             # compare values like minv=-500 nv=-0600
    262             set nv [format "%g" $nv]
    263             set minv [format "%g" $minv]
    264 
    265             if {$nv < $minv} {
    266                 error "minimum value allowed here is $convMinVal"
    267             }
    268         }
    269 
    270         if {"" != $itk_option(-maxvalue)} {
    271             set convMaxVal [set maxv $itk_option(-maxvalue)]
    272             if {"" != $units} {
    273                 set maxv [Rappture::Units::convert $maxv \
    274                     -context $units -to $units -units off]
    275                 set convMaxVal [Rappture::Units::convert \
    276                     $itk_option(-maxvalue) -context $units -to $nvUnits]
    277             } else {
    278                 set newval [format "%g" $newval]
    279             }
    280 
    281             # fix for the case when the user tries to
    282             # compare values like maxv=500 nv=0600
    283             set nv [format "%g" $nv]
    284             set maxv [format "%g" $maxv]
    285 
    286             if {$nv > $maxv} {
    287                 error "maximum value allowed here is $convMaxVal"
    288             }
    289         }
    290 
    291         if {$onlycheck} {
    292             return
    293         }
    294 
    295         set _value $newval
    296 
    297         _redraw
    298         event generate $itk_component(hull) <<Value>>
     210        #
     211        # If this gauge has -units, try to convert the incoming
     212        # value to that system of units.  Also, make sure that
     213        # the value is bound by any min/max value constraints.
     214        #
     215        # Keep track of the inputted units so we can give a
     216        # response about min and max values in familiar units.
     217        #
     218        set newval [set nv [lindex $args 0]]
     219        set units $itk_option(-units)
     220        if {"" != $units} {
     221            set newval [Rappture::Units::convert $newval -context $units]
     222            set nvUnits [Rappture::Units::Search::for $newval]
     223            if { "" == $nvUnits} {
     224                set msg [Rappture::Units::description $units]
     225                error "Unrecognized units: $newval\nEnter value with units of $msg"
     226            }
     227            set nv [Rappture::Units::convert $nv \
     228                -context $units -to $units -units off]
     229
     230            # Normalize the units name
     231            set newval [Rappture::Units::convert $newval -units off]$nvUnits
     232        }
     233
     234        switch -- $itk_option(-type) {
     235            integer {
     236                if { [scan $nv "%g" value] != 1 || int($nv) != $value } {
     237                    error "bad value \"$nv\": should be an integer value"
     238                }
     239            }
     240            real {
     241                if {[string length $nv] <= 0
     242                      || ![string is double $nv]
     243                      || [regexp -nocase {^(inf|nan)$} $nv]} {
     244                    error "bad value \"$nv\": should be a real number"
     245                }
     246            }
     247        }
     248
     249        if {"" != $itk_option(-minvalue)} {
     250            set convMinVal [set minv $itk_option(-minvalue)]
     251            if {"" != $units} {
     252                set minv [Rappture::Units::convert $minv \
     253                    -context $units -to $units -units off]
     254                set convMinVal [Rappture::Units::convert \
     255                    $itk_option(-minvalue) -context $units -to $nvUnits]
     256            } else {
     257                set newval [format "%g" $newval]
     258            }
     259
     260            # fix for the case when the user tries to
     261            # compare values like minv=-500 nv=-0600
     262            set nv [format "%g" $nv]
     263            set minv [format "%g" $minv]
     264
     265            if {$nv < $minv} {
     266                error "minimum value allowed here is $convMinVal"
     267            }
     268        }
     269
     270        if {"" != $itk_option(-maxvalue)} {
     271            set convMaxVal [set maxv $itk_option(-maxvalue)]
     272            if {"" != $units} {
     273                set maxv [Rappture::Units::convert $maxv \
     274                    -context $units -to $units -units off]
     275                set convMaxVal [Rappture::Units::convert \
     276                    $itk_option(-maxvalue) -context $units -to $nvUnits]
     277            } else {
     278                set newval [format "%g" $newval]
     279            }
     280
     281            # fix for the case when the user tries to
     282            # compare values like maxv=500 nv=0600
     283            set nv [format "%g" $nv]
     284            set maxv [format "%g" $maxv]
     285
     286            if {$nv > $maxv} {
     287                error "maximum value allowed here is $convMaxVal"
     288            }
     289        }
     290
     291        if {$onlycheck} {
     292            return
     293        }
     294
     295        set _value $newval
     296
     297        _redraw
     298        event generate $itk_component(hull) <<Value>>
    299299
    300300    } elseif {[llength $args] != 0} {
    301         error "wrong # args: should be \"value ?-check? ?newval?\""
     301        error "wrong # args: should be \"value ?-check? ?newval?\""
    302302    }
    303303    return $_value
     
    315315itcl::body Rappture::Gauge::edit {option} {
    316316    if {$itk_option(-state) == "disabled"} {
    317         return  ;# disabled? then bail out here!
     317        return  ;# disabled? then bail out here!
    318318    }
    319319    switch -- $option {
    320         cut {
    321             edit copy
    322             _editor popup
    323             $itk_component(editor) value ""
    324             $itk_component(editor) deactivate
    325         }
    326         copy {
    327             clipboard clear
    328             clipboard append $_value
    329         }
    330         paste {
    331             _editor popup
    332             $itk_component(editor) value [clipboard get]
    333             $itk_component(editor) deactivate
    334         }
    335         default {
    336             error "bad option \"$option\": should be cut, copy, paste"
    337         }
     320        cut {
     321            edit copy
     322            _editor popup
     323            $itk_component(editor) value ""
     324            $itk_component(editor) deactivate
     325        }
     326        copy {
     327            clipboard clear
     328            clipboard append $_value
     329        }
     330        paste {
     331            _editor popup
     332            $itk_component(editor) value [clipboard get]
     333            $itk_component(editor) deactivate
     334        }
     335        default {
     336            error "bad option \"$option\": should be cut, copy, paste"
     337        }
    338338    }
    339339}
     
    349349    set val $_value
    350350    if {$val == ""} {
    351         set val 0
     351        set val 0
    352352    }
    353353    if {[catch {value [expr {$val+$delta}]} result]} {
    354         if {[regexp {allowed here is (.+)} $result match newval]} {
    355             set _value $newval
    356             $itk_component(value) configure -text $newval
    357         }
    358         if {[regexp {^bad.*: +(.)(.+)} $result match first tail]
    359               || [regexp {(.)(.+)} $result match first tail]} {
    360             set result "[string toupper $first]$tail"
    361         }
    362         bell
    363         Rappture::Tooltip::cue $itk_component(value) $result
    364         return 0
     354        if {[regexp {allowed here is (.+)} $result match newval]} {
     355            set _value $newval
     356            $itk_component(value) configure -text $newval
     357        }
     358        if {[regexp {^bad.*: +(.)(.+)} $result match first tail]
     359              || [regexp {(.)(.+)} $result match first tail]} {
     360            set result "[string toupper $first]$tail"
     361        }
     362        bell
     363        Rappture::Tooltip::cue $itk_component(value) $result
     364        return 0
    365365    }
    366366}
     
    380380
    381381    if {"" == [$c find all]} {
    382         # first time around, create the items
    383         $c create rectangle 0 0 1 1 -outline black -tags block
    384         $c create image 0 0 -anchor center -image "" -tags bimage
    385         $c create rectangle 0 0 1 1 -outline "" -fill "" -stipple gray50 -tags screen
     382        # first time around, create the items
     383        $c create rectangle 0 0 1 1 -outline black -tags block
     384        $c create image 0 0 -anchor center -image "" -tags bimage
     385        $c create rectangle 0 0 1 1 -outline "" -fill "" -stipple gray50 -tags screen
    386386    }
    387387
    388388    if {"" != $itk_option(-spectrum)} {
    389         set color [$itk_option(-spectrum) get $_value]
     389        set color [$itk_option(-spectrum) get $_value]
    390390    } else {
    391         set color ""
     391        set color ""
    392392    }
    393393
     
    400400
    401401    if {$itk_option(-state) == "disabled"} {
    402         $c itemconfigure screen -fill white
     402        $c itemconfigure screen -fill white
    403403    } else {
    404         $c itemconfigure screen -fill ""
     404        $c itemconfigure screen -fill ""
    405405    }
    406406}
     
    417417
    418418    if {"" != $itk_option(-image) || "" != $itk_option(-spectrum)} {
    419         if {$itk_option(-samplewidth) > 0} {
    420             set w $itk_option(-samplewidth)
    421         } else {
    422             if {$itk_option(-image) != ""} {
    423                 set w [expr {[image width $itk_option(-image)]+4}]
    424             } else {
    425                 set w [winfo reqheight $itk_component(value)]
    426             }
    427         }
    428 
    429         if {$itk_option(-sampleheight) > 0} {
    430             set h $itk_option(-sampleheight)
    431         } else {
    432             if {$itk_option(-image) != ""} {
    433                 set h [expr {[image height $itk_option(-image)]+4}]
    434             } else {
    435                 set h [winfo reqheight $itk_component(value)]
    436             }
    437         }
     419        if {$itk_option(-samplewidth) > 0} {
     420            set w $itk_option(-samplewidth)
     421        } else {
     422            if {$itk_option(-image) != ""} {
     423                set w [expr {[image width $itk_option(-image)]+4}]
     424            } else {
     425                set w [winfo reqheight $itk_component(value)]
     426            }
     427        }
     428
     429        if {$itk_option(-sampleheight) > 0} {
     430            set h $itk_option(-sampleheight)
     431        } else {
     432            if {$itk_option(-image) != ""} {
     433                set h [expr {[image height $itk_option(-image)]+4}]
     434            } else {
     435                set h [winfo reqheight $itk_component(value)]
     436            }
     437        }
    438438    }
    439439
    440440    if {$w > 0 && $h > 0} {
    441         $itk_component(icon) configure -width $w -height $h
     441        $itk_component(icon) configure -width $w -height $h
    442442    }
    443443}
     
    451451itcl::body Rappture::Gauge::_hilite {comp state} {
    452452    if {$itk_option(-state) == "disabled"} {
    453         set state 0  ;# disabled? then don't hilite
     453        set state 0  ;# disabled? then don't hilite
    454454    }
    455455    if {$comp == "value" && !$itk_option(-editable)} {
    456         $itk_component(value) configure -relief flat
    457         return
     456        $itk_component(value) configure -relief flat
     457        return
    458458    }
    459459
    460460    if {$state} {
    461         $itk_component($comp) configure -relief solid
     461        $itk_component($comp) configure -relief solid
    462462    } else {
    463         $itk_component($comp) configure -relief flat
     463        $itk_component($comp) configure -relief flat
    464464    }
    465465}
     
    477477itcl::body Rappture::Gauge::_editor {option args} {
    478478    if {$itk_option(-state) == "disabled"} {
    479         return  ;# disabled? then bail out here!
     479        return  ;# disabled? then bail out here!
    480480    }
    481481    switch -- $option {
    482         popup {
    483             if {$itk_option(-editable)} {
    484                 $itk_component(editor) activate
    485             }
    486         }
    487         activate {
    488             return [list text $_value \
    489                 x [winfo rootx $itk_component(value)] \
    490                 y [winfo rooty $itk_component(value)] \
    491                 w [winfo width $itk_component(value)] \
    492                 h [winfo height $itk_component(value)]]
    493         }
    494         validate {
    495             if {[llength $args] != 1} {
    496                 error "wrong # args: should be \"_editor validate val\""
    497             }
    498             set val [lindex $args 0]
    499 
    500             if {[catch {value -check $val} result]} {
    501                 if {[regexp {allowed here is (.+)} $result match newval]} {
    502                     $itk_component(editor) value $newval
    503                 }
    504                 if {[regexp {^bad.*: +(.)(.+)} $result match first tail]
    505                       || [regexp {(.)(.+)} $result match first tail]} {
    506                     set result "[string toupper $first]$tail"
    507                 }
    508                 bell
    509                 Rappture::Tooltip::cue $itk_component(editor) $result
    510                 return 0
    511             }
    512         }
    513         apply {
    514             if {[llength $args] != 1} {
    515                 error "wrong # args: should be \"_editor apply val\""
    516             }
    517             value [lindex $args 0]
    518         }
    519         menu {
    520             eval tk_popup $itk_component(emenu) $args
    521         }
    522         default {
    523             error "bad option \"$option\": should be popup, activate, validate, apply, and menu"
    524         }
     482        popup {
     483            if {$itk_option(-editable)} {
     484                $itk_component(editor) activate
     485            }
     486        }
     487        activate {
     488            return [list text $_value \
     489                x [winfo rootx $itk_component(value)] \
     490                y [winfo rooty $itk_component(value)] \
     491                w [winfo width $itk_component(value)] \
     492                h [winfo height $itk_component(value)]]
     493        }
     494        validate {
     495            if {[llength $args] != 1} {
     496                error "wrong # args: should be \"_editor validate val\""
     497            }
     498            set val [lindex $args 0]
     499
     500            if {[catch {value -check $val} result]} {
     501                if {[regexp {allowed here is (.+)} $result match newval]} {
     502                    $itk_component(editor) value $newval
     503                }
     504                if {[regexp {^bad.*: +(.)(.+)} $result match first tail]
     505                      || [regexp {(.)(.+)} $result match first tail]} {
     506                    set result "[string toupper $first]$tail"
     507                }
     508                bell
     509                Rappture::Tooltip::cue $itk_component(editor) $result
     510                return 0
     511            }
     512        }
     513        apply {
     514            if {[llength $args] != 1} {
     515                error "wrong # args: should be \"_editor apply val\""
     516            }
     517            value [lindex $args 0]
     518        }
     519        menu {
     520            eval tk_popup $itk_component(emenu) $args
     521        }
     522        default {
     523            error "bad option \"$option\": should be popup, activate, validate, apply, and menu"
     524        }
    525525    }
    526526}
     
    539539itcl::body Rappture::Gauge::_presets {option} {
    540540    switch -- $option {
    541         post {
    542             set i [$itk_component(presetlist) index $_value]
    543             if {$i >= 0} {
    544                 $itk_component(presetlist) select clear 0 end
    545                 $itk_component(presetlist) select set $i
    546             }
    547             after 10 [list $itk_component(presets) configure -relief sunken]
    548         }
    549         unpost {
    550             $itk_component(presets) configure -relief flat
    551         }
    552         select {
    553             set val [$itk_component(presetlist) current]
    554             if {"" != $val} {
    555                 value $val
    556             }
    557         }
    558         default {
    559             error "bad option \"$option\": should be post, unpost, select"
    560         }
     541        post {
     542            set i [$itk_component(presetlist) index $_value]
     543            if {$i >= 0} {
     544                $itk_component(presetlist) select clear 0 end
     545                $itk_component(presetlist) select set $i
     546            }
     547            after 10 [list $itk_component(presets) configure -relief sunken]
     548        }
     549        unpost {
     550            $itk_component(presets) configure -relief flat
     551        }
     552        select {
     553            set val [$itk_component(presetlist) current]
     554            if {"" != $val} {
     555                value $val
     556            }
     557        }
     558        default {
     559            error "bad option \"$option\": should be post, unpost, select"
     560        }
    561561    }
    562562}
     
    572572itcl::body Rappture::Gauge::_layout {} {
    573573    foreach w [pack slaves $itk_component(hull)] {
    574         pack forget $w
     574        pack forget $w
    575575    }
    576576
    577577    array set side2anchor {
    578         left   e
    579         right  w
    580         top    s
    581         bottom n
     578        left   e
     579        right  w
     580        top    s
     581        bottom n
    582582    }
    583583    set pos $itk_option(-valueposition)
    584584    pack $itk_component(vframe) -side $pos \
    585         -expand yes -fill both -ipadx 2
     585        -expand yes -fill both -ipadx 2
    586586    $itk_component(value) configure -anchor $side2anchor($pos)
    587587
    588588    if {"" != $itk_option(-image) || "" != $itk_option(-spectrum)} {
    589         pack $itk_component(icon) -side $pos
     589        pack $itk_component(icon) -side $pos
    590590    }
    591591}
     
    596596itcl::configbody Rappture::Gauge::editable {
    597597    if {![string is boolean -strict $itk_option(-editable)]} {
    598         error "bad value \"$itk_option(-editable)\": should be boolean"
     598        error "bad value \"$itk_option(-editable)\": should be boolean"
    599599    }
    600600    if {!$itk_option(-editable) && [winfo ismapped $itk_component(editor)]} {
    601         $itk_component(editor) deactivate -abort
     601        $itk_component(editor) deactivate -abort
    602602    }
    603603}
     
    609609    set valid {normal disabled}
    610610    if {[lsearch -exact $valid $itk_option(-state)] < 0} {
    611         error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
     611        error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
    612612    }
    613613    $itk_component(value) configure -state $itk_option(-state)
     
    623623itcl::configbody Rappture::Gauge::spectrum {
    624624    if {$itk_option(-spectrum) != ""
    625           && ([catch {$itk_option(-spectrum) isa ::Rappture::Spectrum} valid]
    626                || !$valid)} {
    627         error "bad option \"$itk_option(-spectrum)\": should be Rappture::Spectrum object"
     625          && ([catch {$itk_option(-spectrum) isa ::Rappture::Spectrum} valid]
     626               || !$valid)} {
     627        error "bad option \"$itk_option(-spectrum)\": should be Rappture::Spectrum object"
    628628    }
    629629    _resize
     
    637637itcl::configbody Rappture::Gauge::image {
    638638    if {$itk_option(-image) != ""
    639           && [catch {image width $itk_option(-image)}]} {
    640         error "bad value \"$itk_option(-image)\": should be Tk image"
     639          && [catch {image width $itk_option(-image)}]} {
     640        error "bad value \"$itk_option(-image)\": should be Tk image"
    641641    }
    642642    _resize
     
    650650itcl::configbody Rappture::Gauge::units {
    651651    if {$itk_option(-units) != ""
    652           && [::Rappture::Units::System::for $itk_option(-units)] == ""} {
    653         error "unrecognized system of units \"$itk_option(-units)\""
     652          && [::Rappture::Units::System::for $itk_option(-units)] == ""} {
     653        error "unrecognized system of units \"$itk_option(-units)\""
    654654    }
    655655}
     
    662662    set opts {left right top bottom}
    663663    if {[lsearch -exact $opts $pos] < 0} {
    664         error "bad value \"$pos\": should be [join $opts {, }]"
     664        error "bad value \"$pos\": should be [join $opts {, }]"
    665665    }
    666666    _layout
     
    672672itcl::configbody Rappture::Gauge::presets {
    673673    if {"" == $itk_option(-presets)} {
    674         pack forget $itk_component(presets)
     674        pack forget $itk_component(presets)
    675675    } else {
    676         if {$itk_option(-valueposition) == "left"} {
    677             set s "left"
    678         } else {
    679             set s "right"
    680         }
    681         set first [lindex [pack slaves $itk_component(vframe)] 0]
    682         pack $itk_component(presets) -before $first -side $s -fill y
    683 
    684         $itk_component(presetlist) delete 0 end
    685         $itk_component(presetlist) insert end $itk_option(-presets)
     676        if {$itk_option(-valueposition) == "left"} {
     677            set s "left"
     678        } else {
     679            set s "right"
     680        }
     681        set first [lindex [pack slaves $itk_component(vframe)] 0]
     682        pack $itk_component(presets) -before $first -side $s -fill y
     683
     684        $itk_component(presetlist) delete 0 end
     685        $itk_component(presetlist) insert end $itk_option(-presets)
    686686    }
    687687}
     
    692692itcl::configbody Rappture::Gauge::type {
    693693    switch -- $itk_option(-type) {
    694         integer {
    695             set first [lindex [pack slaves $itk_component(vframe)] 0]
    696             if {$first == $itk_component(presets)} {
    697                 pack $itk_component(spinner) -after $first -side left -fill y
    698             } else {
    699                 pack $itk_component(spinner) -before $first -side right -fill y
    700             }
    701         }
    702         real {
    703             pack forget $itk_component(spinner)
    704         }
    705         default {
    706             error "bad number type \"$itk_option(-type)\": should be integer or real"
    707         }
    708     }
    709 }
     694        integer {
     695            set first [lindex [pack slaves $itk_component(vframe)] 0]
     696            if {$first == $itk_component(presets)} {
     697                pack $itk_component(spinner) -after $first -side left -fill y
     698            } else {
     699                pack $itk_component(spinner) -before $first -side right -fill y
     700            }
     701        }
     702        real {
     703            pack forget $itk_component(spinner)
     704        }
     705        default {
     706            error "bad number type \"$itk_option(-type)\": should be integer or real"
     707        }
     708    }
     709}
Note: See TracChangeset for help on using the changeset viewer.