PGItem's setup

Hi all )

I setup the button in this way:

np=NodePath(…)
btn=PGButton(‘my_btn’)
btn.setup(np,np,np,np) #just for test

I expect the identic appearence in all button states, but in ‘rollover’ state button looks shaded. How to switch off internal behaviour (i want to see clear texture)?

There is no automatic shading behavior in PGButton; and in fact when I try the below program I observe no shading:

from direct.directbase.DirectStart import *
from pandac.PandaModules import *

tn = TextNode('tn')
tn.setText('button')
tn.setTextColor(0, 0, 0, 1)
tn.setCardColor(1, 1, 0.5, 1)
tn.setCardAsMargin(0.2, 0.2, 0.2, 0.2)
np = NodePath(tn.generate())

btn = PGButton('my_btn')
btn.setup(np, np, np, np)
bn = aspect2d.attachNewNode(btn)
bn.setScale(0.2)

run()

David

new assumption, miracles occur when setting the texture:

from direct.directbase.DirectStart import *
from pandac.PandaModules import *

##tn = TextNode('tn')
##tn.setText('button')
##tn.setTextColor(0, 0, 0, 1)
##tn.setCardColor(1, 1, 0.5, 1)
##tn.setCardAsMargin(0.2, 0.2, 0.2, 0.2)
##np = NodePath(tn.generate())

np=loader.loadModel('testButton.egg')
state_set=[np]
for sufx in ('depressed','rollover','inactive'):
    temp_np=np.copyTo(NodePath())
    temp_np.detachNode()
    tex=Texture()
    tex.read('testButton_ready.bmp')#one for simplicity
    temp_np.setTexture(tex)
    state_set.append(temp_np)

    
def testShowStates(states):
  z=0.8
  for node in states:
     node=node.copyTo(NodePath())
     node.detachNode()
     node.setScale(1)
     node.setName('del_me')
     node.reparentTo(aspect2d)
     node.setPos(-0.8,0,z-0.22)
     z-=0.4

    
btn = PGButton('my_btn')
btn.setup(state_set[0], state_set[1], state_set[2], state_set[3])
bn = aspect2d.attachNewNode(btn)
bn.setPos(0.2,0,0)
bn.setScale(1)
testShowStates(state_set)

run()

So are you saying the problem is now solved and you understand what went wrong before, or are you saying the problem is still unsolved and showing a bit of code to reproduce it? (I can’t actually run that code without your egg and bmp file.)

David

The problem persists. It is clear that PGButton not guilty. I think something with the texture settings (all states are darker than the initial)?

http://panda3d.org.ru/_fr/1/button_states.zip

The problem is your egg file, which defines the advanced texture property saved-result. Any advanced texture properties compel Panda to construct a special TextureStage for this texture instead of the default TextureStage.

Then, when you do model.setTexture(tex), you are applying your new texture on the default TextureStage, which accumulates with the existing texture instead of replacing it. That’s why it appears darker.

If you want to replace it, you should either find the existing TextureStage first, with:

    ts = temp_np.findTextureStage('*')
    temp_np.setTexture(ts, tex, 1)

Or disable the existing TextureStage first, with:

    temp_np.setTextureOff(1)
    temp_np.setTexture(tex, 1)

Or edit your egg file to remove the saved-result setting.

David

Thanks. TextureStage, at the moment, for me - a black hole, went to digest.

Can I ask what’s a PGButton?
I only know of DirectButton…

It’s the button class of the Panda GUI system. DirectButton is a Python-based wrapper around it.

So… there’s no DirectGUI for C++ users?

DirectGUI is a Python interface. PGui is the underlying C++ interface.

David

So is it just naming difference between the Python wrappers and the original C++ classes?

because the original poster is also using Python.

No. DirectButton is a higher-level wrapper around the PGButton class. Obviously PGButton is also exposed to Python (otherwise DirectButton couldn’t exist).

[color=red]New question

This is my long way to get mouse position (in the scale of aspect2d ), is there any short decision ?

