vizdlg_Dialogs

Vizard’s vizdlg library includes a number of dialog boxes for eliciting user input and displaying messages. These include a ChooseDialog that displays a drop list of options, an AskDialog that displays multiple options as buttons, an InputDialog for typing in values, and much more. The vizdlg dialogs provide similar functionality to the vizinput dialogs without causing a blocking action that halts the rendering of the world. In addition, vizdlg dialogs can be added to a GUI canvas which can be rendered in the world for stereo applications. Run the following code and press different buttons on the AskDialog to change the world model:

import viz
import vizdlg
import viztask

viz.setMultiSample(8)
viz.fov(60)
viz.go()

# Load environment models
worlds = [ viz.addChild(‘maze.osgb’), viz.addChild(‘gallery.osgb’), viz.addChild(‘dojo.osgb’) ]
for i, model in enumerate(worlds):
    model.visible(== 0)

def SelectWorldTask():
    “””Handle selecting of world”””

    options = [ model.getFilename().split(‘.’)[0].capitalize() for model in worlds ]

    dialog = vizdlg.AskDialog(‘Select the world to display:’, options=options, cancel=None, cancelKey=None)
    dialog.setScreenAlignment(viz.ALIGN_CENTER)

    while True:

        yield dialog.show()

        for i, model in enumerate(worlds):
            model.visible(== dialog.selection)

viztask.schedule(SelectWorldTask())

In the example above the dialog box is rendered to the screen. This works well for non-stereo desktop setups. For GUIs to appear properly to the user in stereo applications they should be rendered in the world. Add the following code immediately after the viz.go() statement to place the dialog box on a GUI canvas. The GUI canvas is rendered in the world at a fixed distance from the viewpoint so it can be comfortably viewed in a stereo application:

# Create canvas in world overlay mode and set the mouse style to virtual 
canvas = viz.addGUICanvas()
canvas.setMouseStyle(viz.CANVAS_MOUSE_VIRTUAL)# Hide and trap mouse since we will be using virtual canvas mouse
viz.mouse.setVisible(False)
viz.mouse.setTrap(True)

# Set the default canvas to automatically parent vizdlg, vizinfo, and vizconfig
# objects to the canvas
viz.MainWindow.setDefaultGUICanvas(canvas)