WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Turning info boxes on and off (https://forum.worldviz.com/showthread.php?t=1291)

Karla 12-17-2007 10:31 AM

Turning info boxes on and off
 
Below is the code from my .py file.

I would like to program info boxes to appear and disappear based on user input or a timer, not from clicking on the logo to shrink the box. For example, a box with 3 choices appears to collect the user's choice of phrase. It disappears after the user clicks OK. Then an info box appears to tell the user the avatar's reply. After 2 seconds (enough time to read the reply), that info box disappears. Then another box with 3 choices appears to collect the user's next choice of phrase, and so on. I'm having a problem with the timing.

After running the file, if you press '5' an info box will appear. Once you click the OK button, the first info box will disappear, but a second info box does not appear as it should. Line 74 should make this box appear; line 77 should wait 2 seconds; and line 78 should make this box disappear.

Any advice is greatly appreciated!

Thanks,
Karla


Code:

import viz

import vizinfo        #For message box
import viztask        #For wait time

viz.go()

male = viz.add('male.cfg')        #Add an avatar
male.translate(0,0,1)
male.rotate(0,1,0,180)
male.state(1)                                #Start in neutral state animation

face2 = male.face('biohead_talk.vzf')        #add a face to the avatar

smile = vizact.morph(0,2,0.5)                #Smiling face of male avatar
open = vizact.morph(5,0.5,0.5)        #mouth open morph of male avatar
                               
# Make an action when a key is pressed.
def mykey(key):
        global subTalk, OKbutton, aRadio, bRadio, cRadio, charTalk
               
        if key == ' ':                            #if the pressed key is space bar
                face2.add(smile)                #Smiling face of male avatar
                face2.add(open)                #Open mouth face of male avatar
                male.state(5)                  #Wave animation of male avatar
       
        #Show a Transparent Message Box
        if key == '5': #if the pressed key is '5'
                subTalk = vizinfo.add("")                #Add the vizinfo object
                subTalk.translate(1.0,.95)                #Set position on screen
                subTalk.title("Chat Box")                #Give it a title.
                subTalk.visible(viz.ON)                  #Display the Message Box
                aRadio = subTalk.add(viz.RADIO, 0, "Hello.")        #Create a Radio button
                bRadio = subTalk.add(viz.RADIO, 0, "What is your street address?")
                cRadio = subTalk.add(viz.RADIO, 0, "What is your pet's name?")
                astext = "Hello."
                bstext = "What is your street address?"
                cstext = "What is your pet's name?"
                OKbutton = subTalk.add(viz.BUTTON, "OK")                #Create a button
                print aRadio.get()
               
viz.callback(viz.KEYBOARD_EVENT,mykey)

# Make an action when a BUTTON is pressed.
def onButton (button,state):
        global subtalk, OKbutton, aRadio, bRadio, cRadio, charTalk
        if button == OKbutton and state == viz.DOWN:
                aans = aRadio.get()
                bans = bRadio.get()
                cans = cRadio.get()               
                viztask.waitTime(1)                #Wait 1 second
                subTalk.visible(viz.OFF)  #Remove the Message Box
                if aans == 1:
                        charTalk = vizinfo.add("It's nice to meet you.")
                        print "A."
                elif bans == 1:
                        charTalk = vizinfo.add("Uh, that's personal. I'm Alex. Who are you?")
                        print "B."
                elif cans == 1:
                        charTalk = vizinfo.add("Uh, that's personal. I'm Alex. Who are you?")
                        print "C." 
                else:
                        print "none"
                charTalk.translate(1.0,.95)        #Set position on screen
                charTalk.title("Chat Box")                #Give it a title.
                charTalk.visible(viz.ON)                  #Display the Message Box
                print aans
               
                viztask.waitTime(2)                        #Wait 2 seconds to read avatar's response
                charTalk.visible(viz.OFF)                  #Remove the Message Box
                print bans
        else:
                print "place holder"
viz.callback(viz.BUTTON_EVENT, onButton)

def mytimer(num):
       
        viz.callback(viz.TIMER_EVENT,mytimer)
        viz.starttimer(0,0.01,viz.FOREVER)


#***********************************************************
#Adding a world
#***********************************************************
room = viz.add('panorama.ive')
room.scale(1,1,1)                  # scale actual
room.translate(0,0,0)        # position in the world


farshizzo 12-17-2007 02:08 PM

You are using the viztask module incorrectly. You need to create a function that uses the yield statement and schedule it using the viztask.schedule command. I modified your example to use the viztask module. Let me know if anything is unclear:
Code:

import viz

import vizinfo        #For message box
import viztask        #For wait time

viz.go()

male = viz.add('male.cfg')        #Add an avatar
male.translate(0,0,1)
male.rotate(0,1,0,180)
male.state(1)                                #Start in neutral state animation

face2 = male.face('biohead_talk.vzf')        #add a face to the avatar

smile = vizact.morph(0,2,0.5)                #Smiling face of male avatar
open = vizact.morph(5,0.5,0.5)        #mouth open morph of male avatar

def AvatarSmile():
        face2.add(smile)                #Smiling face of male avatar
        face2.add(open)                #Open mouth face of male avatar
        male.state(5)                  #Wave animation of male avatar
vizact.onkeydown(' ',AvatarSmile)

def StartQuestion():
       
        while True:
               
                yield viztask.waitKeyDown('5') #Wait for '5' key to be pressed
       
       
                subTalk = vizinfo.add("")                #Add the vizinfo object
                subTalk.translate(1.0,.95)                #Set position on screen
                subTalk.title("Chat Box")                #Give it a title.
                aRadio = subTalk.add(viz.RADIO, 0, "Hello.")        #Create a Radio button
                bRadio = subTalk.add(viz.RADIO, 0, "What is your street address?")
                cRadio = subTalk.add(viz.RADIO, 0, "What is your pet's name?")
                astext = "Hello."
                bstext = "What is your street address?"
                cstext = "What is your pet's name?"
                OKbutton = subTalk.add(viz.BUTTON, "OK")                #Create a button
               
                yield viztask.waitButtonDown(OKbutton) #wait for OK button to be pressed
               
                aans = aRadio.get()
                bans = bRadio.get()
                cans = cRadio.get()               
               
                yield viztask.waitTime(1)                #Wait 1 second
               
                subTalk.remove()  #Remove the Message Box
               
                if aans == 1:
                        charTalk = vizinfo.add("It's nice to meet you.")
                        print "A."
                elif bans == 1:
                        charTalk = vizinfo.add("Uh, that's personal. I'm Alex. Who are you?")
                        print "B."
                elif cans == 1:
                        charTalk = vizinfo.add("Uh, that's personal. I'm Alex. Who are you?")
                        print "C." 
                else:
                        print "none"
                charTalk.translate(1.0,.95)        #Set position on screen
                charTalk.title("Chat Box")                #Give it a title.
               
                yield viztask.waitTime(2)                #Wait 2 seconds to read avatar's response
                charTalk.remove()                                  #Remove the Message Box
               
#Schedule task that will ask user a question when '5' key is pressed and display a response
viztask.schedule( StartQuestion() )


#***********************************************************
#Adding a world
#***********************************************************
room = viz.add('panorama.ive')
room.scale(1,1,1)                  # scale actual
room.translate(0,0,0)        # position in the world


Karla 12-17-2007 03:13 PM

Hi,

Thank you for the reply!

I got the following to work. I will try your example also tomorrow. Perhaps both ways of turning the boxes on and off will be useful as I get more complex with the code.

Thanks,
Karla


Code:

#******************************************************************************************
#******************************************************************************************
#Sequence of interaction between avatar and user with avatar smiling and talking
#******************************************************************************************
#******************************************************************************************

import viz

import vizinfo        #For message box
import viztask        #For wait time

viz.go()

male = viz.add('male.cfg')        #Add an avatar
male.translate(0,0,1)
male.rotate(0,1,0,180)
male.state(1)                                #Start in neutral state animation

face2 = male.face('biohead_talk.vzf')        #add a face to the avatar

smile = vizact.morph(0,2,0.5)                #Smiling face of male avatar
open = vizact.morph(5,0.5,0.5)        #mouth open morph of male avatar

#Setting some info boxes
charTalkA = vizinfo.add("It's nice to meet you.")
charTalkA.translate(1.0,.95)                #Set position on screen
charTalkA.title("Chat Box")                #Give it a title.
charTalkA.visible(viz.OFF)                  #turn view off

charTalkB = vizinfo.add("Uh, that's personal. I'm Alex. Who are you?")
charTalkB.translate(1.0,.95)                #Set position on screen
charTalkB.title("Chat Box")                #Give it a title.
charTalkB.visible(viz.OFF)                  #turn view off

def displayAction(some_box, sec):
        some_box.visible(viz.ON)
        viz.waittime(sec)
        some_box.visible(viz.OFF)

# Make an action when a key is pressed.
def mykey(key):
        global subTalk, OKbutton, aRadio, bRadio, cRadio, charTalk
               
        if key == ' ':                            #if the pressed key is space bar
                face2.add(smile)                #Smiling face of male avatar
                face2.add(open)                #Open mouth face of male avatar
                male.state(5)                  #Wave animation of male avatar
       
        #Show a Transparent Message Box
        if key == '5': #if the pressed key is '5'
                subTalk = vizinfo.add("")                #Add the vizinfo object
                subTalk.translate(1.0,.95)                #Set position on screen
                subTalk.title("Chat Box")                #Give it a title.
                subTalk.visible(viz.ON)                  #Display the Message Box
                aRadio = subTalk.add(viz.RADIO, 0, "Hello.")        #Create a Radio button
                bRadio = subTalk.add(viz.RADIO, 0, "What is your street address?")
                cRadio = subTalk.add(viz.RADIO, 0, "What is your pet's name?")
                astext = "Hello."
                bstext = "What is your street address?"
                cstext = "What is your pet's name?"
                OKbutton = subTalk.add(viz.BUTTON, "OK")                #Create a button
                print aRadio.get()
       
viz.callback(viz.KEYBOARD_EVENT,mykey)

# Make an action when a BUTTON is pressed.
def onButton (button,state):
        global subtalk, OKbutton, aRadio, bRadio, cRadio, charTalk
        if button == OKbutton and state == viz.DOWN:
                aans = aRadio.get()
                bans = bRadio.get()
                cans = cRadio.get()               
                subTalk.visible(viz.OFF)  #Remove the Message Box
                if aans == 1:
                        viz.director(displayAction, charTalkA, 1)
                        print "A."
                elif bans == 1:
                        viz.director(displayAction, charTalkB, 2)
                        print "B."
                elif cans == 1:
                        viz.director(displayAction, charTalkB, 3)
                        print "C." 
                else:
                        print "none"
                print bans
        else:
                print "place holder"
viz.callback(viz.BUTTON_EVENT, onButton)

def mytimer(num):
       
        viz.callback(viz.TIMER_EVENT,mytimer)
        viz.starttimer(0,0.01,viz.FOREVER)

#***********************************************************
#Adding a world
#***********************************************************
room = viz.add('panorama.ive')
room.scale(1,1,1)                  # scale actual
room.translate(0,0,0)        # position in the world



All times are GMT -7. The time now is 10:53 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC