Calling Custom Method via runScript on a Template

So I have a template component (‘Temp_Comp’) that has some text overlayed on it. I have a Template Parameter called FontSize.
I have an Internal Property called Run_CustomMethod with an expression binding:
runScript("self.ChangeFont",0,{Temp_Comp.FontSize})

My Custom Method changes the font size over the template when the developer enters a FontSize on each template instance.

def ChangeFont(self, paramFontSize)
	from java.awt import Font
	# Get component object and global font
	text_component = self.getComponent("text")
	# paramFontSize = self.FontSize
	text_component.font = Font('Dialog',0,paramFontSize)

I did this all so that I can change the font size of each component I place on the screen without putting the designer in run mode. This seems to work fine when I am testing in the designer with the template…

MY PROBLEM:
When I drop instances of this template onto a screen and try to adjust the Template Property for “FontSize” the text no longer scales as it did when I had the tested this on the Template Master.

Any help would be appreciated! Thanks!!

Under “Layout” on your text component, if you’re using relative layout, try unchecking “Scale Font”.

I just tried that, but it didnt work.

This Forum Thread makes mention of the runScript() expression function creating unexpected behavior in templates. Im not sure if that’s what is going on here or if there is a work around…

Sorry, I originally unchecked “Scale Font” from the Template Instance. Once I unchecked it from the Template master, it worked on the Window! Thank you!

1 Like

For what it’s worth, we’ve recently been doing the majority of our template theming by using runScripts and have had no issues. Basically we use runScript to call a custom method on the template which then delegates to a script module (passing along the “self” reference from the custom method) that configures/updates the styling.

Combined with some global colors/fonts it makes it very easy to maintain a consistent look and feel across templates.