home *** CD-ROM | disk | FTP | other *** search
- # CVS $Id: forum94,v 1.3 1995/02/03 17:15:37 zibi Exp $
-
- #
- # Example phone book program explained at forum 93 converted
- # to use the new SCO Visual Tcl
- #
-
-
-
- #
- # Strips the widget path off the widget name
- #
- proc stripPath {path} {
- set pathList [split $path .]
- set nameIndex [expr "[llength $pathList] - 1"]
- set name [lindex $pathList $nameIndex]
- return $name
- }
-
- #
- # Pops down and destroys dialog
- #
- proc destroyDialogCB {cbs} {
- VtDestroyDialog [keylget cbs dialog]
- }
-
-
-
-
- #
- # Callback for Ok button on Add Screen
- #
- proc AddFormOkCB {cbs} {
-
- #
- # get userdata which has form fields
- #
- set FormWidgets [VtGetValues [keylget cbs dialog] -userData]
- set PhoneList [keylget FormWidgets PhoneList]
-
- set name [VtGetValues [keylget FormWidgets namefield] -value]
- set number [VtGetValues [keylget FormWidgets numfield] -value]
- set type [stripPath \
- [VtGetValues [keylget FormWidgets statusbox] -value]]
-
- AddToPhoneBook $name $number $type $PhoneList
-
- VtDrawnListSelectItem $PhoneList -position 1
-
- VtDestroyDialog [keylget cbs dialog]
- }
-
-
-
- #
- # Callback for Add button on Menu
- #
- proc PhoneMenuAddCB {cbs} {
-
- set parent [keylget cbs widget]
-
- set addform \
- [VtStartForm $parent.addform \
- -title "Add" \
- -help \
- -okCallback AddFormOkCB \
- -cancelCallback destroyDialogCB]
-
- set namelabel \
- [VtLabel $addform.namelabel -label "Name:" \
- -leftSide NONE \
- -rightSide 20]
-
- set namefield \
- [VtText $addform.namefield -topSide FORM \
- -rightSide FORM \
- -leftSide 20]
-
- set numlabel \
- [VtLabel $addform.numlabel -label "Number:" \
- -topSide $namefield \
- -leftSide NONE \
- -rightSide 20]
-
- set numfield \
- [VtText $addform.numfield -rightSide FORM \
- -below $namefield \
- -leftSide 20]
-
- set statuslabel \
- [VtLabel $addform.statuslabel -label "Status:" \
- -below $numfield \
- -leftSide NONE \
- -rightSide 20]
-
- set statusbox \
- [VtRadioBox $addform.statusbox -numColumns 3 \
- -below $numfield \
- -leftSide 20 \
- -rightSide FORM \
- -borderWidth 1]
- VtToggleButton $statusbox.friend -label "Friend" -value 1
- VtToggleButton $statusbox.enemy -label "Enemy"
- VtToggleButton $statusbox.turkey -label "Turkey"
-
-
- #
- # put fields in userData (including phonelist)
- #
- set PhoneList [VtGetValues [keylget cbs dialog] -userData]
- keylset FormWidgets statusbox $statusbox
- keylset FormWidgets namefield $namefield
- keylset FormWidgets numfield $numfield
- keylset FormWidgets PhoneList $PhoneList
- VtSetValues $addform -userData $FormWidgets
-
- VtShow $addform
- VtSetFocus $namefield
- }
-
-
-
-
- #
- # Callback for Delete button on Menu
- #
- proc PhoneMenuDeleteCB {cbs} {
-
- set PhoneList [VtGetValues [keylget cbs dialog] -userData]
-
- set pos [VtDrawnListGetSelectedItem $PhoneList -byPositionList]
-
- VtDrawnListSelectItem $PhoneList -next
-
- VtDrawnListDeleteItem $PhoneList -position $pos
- }
-
-
- #
- # Callback for Exit button on Menu
- #
- proc PhoneMenuExitCB {cbs} {
- VtClose
- exit 0
- }
-
-
- proc genericCB {cbs} {
- }
-
- #
- # Routine to initially display the menu on the screen
- #
- proc CreatePhoneBookMenu {form} {
-
- set menuList {
- {pd Phone P}
- {bt Add A "" "" PhoneMenuAddCB }
- {bt Delete D "" "" PhoneMenuDeleteCB }
- {sp}
- {bt Exit E "" "" PhoneMenuExitCB }
-
- {pd View V}
- {bt All A "" "" "" }
- {bt Friends F "" "" "" }
- {bt Enemies E "" "" "" }
- {bt Turkeys T "" "" "" }
- }
-
- set menubar [VtMenuBar $form.menubar -helpMenuItemList {INDEX}]
- VxMenu $form $menubar $menuList genericCB
- }
-
-
- #
- # Routine to add a name and phone number on the list
- #
- proc AddToPhoneBook {name phone type PhoneList} {
-
- case $type {
- "friend" {set icon 0}
- "enemy" {set icon 1}
- "turkey" {set icon 2}
- }
-
- VtDrawnListAddItem $PhoneList \
- -position 1 \
- -fieldList [list $icon $name $phone]
- }
-
-
- #
- # Routine to initially display the phone list on the screen
- #
- proc CreatePhoneBookList {form} {
-
- set PhoneList \
- [VtDrawnList $form.PhoneList \
- -formatList {{ICON 2} {STRING 20} {STRING 15}} \
- -iconList [list friend.px enemy.px turkey.px] \
- -CHARM_iconList [list F E T] \
- -leftSide FORM \
- -rightSide FORM \
- -columns 42 \
- -rows 5]
-
- AddToPhoneBook "Shawn McMurdo" 408-429-5192 friend $PhoneList
- AddToPhoneBook "Howard Stern" 408-462-5500 turkey $PhoneList
- AddToPhoneBook "Rick Solaris" 408-555-7643 enemy $PhoneList
- AddToPhoneBook "Bill Windows" 408-437-8455 enemy $PhoneList
- AddToPhoneBook "Wing Eng" 408-475-3485 friend $PhoneList
- AddToPhoneBook "Julia Dye" 408-435-6532 friend $PhoneList
-
- VtDrawnListSelectItem $PhoneList -position 1
-
- #
- # put the drawnlist in the form's userdata
- #
- VtSetValues $form -userData $PhoneList
- }
-
-
- #
- # Main
- #
-
- set app [VtOpen Example]
-
- VtSetAppValues $app -columnValue MAXIMUM
-
- set mainform [VtStartForm $app.form \
- -title "Phone Book"]
-
- CreatePhoneBookMenu $mainform
- CreatePhoneBookList $mainform
-
- VtShow $mainform
- VtMainLoop
-
-
-