Description
The Dialog object provides access to simple user-interface features provided by SecureCRT.
Syntax
crt.Dialog.Method([arglist])
Remarks
SecureCRT's
Dialog object is accessed through the top-level object’s Dialog
property.
Dialog Object Methods
Description
Display a file browse dialog from which the user can select a single file.
Remarks
If the defaultFilename parameter is simply a filename (no path provided), the file dialog browser will open in current working directory. If the defaultFilename parameter specifies an absolute path to a file, the file dialog browser will open in the parent directory of the file. The filename filter is in the following format:
<Name of Filter> (*.<extension>)|*.<extension>||
For example:
Text Files (*.txt)|*.txt||
or
Text Files (*.txt)|*.txt|Log File (*.log)|*.log||
The FileOpenDialog method returns the path to the selected file.
VBScript
Syntax
crt.Dialog.FileOpenDialog([title, [buttonLabel, [defaultFilename, [filter ]]]])
Examples
' Browse for a file of any type
filePath = crt.Dialog.FileOpenDialog("Please select a file")
' Browse for only .txt files
filePath = crt.Dialog.FileOpenDialog("Please select a text file", "Open", "", "Text Files (*.txt)|*.txt||")
Python
Syntax
crt.Dialog.FileOpenDialog([title, [buttonLabel, [defaultFilename, [filter ]]]])
Examples
# Browse for a file of any type
filePath = crt.Dialog.FileOpenDialog(title="Please select a file")
# Browse for only .txt files
filePath = crt.Dialog.FileOpenDialog(title="Please select a text file", filter="Text Files (*.txt)|*.txt||")
Description
Display a message
Remarks
The MessageBox function displays a message string to the user. The optional title string sets the title or caption of the MessageBox. The buttons that appear on the MessageBox can be configured by passing a combination of numeric values in the optional ‘buttons’ parameter. By default MessageBox will display the message string with an OK button. However, many possibilities exist for displaying message boxes with different icons, and buttons.
The MessageBox function returns a numeric value that can be used to identify which button was clicked.
VBScript
Syntax
crt.Dialog.MessageBox(message [, title [, buttons]])
Example
The following code sample defines the constants that can be combined to form the "button" parameter as well as the possible numeric return values:
Python
Syntax
crt.Dialog.MessageBox(message [, title [, buttons]])
Example
The following code sample defines the constants that can be combined to form the "button" parameter as well as the possible numeric return values:
# button parameter options
ICON_STOP = 16 # display the ERROR/STOP icon.
ICON_QUESTION = 32 # display the '?' icon
ICON_WARN = 48 # display a '!' icon.
ICON_INFO= 64 # displays "info" icon.
BUTTON_OK = 0 # OK button only
BUTTON_CANCEL = 1 # OK and Cancel buttons
BUTTON_ABORTRETRYIGNORE = 2 # Abort, Retry, and Ignore buttons
BUTTON_YESNOCANCEL = 3 # Yes, No, and Cancel buttons
BUTTON_YESNO = 4 # Yes and No buttons
BUTTON_RETRYCANCEL = 5 # Retry and Cancel buttons
DEFBUTTON1 = 0 # First button is default
DEFBUTTON2 = 256 # Second button is default
DEFBUTTON3 = 512 # Third button is default
# Possible MessageBox() return values
IDOK = 1 # OK button clicked
IDCANCEL = 2 # Cancel button clicked
IDABORT = 3 # Abort button clicked
IDRETRY = 4 # Retry button clicked
IDIGNORE = 5 # Ignore button clicked
IDYES = 6 # Yes button clicked
IDNO = 7 # No button clicked
# Display a messagebox with Yes/No buttons.
# Make the 'No' button the default.
result = crt.Dialog.MessageBox("Login Failed, Retry?", "Error", ICON_QUESTION | BUTTON_YESNO | DEFBUTTON2 )
if result == IDNO:
return
Description
Prompt a user to enter a string.
Remarks
The Prompt function displays a simple dialog that has message and an edit field for the user to enter a string. The message parameter is an informational string displayed in the prompt dialog. Optionally the title of the prompt dialog may be set by passing a title string. By default the edit field is empty, but the initial contents of the edit field may be set with the optional default string. Finally, if the text entered in the edit field is to be obscured as it is entered (such as when entering a password) then the Boolean isPassword field should be set to True.
If the user clicks OK, Prompt returns the entered string; whereas, if the user clicks Cancel, Prompt returns an empty string.
VBScript
Syntax
crt.Dialog.Prompt(message [, title [, default [, isPassword ]]])
Example
Dim pass
pass = crt.Dialog.Prompt("Enter your password:", "Logon Script", "", True)
If pass = "" Then
' User clicked Cancel button
Else
' User added data
End If
Python
Syntax
crt.Dialog.Prompt(message [, title [, default [, isPassword ]]])
Example
password = crt.Dialog.Prompt("Enter your password:", "Logon Script", "", True)
if password == "":
# User clicked Cancel button
else:
# User added data