home *** CD-ROM | disk | FTP | other *** search
- # CVS $Id: input3.tcl,v 1.3 1995/02/03 16:54:54 zibi Exp $
- # input3.tcl, 12 Nov 92
- #
- # this script demonstrates the VtAddInput and complementary VtRemoveInput
- # commands that provide the ability to tell the widget server to
- # monitor activity on a file descriptor, such as a pipe. This is
- # accomplished by telling wserver the name of the file descriptor to
- # watch and the name of the callback function to invoke when there
- # is activity.
-
- # As used below, the tcl "pipe" command opens the first handle as the
- # side of the pipe meant for reading. The 2nd handle is opened for
- # writing.
-
- proc InPipeCB {dlog fileId} {
- set data [gets $fileId]
-
- VtInformationDialog $dlog.$fileId -hidden false \
- -message "Activity on file ID: $fileId\n\n$data"
-
- }
-
- proc ListWidgetCB {cbs} {
- global selectedData
-
- set selectedData [keylget cbs selectedItemList]
- }
-
- proc CancelCB {cbs} {
- set target [keylget cbs widget]
- VtDestroyDialog $target
-
- exit
- }
-
- proc writeCB {fID cbs} {
- global selectedData outPipe
-
- puts $fID $selectedData
- flush $fID
- }
-
- # grab name of this script minus the tcl extension
- set scriptname [file tail [file root [info script]]]
-
- set app [VtOpen $scriptname]
-
- pipe p1read p1write
- pipe p2read p2write
-
- set dlog [VtFormDialog $app.form1 \
- -MOTIF_verticalSpacing 5 \
- -okLabel "Send Pipe1" -okCallback "writeCB $p1write" \
- -applyLabel "Send Pipe2" -applyCallback "writeCB $p2write"\
- -cancelLabel Exit -cancelCallback CancelCB \
- -defaultButton OK ]
-
- VtLabel desc -label \
- "Demo of VtAddInput and VtRemoveInput commands" \
- -leftSide FORM -rightSide FORM \
-
-
- VtSeparator sep -leftSide FORM -rightSide FORM -horizontal
-
- set data [list "Short" \
- "Medium Test line" \
- "Long test line that is sent to input pipe" \
- "VtAddInput is used every time a line is selected"]
-
- set lst [VtList listwidget \
- -itemList $data \
- -leftSide FORM -rightSide FORM -bottomSide FORM \
- -scrollBar 1\
- -rows 3 -callback ListWidgetCB]
-
- global selectedData
-
- VtListSelectItem $lst -item Short
- set selectedData Short
-
-
- VtAddInput $p1read "InPipeCB $dlog"
- VtAddInput $p2read "InPipeCB $dlog"
-
- VtShowDialog $dlog
-
- VtMainLoop
-