class HaHa(PGItem, DirectObject):
   def __init__(self):
      . . .
      self.accept (self.getPressEvent(btn_obj),
                   self.__class__.__dict__[btn_name+'_Action'],[self])
   . . .
   def mouse1_Action(self, args):
       vc=VBase2 (0.0, 0.0)
       vc=args.getMouse()+vc
       vc=VBase3 (vc.getX(),0.0, vc.getY())
       pnt=aspect2d.getRelativePoint(render2d, vc)
       print args, pnt

Not sure what you’re asking. The only function call there with any meat in it is getRelativePoint(); the rest of it is all fluff which you don’t necessarily need. Are you asking how to eliminate the fluff, or are you asking if there is some other method than getRelativePoint()?

David

I found the solution in DirectGuiBase.editStart()(i have a similar task to move window in realtime).

[color=red]New question

from panda3d.core import *
from direct.showbase.DirectObject import DirectObject 

if __name__=='__main__':
   from direct.showbase.ShowBase import ShowBase
   from direct.showbase.DirectObject import DirectObject
   app=ShowBase('test_app')

class guiEntry(PGEntry, DirectObject):
   def __init__(self):
      PGEntry.__init__(self, 'test_entry')
      DirectObject.__init__(self)
      np=aspect2d.attachNewNode(self)
      np.setPos(0,0,0)

if __name__=='__main__':
   en=guiEntry()
   en.setup (0.3, 1)
   en.setFrame(0.0,0.5,0.0,0.4)
   en.setBlinkRate (1.5)
   en.setActive (1)
   en.setFocus (1) 
   en.setMaxChars (100)
   en.setState(en.SFocus)
   
   fs=en.getFrameStyle(0)
   fs.setType(fs.TFlat)
   fs.setColor(0.2,0.7,0.7,1)
   fs.setWidth(0.05,0.05)
   en.setFrameStyle(0, fs) 
   ''' # way 1
   pgi_txt=en.getTextNode()
   pgi_txt.setTextColor(0.9,0,0,1)
   pgi_txt.setGlyphScale(0.2)
   pgi_txt.setText('start')
   en.addChild(pgi_txt)
   ''' # way 2
   text_def=en.getTextDef (en.SFocus)
   text_def.setGlyphScale(0.2) # no effect
   en.setText('ggoo')
   text_def.setText('ggoo')
   text_def.setTextColor(0.9,0,0,1) # no effect
   #NodePath(text_def).setPos(-0.4,0,0.4)
   #en.addChild(text_def)
   #'''
   cr=TextNode('cursor')
   cr.setText('<')
   cr=NodePath(cr.generate())
   cr.setScale(0.2)   
   str_end=len(en.getPlainText())
   en.setCursorPosition (str_end)
   en.getCursorDef().node().removeAllChildren()
   cr.reparentTo(en.getCursorDef())
   
   app.run()

Сan not set text properties (color, scale) through TeхtNodе obtained by PGEntry.getTextDef(0)/way1/ and TextNode obtained by PGItem.getTextNode() /way2/ is not processed by method PGEntry.getPlainText() (for example), PGEntry.getProperties() returns const object. Not yet used the font. How to set entry-text color, scale …in general, how to control it?

You have to set an explicit TextNode first:

en.setTextDef(en.SFocus, TextNode('tn'))

David

not obvious (
I called PGItem.getTextNode() without pre-initialization, and everything seems all right, using PGEntry.getTextDef(0).setText(’…’) and it is displayed (hence the object exists).
What is the purpose of the PGEntry.getProperties()? Only for copy?

I agree it’s not obvious, but you are mucking around with the low-level objects here, instead of using the high-level DirectEntry. Since you’re using low-level objects, you have to expect the occasional nonobvious interface; these objects weren’t really intended for direct manipulation by end-users.

PGEntry.getProperties() is read-only, and is intended for querying the properties at a particular character position in the string. This might be useful if embedded property changes are present within the string (e.g. for RTF input).

David