Unidata McIDAS-X
Tcl/Tk script, strnvals.gui



#!/bin/sh
# the next line restarts using mcwish \
exec mcwish "$0" "$@"

#---------------------------------------------------------------------------
#
# Name:    strnvals.gui
#
# Purpose: List and modify Unidata Menu-relevant String Table Values
#
# History: 19940829 - Written for Unidata McIDAS-X 1.90 FKey Menu
#          19950529 - Updated for Unidata McIDAS-X 2.00
#          19950914 - Updated for Unidata McIDAS-X 2.1: added help hints
#                     for widget use
#          19951116 - Modified to display watch cursor when updating
#                     values in string table
#          19951214 - Changed to set maxsize for window geometry; this lets the
#                     packer choose the initial size and the user to resize
#          19960106 - Updated single line helps; additional minor housekeeping
#          19960411 - Updated to add access to +DWELL string
#          19960414 - Updated to add access to +NLDNINT string
#          19960502 - Added support for MCPATH environment variable
#          19960710 - Updated for Unidata McIDAS-X 7.000 and Tcl/Tk 7.5/4.1
#          19961203 - Changed Fkey menu string PREFIX from '+' to '?'
#                   Updated to use 'mcwish' from Unidata McIDAS 7.10
#          19970128 - Changed 'wm maxsize . n m' to 'wm minsize . 1 1'
#          19970213 - General update of module
#          19970413 - Added support for precipitation contour string
#          19970922 - Changed look of control buttons (Plot/Exit)
#          19971110 - Modified to use 7.201 stringLoad procedure and
#                     'mcidas strget sname' and 'mcidas strput sname svalue'
#                     functions
#          20000131 - Modified to use 7.60 stringtable [get|put] routines
#          20010505 - Modified to use Notebook widget
#
#---------------------------------------------------------------------------

set home      $env(HOME)
set mcgui     $env(MCGUI)
set mcpath    $env(MCPATH)
set auto_path "$mcgui $auto_path"

# Global variables

    global mcpath
    global str
    global helptxt

# Set widget options
#   option add *font {-misc-fixed-bold-r-normal--13-100-100-100-c-70-iso8859-1}
    option add *font {-adobe-helvetica-bold-r-normal--*-120*}
    option add *activeBackground bisque2
    option add *activeForeground green3
    option add *background bisque2
    option add *disabledForeground red
    option add *foreground black
    option add *highlightBackground bisque
    option add *highlightColor green3
    option add *insertBackground black
    option add *selectBackground bisque2
    option add *selectForeground white
    option add *Text.Foreground white
    option add *Text.Background black

# Define widget tabs

    set tabs { "Display" "Loops" "Grids" "Misc" }

# Define System Key Table Values of interest

    set strntbl_title1 \
        "String Value Used for:             Name         Current Value"

    set [lindex $tabs 0] {
        "Current Satellite Image Frame       ?IFRM"   \
        "Surface Plot/Contour Frame          ?SFRM"   \
        "Upper Air Plot/Contour Frame        ?UFRM"   \
        "Wind Profiler Plot Frame            ?PFRM"   \
        "NLDN Lightning Plot (IDD) Frame     ?NFRM"   \
        "Vertical Cross Section Frame        ?XFRM"   \
    }

    set [lindex $tabs 1] {
        "Antarctic Composite start,#frames  ?AFRMS"   \
        "Floater(s) & misc start,#frames    ?FFRMS"   \
        "Water Vapor start,#frames          ?HFRMS"   \
        "Infrared Images start,#frames      ?IFRMS"   \
        "Radar (MDR/NIDS) start,#frames     ?MFRMS"   \
        "Visible Images start,#frames       ?VFRMS"   \
        "Image Loop DWELL Rates  1..n-1 n   ?DWELL"   \
    }

    set [lindex $tabs 2] {
        "00-hour Forecast Grid Frame        ?GFRML"   \
        "12-hour Forecast Grid Frame        ?GFRMB"   \
        "24-hour Forecast Grid Frame        ?GFRMC"   \
        "36-hour Forecast Grid Frame        ?GFRMD"   \
        "48-hour Forecast Grid Frame        ?GFRMH"   \
        "Objective Analysis GRID File #     ?GFILE"   \
    }

    set [lindex $tabs 3] {
        "Draw BAR on image [NO|YES|HOR|VER] ?BAR"     \
        "MENU Map Projection  [MERC,CONF]   ?PRO"     \
        "Precipitation Amounts [in]         ?PCP"     \
        "Relative Humidity Levels [%]       ?RHLEV"   \
        "250 mb Wind Speed Levels [kts]     ?WLEV"    \
        "NLDN lightning plot interval       ?NLDNINT" \
        "Circuits for current data plots    ?CIRCUIT" \
        "Blank image under macro labels     ?BLANK"   \
    }

# Create an input widget

    wm title    . "Menu String Table Values"
    wm iconname . "StrnTbl"
    wm geometry . +50+50
    wm minsize  .  1 1

