Focus on the textbox (blur)

Hello everyone,

I need help with the following situation: I have a program running on a workstation where the user needs to scan parts. Because of this, the focus must remain on the text field. I am using the Focus and onBlur events so that whenever the user clicks outside the field, the focus is automatically returned to the text field.
The station didn't have a keyboard the only interaction is by the touchscreen, the user can click on the buttons when needed.

The onBlur triggers a script as shown below.

def tf_focus(self):
	view = self.view
	view.refreshBinding("custom.Parameters.vUserID") 
	view.refreshBinding("custom.Parameters.vUserName")
	def waitFocus():
		from time import sleep
		sleep(.25)
		vPath = 'root/FlexMain/FlexSerialInfo/'
		if vViewDowntimeActive == 0 or vScrapinHold == 0:
			view.getChild(vPath + "lvSerialNumber").props.enabled = True
			if view.getChild(vPath + "lvSerialNumber").focus() != True:
				view.getChild(vPath + "lvSerialNumber").focus()
		else:
			view.getChild(vPath + "lvSerialNumber").props.enabled = False
			
	system.util.invokeAsynchronous(waitFocus)

textfied

I was wondering if this is the best approach.

I wouldn't use system.util.invokeAsynchronous with sleep, I would do:

from threading import Timer 

def waitFocus(self):
	view = self.view
	vPath = 'root/FlexMain/FlexSerialInfo/'
	if vViewDowntimeActive == 0 or vScrapinHold == 0:
		view.getChild(vPath + "lvSerialNumber").props.enabled = True
		if view.getChild(vPath + "lvSerialNumber").focus() != True:
			view.getChild(vPath + "lvSerialNumber").focus()
	else:
		view.getChild(vPath + "lvSerialNumber").props.enabled = False

def tf_focus(self):
	view = self.view
	view.refreshBinding("custom.Parameters.vUserID") 
	view.refreshBinding("custom.Parameters.vUserName")
	Timer(0.25, waitFocus, [self]).start()