Customizing Tag Browse Tree

Hi Paul,

I’m not sure if I should start a new thread or not, but I’m having a weird issue with the Tag Browse Tree fonts as well. I have 2 buttons on a screen, one to increase the font by 2, the other to decrease it by 2. The code behind the buttons works fine in Designer, so I deployed it to the production system (running windows), but this morning when I tested it in my dev environment (Ubuntu), it still works in designer, but does not work when I launch a client.

I had to add the .visible flag and .showRootNode flags to get the Tag Browse Tree to refresh properly (that is the only reason it is in the code).

I’ve also played with the Script Editor for mouseClicked, mousePressed, and mouseReleased thinking it could be a race condition somewhere as when I run it in the Linux client, if I hit the Font minus button, some times it increases…

Thoughts?

from java.awt import Font
#Forcing the showRootNode and visible flags to 0, then to 1
#forces a refresh of the font.
event.source.parent.getComponent('Tag Browse Tree').visible = 0
event.source.parent.getComponent('Tag Browse Tree').showRootNode = 1
oldfontplus = event.source.parent.getComponent('Tag Browse Tree').font
sizenewplus = oldfontplus.size + 2
newFontplus = Font('Dialog',0,sizenewplus)
#newFontplus = oldfontplus.deriveFont(sizenewplus)
event.source.parent.getComponent('lblFontSize').text = "Size = %s" % str(int(sizenewplus))
event.source.parent.getComponent('Tag Browse Tree').font = newFontplus
event.source.parent.getComponent('Tag Browse Tree').showRootNode = 0
event.source.parent.getComponent('Tag Browse Tree').visible = 1

@PGriffith, I also found another forum entry for changing the colors, so I tried modifying that code as well (works fine in Designer, but not in the Vision Client):


from javax.swing.tree import DefaultTreeCellRenderer
from javax.swing.plaf import FontUIResource
cellRenderer = DefaultTreeCellRenderer()
btr = system.gui.getParentWindow(event).getComponentForPath("Root Container.Tag Browse Tree")
oldfont = (event.source.parent.getComponent('Tag Browse Tree').font).size
newFont = FontUIResource('Dialog',0,(oldfont-2))
cellRenderer.setFont(newFont)
btr.viewport.view.setFont(newFont)
btr.setFont(newFont)

@koryk
I moved these posts to a new thread, just to make it easier to track.

I don’t have any great advice - it seems like what you’re doing should be working, without diving into it myself. It’s possible that a repaint() event is being fired (most likely, by the showRootNode/visible property changes) and on repaint, the component is resetting the font settings to default.

1 Like

Thanks for looking. I’ve opened a ticket with support.

Kory

So, after much troubleshooting with Inductive Automation tech support (thanks Tyler!), reading the font back before adding 2 to the size was the issue. It seems to reads from a different location, or it reads before the new changes have propagated throughout the Gateway. To correct this behaviour, I added a Custom Property to the Root Container called storedFont (type integer), and set the default value to 12. Then I execute the following on a button:

from javax.swing.tree import DefaultTreeCellRenderer
from javax.swing.plaf import FontUIResource
cellRenderer = DefaultTreeCellRenderer()
btr = system.gui.getParentWindow(event).getComponentForPath("Root Container.Tag Browse Tree")
savedFontSize = event.source.parent.storedFont
newFontSize = savedFontSize + 2
event.source.parent.storedFont = newFontSize
newFont = FontUIResource('Dialog',0,newFontSize)
btr.viewport.view.setFont(newFont)
btr.viewport.view.setCellRenderer(cellRenderer)

So one thing I learned from this is exported templates also seem to export the Component with them, and although the running production system is running Gateway v7.9.12, but the template I modified is OLD, so it is using a very old version of the Tag Browse Tree which doesn’t exhibit this behaviour.

One important thing to note is that using the

btr.viewport.view.setFont(newFont)

breaks the ability to set the font from the Property Editor within designer. Oh well, win some, lose some :wink:

1 Like