Making DirectEntry text property changes instantly visible


Is there a straightforward way to change the text color (or other text property, like font) of a DirectEntry and see the result instantaneously?

Accessing the underlying TextNode and changing the desired property works only for text typed after the change. Doing something like entry.set(entry.get()) does not take effect immediately either.

The only little hack I found was to predefine multiple TextNodes with different property settings and assign them to the DirectEntry as needed using:

entry.guiItem.setTextDef(0, text_node_arial_green)

Is that the only way, or I missing something obvious?


Hmm, if you call setTextDef(0, newNode) repeatedly, does it change live with each call? Or do you need to assign a different one to each state?


Hi David, thank you for your reply.

Yes it does, that’s why I have adopted this method to change text properties on-the-fly. A bit of a roundabout way, but it works.

Yes again. When the DirectEntry loses focus, the text changes back to the default properties, so I also need to assign the newNode to state 1 if I don’t like that.

Let me recap, so there are no misunderstandings:

  • What I would like:

[list][*]My intention is to change properties of the text that has already been typed into the DirectEntry, and to see those changes from the very frame that I make them.

]What I see:

  • After I typed some text, it keeps its properties even after I change those properties on the underlying TextNode, using for example [color=darkblue]entry.guiItem.getTextDef(0).setTextColor(0., 1., 0., 1.) (or doing it the “intended” way - [color=darkblue]entry[“text_fg”] = (0., 1., 0., 1.) - which has the exact same effect) to set the text to green.
    Text typed after that change is green, but the previous text (to the left of that green text) simply remains black.
    UPDATE: I just noticed that the changes only take effect from the second character onward after the change. So if I type “123”, then change the color to green and type “456”, “4” will still be black and only “56” will be green.

  • Calling [color=darkblue]setTextDef(0, newNode) does work, but only for state 0 (entry has focus), so I also need to call [color=darkblue]setTextDef(1, newNode) if I still want to see the text with the desired properties when the entry loses focus.
    [/*:m][/list:u]Could it be, that once text is typed into the DirectEntry, it gets merged into its own GeomNode and becomes independent from the TextNode that generated it? That might explain this behaviour.

Yes, that is exactly what happens. The PGEntry is trying hard to optimize this (it’s an unusual problem because the text changes frequently, but usually with the addition of one letter at a time).

Changing the text properties on the fly is something we simply never considered, so there aren’t any hooks to handle it the way you’d expect it to work. I agree it would be nice if it did work in the expected way, though. Perhaps you could file this as a bug over at launchpad.


Thank you for the explanation, David.