Example Widget Toolbox Application
The following program demonstrates how to use Widget Toolbox functions to create a simple GUI. This program displays a form containing a single button. When you click on the button, the button’s label changes.
Figure 6-1: Motif GUI shows the example program’s output:
; The QUITIT procedure is a callback routine that is executed
; when the "Hello World" button is selected.
PRO QUITIT, wid, data, npars, reason, event, count
COMMON widgets, warr, pushed
; If button selected, replace button label with "Good Bye!!!".
; Next time button selected, close top-level window to quit
; the application.
IF pushed EQ 0 THEN BEGIN
; args is defined as an unnamed structure.
args={,labelString:'Good Bye!!!!'}
status=WtSet(wid,args)
pushed=1
ENDIF ELSE BEGIN
PRINT, 'Quitting...'
status=WtClose(warr(0))
ENDELSE
END
; This procedure creates pushbutton with QUITIT routine as
; callback.
PRO EXAMPLE
@wtxmclasses
@wtxmconsts
COMMON widgets, warr, pushed
warr = LONARR(4)
pushed=0
; Initialize the application.
warr(0)=WtInit('example','Examples')
; Create a "container" widget.
warr(1) = WtCreate('form',xmFormWidgetClass, warr(0))
args={,x:10,y:10}
; Create a label.
warr(2)=WtCreate('Push Me, Please!', xmLabelWidgetClass, $
warr(1),args)
args={,y:40,width:140,height:25,recomputeSize:FALSE}
; Create the "Hello World" push button.
warr(3)=WtCreate('Hello,World!', xmPushButtonWidgetClass, $
warr(1),args)
; Add the button callback.
status=WtAddCallback(warr(3), 'activateCallback', 'quitit')
; Display the top-level shell.
status=WtSet(warr(0), /Realize)
; Process events. Call callbacks.
WtLoop
END