Blinking a Text Field backgroud by Scripting

Hi
I know there are several and simple ways of doing this, but I’m working on a template and my bindings are indirect. Depending of memory tags that are high and low alarm values. I want the background to blink. I have made my scripting;property change to be indirect and my background does change but is static to red but I want it to blink for example 1s.
Of course I can solve this with a timer and make some binds with custom property and use an “if” statement but I want to make it like an animation. Exactly like Style Customer does.

The code that turns background to red is:

if value <= lowAlarm:
    event.source.background = system.gui.color(255,0,0)		
elif value >= highAlarm:
	event.source.background = system.gui.color(255,0,0)

The code I was trying but cause the client to crash.

import time
def animated():
   event.source.background = system.gui.color(255,0,0)#red
   time.sleep(1)
   event.source.background = system.gui.color(255,255,255)#white
   time.sleep(1)
	
if value <= lowAlarm:
	animated()		
elif value >= highAlarm:
	animated()

I know there should be a break statement somewhere but I can’t make it work
Please some help.

I recommend using the style customizer to set up with example low and high alarms, then use cell bindings in the style dataset to replace those values with your indirect tag binding results.

You are crashing your client because you are using sleep() in a foreground task. Never do this. If you have a process need for a sleep() call, you must use a background thread (via invokeAsynchronous), which are not allowed to interact with gui components.

1 Like

Hi @pturmel
You are so right, I haven’t noticed that property there. I’m pretty new in Ignition
Regards