Focus on Text Box Loses Cursor

Good Morning,

I’m working in Perspective, Gateway 8.0.16.

I have a pretty basic setup where a menu item is clicked, and kicks off 2 events: 1) An Embedded View loads a new view, and 2) a Text Field is given focus.

The problem I’m having is that the Text Field is given focus properly half the time, and the other half, it is given focus (based on console messaging on the onFocus event and the outline around the component) but the cursor won’t be in the component. I can tell that focus wasn’t lost (because of console messaging on the onBlur event, and the outline on the component) but the cursor hasn’t moved to the Text Field.

Any thoughts on what could be stealing my cursor, or how to get it back while the Text Field has focus? Best guess is it’s a timing issue with the view loading, but I have put the focus call as late in the sequence as I can.

I’m using a message handler on the Text Field with the following code to give it focus:

system.perspective.print('focus given by message handler')

For anyone who is interested, I fixed the problem by adding a 1/4 second delay before calling focus to Text Field:

from time import sleep

system.perspective.print('focus given by message handler')

I’m not excited by this solution, but it seems to separate the loading of the new view in the Embedded View from the focus setting enough that they no longer fight each other and end up with the lost cursor.

I’d be interested in anyone else has a better reason or solution for this behavior.


I cant describe how much you have helped me, I love you


bro, this is perfect!
@cmallonee Question: why does adding sleep to this, and m.boog's code make this work?

Seems like it should be sequential operation of code, should send the message and the message receiver should activate. But until I added sleep, the message receiver did not fully work.

def runAction(self, event):
	from time import sleep
	self.view.custom.edit_qty_left = True
#	self.parent.parent.getChild("FlexContainer_2").getChild("QtyLeft_1").focus
	self.view.getChild("root").custom.qtyLeft_focus = 1
	message = "get_focus_qtyLeft"
	system.perspective.sendMessage(messageType = message)

Message Receiver: (The background color changes without the sleep, but both lines run with the sleep.

def onMessageReceived(self, payload):
	if self.view.getChild("root").custom.qtyLeft_focus == 1:
	self.parent.parent.getChild("Spacer_1").getChild("Label") = '#C79393'

Holy crap I wish I saw this sooner. Thank you