Panda3D Manual: DirectDialog
  <<prev top next>>     

DirectDialog objects are popup windows to alert or interact with the user. It is invoked just like the other DirectGUI objects, but it also has some unique keywords. Integral to DirectDialog are dialogName, buttonTextList, buttonImageList, and buttonValueList. The dialogName should ideally be the name of the NodePath created to hold the object. The button lists contain the various properties of the buttons within the dialog box. No maximum number of buttons needs to be declared.

Panda3D contains a number of shortcuts for common dialog options. For example, rather than specifying the rather common text list ("Yes","No"), there is a YesNoDialog that functions exactly like a normal dialog but has buttonTextList already defined. The other similar dialogs are OkCancelDialog, OkDialog, RetryCancelDialog, and YesNoCancelDialog.

KeywordDefinitionValue
dialogNameName of the dialogString
buttonTextListList of text to show on each button[Strings]
buttonGeomListList of geometry to show on each button[NodePaths]
buttonImageListList of images to show on each button[Image Paths]
buttonValueListList of values sent to dialog command for each button. If value is [] then the ordinal rank of the button is used as its value[Numbers]
buttonHotKeyListShortcut key for each button (the button must have focus)[Characters]
buttonSize4-tuple used to specify custom size for each button (to make bigger then geom/text for example)(Left,Right,Bottom,Top)
topPadExtra space added above text/geom/imageNumber
midPadExtra space added between text/buttonsNumber
sidePadExtra space added to either side of text/buttonsNumber
buttonPadSFScale factor used to expand/contract button horizontal spacingNumber
commandCallback command used when a button is pressed. Value supplied to command depends on values in buttonValueListFunction
extraArgsExtra arguments to the function specified in command[Extra Arguments]
fadeScreenIf 1, fades screen to black when the dialog appears0 or 1

YesNo Dialog Example

import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText 
from direct.gui.DirectGui import *
from direct.task import Task
from direct.actor import Actor
from direct.interval.IntervalGlobal import *

#add some text
bk_text = "DirectDialog- YesNoDialog Demo"
textObject = OnscreenText(text = bk_text, pos = (0.85,0.85), 
scale = 0.07,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=1)

#add some text
output = ""
textObject = OnscreenText(text = output, pos = (0.95,-0.95),
 scale = 0.07,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=1)

#callback function to set  text 
def itemSel(arg):
	if(arg):
		output = "Button Selected is: Yes"
	else:
		output = "Button Selected is: No"
	textObject.setText(output)

#create a frame
dialog = YesNoDialog(dialogName="YesNoCancelDialog", command=itemSel)

base.camera.setPos(0,-20,0)
#run the tutorial
run()
  <<prev top next>>