#!/bin/sh
# \
exec oagwish "$0" "$@"
set auto_path [linsert $auto_path 0 /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0 /usr/local/oag/lib_patch/$env(HOST_ARCH)]
APSDebugPath


proc setStatus {text} {
    global status
    set status "[clock format [clock seconds] -format %H:%M:%S]: $text"
    update
}

APSApplication . -name demoScript \
    -version 1.0 -overview "Shows various widgets and indicates how to use them."

setStatus Working...
APSScrolledStatus .status \
    -parent .userFrame \
    -textVariable status \
    -width 65 \
    -packOption "-fill both -expand true"

set tabLabelList [list EntryBox Buttons Misc.]
set tabWidgetList [APSTabFrame .main -parent .userFrame -label "" \
                     -labelList $tabLabelList -width 900 -height 300 \
                     -packOption "-fill x -expand true"]

proc FillEntryBoxTab {w} {
    global entryVariable1 entryVariable2 entryVariable3 entryVariable4 enableVariable4
    global entryVariable5 enableVariable5
    set entryVariable1 "My entry"
    APSLabeledEntry .le1 -parent $w -label "Plain entry widget: " \
      -textVariable entryVariable1 -width 40 -contextHelp \
      "This is a plain entry box"
    
    set entryVariable2 /home/oxygen/BORLAND/myFile.sdds
    APSLabeledEntry .le2 -parent $w -label "Entry widget with file selection support: " \
      -textVariable entryVariable2 -fileSelectButton 1 -width 40 -buttonsOnLeft 1  -contextHelp \
      "This is a entry box with file selection support.  You can click on the F button to bring up a file selection dialog." 
    
    set entryVariable3 /home/oxygen/BORLAND/myFile.sdds
APSLabeledEntry .le3 -parent $w -label "Entry widget with command support: " \
      -textVariable entryVariable3 -commandButton 1 -width 40 -buttonsOnLeft 1 -contextHelp \
      "This is a entry box with command support.  You can click on the combo-box button to bring up a selection of commands and to select files."
    
    set entryVariable4 3.1415926
    set enableVariable4 0
    APSLabeledEntry .le4 -parent $w -label "Entry widget with enable/disable button: " \
      -textVariable entryVariable4 -width 40 -buttonsOnLeft 1 \
      -enableVariable enableVariable4 -contextHelp \
      "This is a entry box with an integrated enable/disable button.  It is used to tell the program to ignore any entry, or to tell it to use the entry and allow it to be altered."

}

proc CountArray {args} {
    set arrayName ""
    set outputVariable ""
    APSStrictParseArguments {arrayName outputVariable}

    global $arrayName $outputVariable
    set $outputVariable 0
    foreach item [array names $arrayName] {
        if {([set $arrayName\($item\)])} {
            incr $outputVariable 1
        }
    }
}

proc FillButtonTab {w} {
    global radioButton1 
    set radioButton1 1
    frame $w.fr1 
    pack $w.fr1 -anchor n -side top
    set w1 $w.fr1
    APSRadioButtonFrame .rb -parent $w1 -variable radioButton1 \
      -label "Radio button: " -orientation horizontal \
      -buttonList "Yes No" -valueList "1 0" \
      -commandList {"setStatus Yes!" "setStatus No!"} \
      -contextHelp \
      "A radio button is used to select from a group of mutually exclusive options.  Frequently, a command is executed when the choice is changed."

    global checkButton checkButtonCount
    set checkButtonCount 0
    for {set i 0} {$i<10} {incr i} {
        set checkButton($i) [expr int(rand()*2)]
        lappend cbVarList checkButton\($i\)
        lappend cbButtonList $i
        lappend cbCommandList "CountArray -arrayName checkButton -outputVariable checkButtonCount"
    }
    APSCheckButtonFrame .cb -parent $w1 -variableList $cbVarList \
      -buttonList $cbButtonList -commandList $cbCommandList -allNone 1 \
      -label "Check buttons: " -orientation horizontal -limitPerRow 5 -contextHelp \
      "A check button frame is used to provide a group of related options that are mutually compatible.  Frequently, a command is executed when any choice is changed.  In this case, we just count the number of selections."
    CountArray -arrayName checkButton -outputVariable checkButtonCount
    APSLabeledOutput .lo -parent $w1 -textVariable checkButtonCount \
      -label "Number chosen: " -width 10 -contextHelp \
      "This is a labeled output widget that shows the number of items chosen from the check button list."

    frame $w.fr2 
    pack $w.fr2 -anchor n -side top
    set w1 $w.fr2
    APSButton .b1 -parent $w1 -text "Command Button" \
      -command {setStatus "Command executed!"; bell} \
      -contextHelp \
      "This button executes a command when pressed and released."
    APSButton .b2 -parent $w1 -text "Command Button ..." \
      -command "CommandPopUp" \
      -contextHelp \
      "This button executes a command with a dialog when pressed and released."
}

proc CommandPopUp {} {
    set choice [APSChooseItemFromList \
                  -name "Choose Item" \
                  -itemList "One Two Three Infinity" \
                  -returnList "1 2 3 Infinity" ]
    if [string length $choice] {
        setStatus "You chose $choice"
    }
}

proc FillMiscTab {w} {
    APSFrame .fr1 -parent $w -packOption "-side top" 

    APSComboboxFrame .cbox -parent $w.fr1.frame -label "Combo box: " -width 50 \
      -packOption "-side top" -itemList \
      "One Two Three Infinity" \
      -textVariable comboBoxChoice -maxWidth 1 \
      -contextHelp "Click on the triangle-shaped icon to bring up a list of possible selections."
    
    APSFrame .fr2 -parent $w -packOption "-side top" 
    APSScrolledListWindow .slist -parent $w.fr2.frame -label "Listbox widget" \
      -height 6 -itemList "One Two Three Infinity" \
      -selectMode extended -selectionVar scrolledListSelection -closeButton 0 \
      -contextHelp "This is a listbox widget, which allows selection of one or more items from a list."
    APSLabeledOutput .lo -parent $w.fr2.frame -label "Listbox selection: "  \
      -textVariable scrolledListSelection -width 40 
}

FillEntryBoxTab [lindex $tabWidgetList 0]
FillButtonTab [lindex $tabWidgetList 1]
FillMiscTab [lindex $tabWidgetList 2]

setStatus "Remember: double-right-click to bring up context help"