# Describe the graphical widget

    set w .f
    frame $w

    # Title
    message $w.title -aspect 1100 -justify center \
        -font {Helvetica -16 bold underline} \
        -text "String Table Values Used by Menu System"

    # Notebook pages
    Notebook:create $w.n -pages $tabs -width 500 \
                         -font {Helvetica -14 bold italic} \

    # Widget controls
    frame $w.ctrl -relief raised -bd 1

    button $w.ctrl.ok -text "Update and Exit" -cursor {hand2} \
        -font {Helvetica -13 bold}
    set helpmsg$w.ctrl.ok "Click left button to update strings and EXIT"

    button $w.ctrl.exit -text "Exit" -activeforeground red -cursor {pirate} \
        -font {Helvetica -13 bold}
    set helpmsg$w.ctrl.exit "Click left button to EXIT without updating strings"

    # One line help
    label $w.help -textvariable helptxt -width 55 \
        -font {Helvetica -13 bold}

# Begin packing the widget

    grid configure $w       -row 0

    grid configure $w.title -row 0 -sticky "nsew"
    grid configure $w.n     -row 1 -sticky "nsew"
    grid configure $w.ctrl  -row 2 -sticky "nsew" -pady 5 -ipady 1
    grid configure $w.help  -row 3 -sticky "nsew" -pady 2

    grid configure $w.ctrl.ok   -row 0 -column 1 -sticky "w"
    grid configure $w.ctrl.exit -row 0 -column 3 -sticky "e"
    grid columnconfigure $w.ctrl 0 -weight 1
    grid columnconfigure $w.ctrl 2 -weight 1
    grid columnconfigure $w.ctrl 4 -weight 1

# Get all of the String Table values used by the Unidata Fkey Menu system

    runBusy busy
    set helptxt "String table information being loaded; please wait"
    update

    stringLoad

    # Put strings in frame widgets along with sliders or entries

    set string_names {}

    foreach type $tabs {
        set wi [Notebook:frame $w.n $type]

        #Title
        set win [frame $wi.f0]
        label $win.ld -text "String Description" -width 25 -anchor w \
              -font { Helvetica -14 bold italic underline }
        label $win.ls -text "String Name" -width 18 -anchor w \
              -font { Helvetica -14 bold italic underline }
        label $win.lv -text "String Value"  -width 16 \
              -font { Helvetica -14 bold italic underline }
        grid configure $win    -row 0 -sticky "new" -pady 3
        grid configure $win.ld -row 0 -column 0 -sticky "w"
        grid configure $win.ls -row 0 -column 1 -sticky "e"
        grid configure $win.lv -row 0 -column 2 -sticky "e"
#       grid columnconfigure $win 0 -weight 1

        set row 1
        foreach txt [set $type] {

            set sname [string range $txt [string last "?" $txt] end]
            set labl  [string range $txt 0 [expr [string last "?" $txt]-1]]
            global $sname
            lappend string_names $sname
            set $sname [getStringVal $sname]

            set win [frame $wi.f$row]

            label $win.l -text $labl -width 35 -anchor w
            label $win.s -text $sname -width 10 -anchor w
            entry $win.e -width 22 -textvariable $sname
            set helpmsg$win.e "Click left button and enter value (highlight overwrites)"

            grid configure $win   -row $row -sticky "new" -pady 2
            grid configure $win.l -row    0 -column 0 -sticky "w"
            grid configure $win.s -row    0 -column 1 -sticky "w"
            grid configure $win.e -row    0 -column 2 -sticky "e"
#           grid columnconfigure $win 1 -weight 1

            incr row

            bind $win.e  {
                set w [winfo toplevel %W]
                tk_messageBox -default ok -icon info -title "Menu Defaults" -message "To modify a string value used by the Unidata Function Key Menu, simply click the left mouse button in the ENTRY containing the value to be modified, highlight any/all of the value(s) you want to change, and enter the new value.  Remember to select the Update and Exit option to save the new string value!"
            }
        }

    }

    runBusy normal

# Special bindings for widget classes

    # OK
    bindtags $w.ctrl.ok [list all Button $w.ctrl.ok]
    bind $w.ctrl.ok  {
        foreach sname $string_names {
            set val [string toupper [set $sname]]
            putStringVal $sname $val
        }
        destroy [winfo toplevel %W]
        set helptxt ""
    }

    # Exit
    bindtags $w.ctrl.exit [list all Button $w.ctrl.exit]
    bind $w.ctrl.exit  {
        destroy [winfo toplevel %W]
        set helptxt ""
    }

    bind Entry   {
        focus %W
        %W icursor end
    }
    bind Entry  {
        %W delete 0 end
    }
    bind Entry  {
        %W delete 0 end
    }
    bind Entry  {
        if {"%A" != ""} {
            set a [string compare %A "A"]
            set b [string compare %A "Z"]
            set c [string compare %A "a"]
            set d [string compare %A "z"]
            if { ($a >= 0 && $b <= 0) || ($c >=0 && $d <=0 ) } {
                if [%W selection present] {
                    %W delete sel.first sel.last
                }
                %W insert insert [caseFlip %A]
                break
            }
            set a [string first %A "0123456789 .:-+/\""]
            if { $a != -1 } {
                if [%W selection present] {
                    %W delete sel.first sel.last
                }
                %W insert insert %A
                break
            }
        }
    }

    bind all  {
        catch {set helptxt ${helpmsg%W}}
    }
    bind all  {
        set helptxt ""
    }