PGEntry within TextProperties (Sometimes They Come Back)

here stuck again with Textproperties and stuff

I settled up an entry component that while is by himself, as showed in the following code, it works nice:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
#----
class myentry(PGEntry):
  def __init__(self, name="Entry", parent=aspect2d):
    PGEntry.__init__(self, name)
    self.setup(10,3)
    self.NP=parent.attachNewNode(self)
    #
    ACCEPT=self.getAcceptEvent(KeyboardButton.enter())
    DO=DirectObject()
    DO.accept(ACCEPT, self._onEnter)
  #
  def _onEnter(self, par=None):
    print self.getPlainWtext()
    print self.getPlainText()
    print self.getWtext()
    print self.getText()

#----
if __name__ == '__main__':
  #
  e=myentry(parent=base.aspect2d)
  e.NP.setScale(.06)
  #
  run()

but not if I stuff it into a Texproperties object like this:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
#----
class myentry(PGEntry):
  def __init__(self, name="Entry", parent=aspect2d):
    PGEntry.__init__(self, name)
    self.setup(10,3)
    self.NP=parent.attachNewNode(self)
    #
    ACCEPT=self.getAcceptEvent(KeyboardButton.enter())
    DO=DirectObject()
    DO.accept(ACCEPT, self._onEnter)
  #
  def _onEnter(self, par=None):
    print self.getPlainWtext()
    print self.getPlainText()
    print self.getWtext()
    print self.getText()

#----
if __name__ == '__main__':
  #
  e=myentry(parent=hidden)
  tpEntry1=TextGraphic()
  te=e.getFrame()
  tpEntry1.setFrame(te)
  tpEntry1.setModel(e.NP)
  #
  tpMgr = TextPropertiesManager.getGlobalPtr()
  tpMgr.setGraphic("Entry1", tpEntry1)
  #
  text=TextNode('tnode')
  tn=base.aspect2d.attachNewNode(text)
  text.setText("Lorem ipsum dolor sit amet,\n\n\5Entry1\5\2\n\nconsectetuer adipiscing elit.")
  tn.setScale(.06)

  run()

so: does anyone knows (my bet on the always awesome David) what’s going on there :question:

Yep. The problem is that the TextProperties makes a copy of the object by default. This is what you want it to do 99% of the time.

However, in the case of a PGEntry, you probably want to be able to query data on the original object after the user has made changes to the one onscreen. So a copy won’t do in that case; you need an instance.

Fortunately, I’ve recently added the necessary interface. If you pick up and build the latest Panda, you can add the line:

tpEntry1.setInstanceFlag(True)

and then it should work the way you want it to.

David

sure like gold David - works like a charm
thankyou!
PS: I win my bet :slight_smile: