Script - update property

Hi,

I have the following script on key released:

from time import sleep
if event.keyCode == event.VK_ENTER:
	if event.source.text == event.source.parent.getComponent('Label 9').text:

	#advance to next filed	
		event.source.parent.getComponent('Input1').requestFocusInWindow()
	else:
		event.source.text = "Incorrect Unit Serial Number"
		sleep(3)
		event.source.text = ""

Not sure why is not working properly.

event.source.text = "Incorrect Unit Serial Number"

is never displayed. Script just go to:

event.source.text = "".

Regards
Pawel

You can’t (safely) use any form of sleep in event routines. You aren’t seeing the text display because your UI is freezing during the sleep, never giving your component (or any other) a chance to redraw themselves with the changes. You must use timer events or a timer component or an invokeLater() call to defer an action.

Here is a link for system.util.invokeLater() function in case you are unfamiliar with how it works.

Thanks for quick replay.

I tried this script:

from time import sleep
if event.keyCode == event.VK_ENTER:
	if event.source.text == event.source.parent.getComponent('Label 9').text:

	#advance to next filed	
		event.source.parent.getComponent('Input1').requestFocusInWindow()
	else:
   		def clickButton(button = event.source.parent.getComponent('Refresh')):
	   		import system
	   		button.doClick()
	   		system.gui.messageBox("Button has been clicked!")
  
	# Tell the system to invoke the function after
	# the current event has been processed
		system.util.invokeLater(clickButton)```

and I am getting this error.
Error running function from fpmi.system.invokeLater.

But it will be even better when I can call messageBox' for 3 seconds and then automatically closed and get back focus in window to correct the scan entry.

So the process look like:
Scan first entry verify against another value if not match then notify operators somehow.
Option 1. by displaying message in input text field for few seconds then automatically clear entry.
Option 2. Pop up message box with information. Unfortunately operators has only scanner to scan entries and no mouse or keyboard, so in option 2 message box will need to disappeared after few seconds automatically.

Regards
Pawel

Maybe try something like this

if event.keyCode == event.VK_ENTER:
    scan = str(event.newValue)
    stringCheck = event.source.parent.getComponent('Label 9').text
    if scan == stringCheck:
         your logic here
    else:
         def reset():
               event.source.text = ''
         event.source.text = 'Scan Rejected!'
         system.util.invokeLater(reset,3000)