Who told you that the text is static ? It’s modifiable if you use mayChange=1.
Take advantage of offscreen DirectEntry and instance it to the avatar’s top, so you would get the blinking cursor too.
from pandac.PandaModules import *
loadPrcFileData('','''
sync-video 1
''')
import direct.directbase.DirectStart
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *
from direct.showbase.DirectObject import DirectObject
import sys
class World(DirectObject):
def __init__(self):
base.setFrameRateMeter(1)
base.disableMouse()
camera.setY(-15)
self.startChatKey='enter'
self.accept('escape',sys.exit)
self.acceptOnce(self.startChatKey, self.startTextInput)
dummy=render.attachNewNode('dummy')
smi=loader.loadModel('smiley')
smi.reparentTo(dummy)
smi.setX(3)
dummy.hprInterval(5,Vec3(-360,0,0)).loop()
chatTextParent=aspect2d.attachNewNode('chat text dummy')
self.chatTextDE = DirectEntry( parent=chatTextParent,
width=20, numLines=3,
frameColor=(0,0,0,0),
text_fg=(1,1,1,1), #text_shadow=(0,0,0,1),
text_align=TextNode.ACenter,
text='SMILEY', # the name
text_pos=(0,-1.2),
initialText='_____________ press Enter to chat _____________',
command=self.stopTextInput)
chatTextParent.setZ(-5) # put it offscreen
# self.chatTextDE.hide()
# dummy node for the billboard, or else the result would be weird
# if there is translation on the node
chatTextOutputParent=smi.attachNewNode('chat text dummy')
self.chatTextOutput=self.chatTextDE.instanceUnderNode(chatTextOutputParent,'chat text')
self.chatTextOutput.setScale(.2)
self.chatTextOutput.setZ(smi.getTightBounds()[1][2]+1) # put it above smiley
chatTextOutputParent.setBillboardPointEye()
def startTextInput(self):
self.chatTextDE.show()
self.chatTextDE['focus']=1
# setting '' as text places the cursor on the left side, not center.
# So use space, nobody would notice.
self.chatTextDE.set(' ')
print 'START INPUT'
def stopTextInput(self,c):
# keypress input check is performed after DirectEntry command,
# so let a frame pass by before accepting the key
taskMgr.step()
self.acceptOnce(self.startChatKey, self.startTextInput)
print 'STOP INPUT',c
World()
run()