|
iTool Programming: Using iTool User Interface Elements |
|
Prompts solicit information from the user. Prompts are generally presented as modal dialogs, meaning that the user must respond to the prompt before operation of the iTool can continue.
The IDLitIMessaging class provides two methods that prompt for user input: PromptUserYesNo and PromptUserText. See IDLitIMessaging for additional details on these methods.
The IDLitIMessaging::PromptUserYesNo method displays a prompt string along with Yes and No buttons. In the standard iTool interface created using the IDL widget toolkit, Yes/No prompts appear as modal dialogs as shown in Figure 12-2.
| Note The PromptUserYesNo function returns 1 if the dialog executed properly. You must check the value stored in the variable specified as the Answer argument to determine which button the user pressed. |
The following code asks the user a Yes or No question and performs some action if the dialog returns properly and the value of the returned variable answer is equal to 1 (as would be the case if the user clicked Yes):
status = self->PromptUserYesNo('Overwrite Variable: Plot_Y?', $
answer, TITLE='Overwrite Variable?')
IF (status NE 0 && answer EQ 1) THEN BEGIN
; do something...
ENDIF
The value of the TITLE keyword is displayed in the title bar of the dialog box.
The IDLitIMessaging::PromptUserText method displays a prompt string and a text-entry field along with OK and Cancel buttons. In the standard iTool interface created using the IDL widget toolkit, text prompts appear as modal dialogs as shown in Figure 12-2.
| Note The PromptUserText function returns 1 if the user clicks the OK button, or 0 if the user clicks the Cancel button. |
The following code asks the user to enter a text string, which will be stored in the variable stringName:
status = self->PromptUsertext('Enter a string value', $
stringName, TITLE = 'Name the Created Object')
The value of the TITLE keyword is displayed in the title bar of the dialog box. The variable status will contain a 1 if the user clicks OK, or a 0 if the user clicks Cancel.
IDL Online Help (March 06, 2007)