NodePath.find and DirectGUI

np = aspect2d.find('**/foo*')

Assuming I have created e. g. a DirectButton previously and named it ‘foo’ I will be able to find it this way. But the variable “np” returned by “find” is now a NodePath, and not a DirectButton.

I think understand why, because DirectButton inherits from NodePath, but it is a Python extension for NodePath and the C++ method “find” doesn’t know about it.

My question: I considered cleaning up a GUI layer by searching for GUI elements this way and then calling “destroy” on them. Is therea way to convert the NodePath returned by “find” into it’s original type (DirectButton)?

I can easily work around, e. g. by storing the GUI elements somewhere. It’s more a question of curiousity, so no priority at all.

Right, this is a problem everyone discovers at one point or another. It’s described in more detail on the Subclassing manual page.

The workaround is to save the Python handle somewhere you can access it. There’s no possibility of converting the NodePath you get back from find() into a DirectButton, because it isn’t a DirectButton at all. (It’s not even the same NodePath object, because a NodePath is a lightweight object that is created on the fly.)


Ok, this is what I already do. I was just curious if there is a magic “restore” function which takes a NodePath or PandaNode (PGButton, …) and returns an initialized DirectGui widget.