Embed a directgui object to a Textnode: howto?

David you told me that would be possible but seems I can’t find a way.
With this code…

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.DirectGui import *
import direct.gui.DirectGuiGlobals as DGG
#----
def printtext(t):
  print t
#----
if __name__ == '__main__': 
  denp=NodePath()
  de=DirectEntry(
    parent=denp,
    text="" ,
    pos=(0,-.5,0),
    scale=.03,
    command=printtext,
    initialText="",
    numLines = 1, width=15,
    focus=1,
  )
  tpGg1=TextGraphic()
  tpGg1.setModel(denp)
  #
  tpMgr = TextPropertiesManager.getGlobalPtr()
  tpMgr.setGraphic("gr1", tpGg1)
  #
  text=TextNode('tnode')
  tn=base.aspect2d.attachNewNode(text)
  t1="\5gr1\5\2"
  text.setText(t1)
  run()

…Panda3D quits abruptly with bad messages on console as follows:

Assertion failed: !is_empty() at line 269 of built/include/nodePath.I
Traceback (most recent call last):
  File "x.py", line 36, in <module>
    run()
  File "linuxroot/usr/share/panda3d/direct/src/showbase/ShowBase.py", line 2266, in run
  File "linuxroot/usr/share/panda3d/direct/src/task/Task.py", line 965, in run
  File "linuxroot/usr/share/panda3d/direct/src/task/Task.py", line 903, in step
  File "linuxroot/usr/share/panda3d/direct/src/task/Task.py", line 802, in __stepThroughList
  File "linuxroot/usr/share/panda3d/direct/src/task/Task.py", line 721, in __executeTask
  File "linuxroot/usr/share/panda3d/direct/src/showbase/ShowBase.py", line 1526, in __igLoop
AssertionError: !is_empty() at line 269 of built/include/nodePath.I

what I wrong?

This statement:

denp=NodePath()

creates an empty NodePath. This is a NodePath that has no node whatsoever; it’s like a NULL pointer. It’s completely different from this statement:

denp=NodePath('denp')

which creates a PandaNode named ‘denp’, then wraps a NodePath around it.

The first form will result in an empty NodePath being passed to your TextGraphic, which is illegal; the second form will work correctly.

But you don’t really need an intervening node. You could just pass the DirectEntry itself into the TextGraphic. Use parent = NodePath() when creating the DirectEntry so it doesn’t attach itself to aspect2d by default.

David

Actually, there might be an issue with DirectEntry within a TextGraphic like this. But DirectButton works.

David

issue confirmed - acting like you told it crashes issuing also a segfault:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.DirectGui import *
import direct.gui.DirectGuiGlobals as DGG
#----
def printtext(t):
  print t
#----
if __name__ == '__main__': 
  de=DirectEntry(
    parent=NodePath('denode'),
    text="" ,
    pos=(0,-.5,0),
    scale=.03,
    command=printtext,
    initialText="",
    numLines = 1, width=15,
    focus=1,
  )
  tpGg1=TextGraphic()
  tpGg1.setModel(de)
  #
  tpMgr = TextPropertiesManager.getGlobalPtr()
  tpMgr.setGraphic("gr1", tpGg1)
  #
  text=TextNode('tnode')
  tn=base.aspect2d.attachNewNode(text)
  text.setText("\5gr1\5\5")
  #
  run()

and also confirmed that the button works:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.DirectGui import *
import direct.gui.DirectGuiGlobals as DGG
#----
if __name__ == '__main__': 
  b=DirectButton(
    parent=NodePath('butt'),
    text=("OK", "click!", "rolling over", "disabled")
  )
  tpGg1=TextGraphic()
  tpGg1.setModel(b)
  tb=b.getBounds()
  print tb
  tpGg1.setFrame(*tb)
  #
  tpMgr = TextPropertiesManager.getGlobalPtr()
  tpMgr.setGraphic("gr1", tpGg1)
  #
  text=TextNode('tnode')
  tn=base.aspect2d.attachNewNode(text)
  text.setText("this is a button\n\5gr1\5\5\2")
  tn.setScale(.06)
  #
  run()

but not perfectly cos the text is partially overlapped by the button but this is a very minor issue even if confirms that the text stuff pretty needs a little overhaul.