font.deriveFont problem

Good morning!

I’m struggling to make work a simple font size change via scripting of a numeric label.

I create I template where I count the actual active alarms and according to the totalizer I change the font size.

I try using this code:

lblConteggioAllarmi = event.source.getComponent('lblConteggioAllarmi')
lblConteggioAllarmi.font = lblConteggioAllarmi.font.deriveFont(60.0) 

and this just to be sure to call the exact component:

event.source.getComponent('lblConteggioAllarmi').font = event.source.getComponent('lblConteggioAllarmi').font.deriveFont(60.0) 

but in both cases I have no size font change.

Where do I wrong?

Thank you for the help.

Both should work BUT

I think you mean

event.source.parent.getComponent('lblConteggioAllarmi').font = event.source.parent.getComponent('lblConteggioAllarmi').font.deriveFont(60.0)

Note you’re missing parent key words

Good morning jespinmartin1,
I’ve just tried to change the line in

event.source.parent.getComponent('lblConteggioAllarmi').font = event.source.parent.getComponent('lblConteggioAllarmi').font.deriveFont(60.0)

but I have this error:

Traceback (most recent call last):
** File “event:propertyChange”, line 71, in **
TypeError: getComponent(): 1st arg can’t be coerced to int

Ignition v8.1.6 (b2021052512)
Java: Azul Systems, Inc. 11.0.11

where line 71 is the one I’ve just edit.

No, the parent keywords weren’t missing. (I presume that the propertyChange event is on the root container.)

I think you are running into the fact that the font on a label is evaluated only when text is to be drawn. As a passive property, .font doesn’t generate a change event itself. (It doesn’t show up in a property binding list as a possible source.) So the font property is likely changing, but the label isn’t being redrawn. You’ll probably have to assign to its .text property to make it redraw.

Yes you are right, I manage the script on the root container and I have custom property for the different alarms (active, clear, ack and unacked). Then I make the count and I would like to change the font size according to the number of alarms ( <10 between 10-99 and >100 ).

Thanks for your help, I’ll try to play on the text and I’ll let you know the result.

Then you are calling the script from itself. In that case just do
event.source.font=event.sount.font.deriveFont(60.0)