Vizard 8 » Reference » Graphical user interfaces (GUIs) » Dialog boxes » vizinput dialogs
8.0

vizinput dialogs

The vizinput module provides several dialog style boxes for eliciting user input and displaying messages. All dialogs create a blocking action that halts events until the user has responded or the box is closed. To set their positions and titles use the standard dialog options described in the vizinput properties section.

Display a message

Use vizinput.message() to display a message box to the user:

import vizinput
vizinput.message('There was no data recorded!')

Prompt for a string

The  vizinput.input() dialog returns a string entered by the user:

The vizinput.input() command accepts the following optional keyword arguments, along with the standard dialog options.

Argument

Description

password

If the value of this argument evaluates to True, then the contents of input control will be displayed as asterisks (*). This is useful when entering passwords or other sensitive information.

import vizinput
userName = vizinput.input('Enter your name:')

Ask the user a Yes/No question

The vizinput.ask() dialog displays a question and allows the user to select a Yes/No response. The answer will be 1 for 'Yes' and 0 for 'No':  

import vizinput
answer = vizinput.ask('Are you ready?')

Prompt the user to choose from a list of options

Use the vizinput.choose() dialog to create a pop-down menu of choices. The user's answer will be the order of their response within the array of options (0 is returned for choice 1, 1 for choice two, etc...):

import vizinput
choice = vizinput.choose('Select a scene',['mountains','beach','forest'])

Prompt the user to select a color

The vizinput.color() dialog allows the user to select a color using a variety of tools. The return value is a list of normalized RGB values. Optionally, one can specify the initial color that is selected when the dialog opens.

import vizinput
color = vizinput.color(viz.BLUE) # Specifying initial color is optional
viz.clearcolor(color)

Windows open/save dialogs

Use vizinput.fileOpen() and vizinput.fileSave() to display standard Windows open and save dialogs. A string holding the path to the selected file is returned when the open or save button is pressed:

The following commands create open/save dialogs:

Command

Description

vizinput.fileOpen()

Displays a Windows open dialog box. The path to the file is returned as a string when the Open button is pressed.

vizinput.fileSave()

Displays a Windows save dialog box. The path to the file is returned as a string when the Save button is pressed.

Both commands accept the following optional keyword arguments, along with the standard dialog options.

Argument

Description

filter

A list of 2 item tuples. The first item of the tuple is a file type description. The second item of the tuple is a file type filter, with wildcards supported.

file

Specifies the default file name to open/save.

directory

Specifies an initial directory to display in the dialog.

In the code below a  vizinput.fileOpen dialog displays the Vizard resource directory and filters for OSG and VRML files. The file selected is added to a Vizard scene:   

import viz
import vizinput

filePath = vizinput.fileOpen(filter=[('OSG Files','*.ive;*.osgb;*.osg'),('VRML Files','*.wrl')],directory='c:/Program Files/WorldViz/Vizard4/resources')
model = viz.add(filePath)

viz.go()

In the following code a default file name is specified:

import vizinput
filePath = vizinput.fileSave(file='test.py')
print(filePath)

Windows directory selection dialog

The vizinput.directory() command displays the standard Windows directory selection dialog. A string holding the path to the selected directory is returned when the OK button is pressed:

The vizinput.directory() command accepts the following optional keyword arguments, along with the standard dialog options.

Command

Description

prompt

The message prompt to display above the directory tree.

directory

The initial directory to have selected.

In the code below, a file is opened in the selected directory:

import vizinput
path = vizinput.directory(prompt='Select a folder to save the log file.',directory='C:\\')

file = open(path + '/log1.txt', 'w')

vizinput dialogs

vizinput properties