DirectButton subclassing

does anybody knows why I can’t subclass a DirectButton?
here my code:

class midg_button(DirectButton):
    def __init__(self, parent = None, **kw):
      DirectButton.__init__(self, parent, **kw)

class ciccio(DirectObject):
  def __init__(self):
    DirectObject.__init__(self)
    butt=midg_button(
      pos=(0,0,0),
      text=("OK", "click!", "rolling over","disabled"),
      text_scale=.3,
      text_fg=(0,.99,0,1),
      scale=1,
      relief=DGG.FLAT,
    )

if __name__ == '__main__':
  app=ciccio()
  run()

with the above I can’t see the button but if I use the following the button shows correctly:

class ciccio(DirectObject):
  def __init__(self):
    DirectObject.__init__(self)
    butt=DirectButton(
      pos=(0,0,0),
      text=("OK", "click!", "rolling over","disabled"),
      text_scale=.3,
      text_fg=(0,.99,0,1),
      scale=1,
      relief=DGG.FLAT,
    )

if __name__ == '__main__':
  app=ciccio()
  run()

any clues there?

Subclassing a DirectGui item is not 100% straightforward. See this thread:
https://discourse.panda3d.org/viewtopic.php?t=2495

David

You’re the man David: I didn’t exactly got that trick but it works!

for reference here the working code:

class midg_button(DirectButton): 
    def __init__(self, parent = None, **kw): 
      DirectButton.__init__(self, parent, **kw) 
      #>>>added this and the button now shows himself
      self.initialiseoptions(midg_button)
 
class ciccio(DirectObject): 
  def __init__(self): 
    DirectObject.__init__(self) 
    butt=midg_button( 
      pos=(0,0,0), 
      text=("OK", "click!", "rolling over","disabled"), 
      text_scale=.3, 
      text_fg=(0,.99,0,1), 
      scale=1, 
      relief=DGG.FLAT, 
    ) 
 
if __name__ == '__main__': 
  app=ciccio() 
  run() 

thank you Dave!