How to Reset a numeric entry field while being focused on the component in Perspective

Hello!

I'm currently working in perspective and I'm having some trouble with having a numeric entry field resetting to 0 all while staying focused on this component so the user only has to use the keyboard and enter a number and hit enter. I also have a submit button as well as a table that needs gets updated whenever the user enters a number and submits it. So, I have custom method on this submit button that has a named query that stores the numeric entry into the database and then updates the table. Then I have a Message Handler that's supposed to reset the value in the numeric entry field to 0 and stay focused on the component.

On the Numeric entry field I have a script onActionPerformed that calls the custom method on submit button when the user hits enter on the keyboard.

When I try to run this, I'm able to submit a number but it doesn't reset back to 0 but it stays focused on the component. If I click away anywhere else on the screen it will reset to 0 but of course won't be focused. I've tried several different things, but it seems I can only do one or the other being I can get it to reset back to 0 but it won't stay focused or staying focused, but it won't reset back to 0.

I also have this application in vision and it works on vision, but we were trying to move it into perspective and ran into this problem. If anyone has any suggestions, it would be greatly appreciated! Thanks

I've removed the vision tag as your question is really about a Perspective problem. I think you're going to need to show some code. Please see Wiki - how to post code on this forum.

It seems that requesting the focus back to the numeric entry after you change the value is happening so quickly that the value is not committed.

I added a one second delay and it worked. This is probably not the final solution, but explains what the problem is.

from time import sleep
# set value
sleep(1)
# request focus
1 Like

Text fields have the optional flag rejectUpdatesWhileFocused that will cause the text field to act like this when it is enabled. I imagine something similar is happening with the NumericEntryField in this case, but there is no option to disable it.

I tried taking focus off of the field for a moment and refocusing it after the script completed. But it seemed to cause a race condition that would cause issues without some sort of sleep which is definitely not the best.

    import time
	val = self.getSibling('NumericEntryField').props.value
	
	self.getSibling('Label_0').props.text = 'New Value = %d' % val
	
	self.view.getChild('root').focus()
	self.getSibling('NumericEntryField').props.value = 0
	time.sleep(0.1)
	self.getSibling('NumericEntryField').focus()
1 Like

Yeah that's the thing about sleep, it could lock up the entire client. Like you said it's not the best way to do it. Adding a Delay to a Script | Ignition User Manual

sleep is less of a problem in Perspective than it is in Vision, that comment is made at Vision.

It will only do this in Vision, not in Perspective. In Perspective it will hold up the thread running the code, and the more held threads you have the more threads will be generated leading to reduced gw performance.
In Vision, all scripts run on the EDT (event dispatch thread). Holding this up with sleeps or any other long running code will stop the client from responding to user actions while the script is running.

It looks like that user manual reference is aimed at Vision