bellm
October 5, 2018, 3:22pm
1
I would like to flash the background of a Text Field when that enter more characters then the max allowed. This is what I have right now:
import time
from java.awt import Color
TextField = event.source.parent.getComponent('Text Field')
startingColor = TextField.background
errorColor = Color(255,128,128)
if event.propertyName == 'text':
print len(event.newValue)
if len(event.newValue)>event.source.parent.MaxCharacters:
event.source.text = ''
TextField.background = errorColor
sleep(5)
TextField.background = startingColor
I found that this wont work becuase of the way the time function fires but can not think of another way to do it, any suggestions?
Definitely don’t call sleep from a GUI thread.
I would use an expression binding on the Text Field background instead. You could look at the current time in seconds and use a modulo operator to accomplish what you want.
Edit: Sounded like fun so I just went ahead and did it myself.
if((len({Root Container.Text Field.text}) > {Root Container.Text Field.MaxCharacters}) &&
(getSecond(now(1000)) % 2) ,
Color(255,128,128) , "White")
4 Likes
As a different approach, I changed the custom property to hold the length of the text. The style customizer than then be used to adjust setpoints and animations.
1 Like
bellm
October 5, 2018, 6:16pm
4
Thank you both for you replies. going to try this now.
To expand on the sleep() thing, because I didn't know this and almost did a bad with the project I'm working on:
[quote=“dlaki”]Anyone here have tried to to use time.sleep function of time module in Ignition?[/quote]Nick hints at this, but let me be more explicit:
Never, ever, use time.sleep or any other delay function in Ignition unless it is on its own asynchronous thread. Delays on the event dispatch thread (darn near everything in a client) will freeze the user interface for the duration of the delay.
Just say no to any form of sleep. When you need delays, always use system.util.invokeLater() with …
That thread gives the reasons why you shouldn't use sleep() and a few workarounds