How is text connected to the PGButton?

I found that I can use node().getFrame() to work out the width and height of the button but I am now trying to find out how the text, which is displayed on the button, is stored.

Ive tried going down the API and trying to trace what DirectButton does but Im kinda lost.

Any help greatly appreciated.

It is pretty mysterious. The TextNode that renders the text, like all other geometry visible on the button, is parented to one of (or, more commonly, all of) the button’s various “state” NodePaths, which are made visible when the button is in each of its states. I could help you walk through the full mechanism, but it is indeed complicated, and maybe you’re asking only because you actually have a different question–like “how do I modify the text”?

If you have a question like that, there is actually a very simple answer, since the DirectButton does provide an API for changing properties of the text (and most other things). In particular, you can do button[‘text’] = ‘My new text’.

I don’t mean to dodge your original question, though. If you are actually curious about how the DirectButton works internally, then there are indeed answers for you, and you will find them along a convoluted, but interesting, path.

David

Thanks, just needed a pointer in the right direct.

You didnt dodge it entirely. :wink:

I had a couple mins to look further over the weekend. I went to the source and walked through the inital setup of the PGButton. Then it became clear, I think, as to what goes on :slight_smile:

Each state has a nodepath which may refer to the same TextNode.
I wrote a quick (and horrible!) recursive function to print out the various state nodes of a button. Its very interesting to see how this is coupled together.

I would not say its complicated as it is nice and logical.

Now I can getText() and setText() on the TextNode. Ok, so there is no real point in doing anything like this. But its nice to understand :slight_smile:

Thanks for initial pointer.