How to know if user closed popup via <Esc> key

Have a popup that is configured with (Show close button) disabled.

The popup has a button that closes the view. Is there a way (like in onShutDown event) to know if the user closed the popup via the (Esc) key or if the user closed the popup by clicking the button?

Not an easy way, no.

In theory you could make a new Key Handler event oriented around the Escape key and set some custom session property, and then in the onShutdown event you could reference that session property, but you would also need to include some sort of invokeAsync usage within the Key handler event to reset the session prop after so many seconds so that your stored value isn’t “stale”.

Yeah that sounds complicated ha

I’ve been playing around with a global or (project scoped) boolean variable called similar to ViewWasCanceled = True. The view’s onStartUp sets it = True too. The only event that sets it to False is the button I mentioned in my original post. This seems to work. I can check ViewWasCanceled in onShutDown and it seems to test correctly. After lunch, I’ll try to break this logic using 2 PCs and see how it works. But my understanding is that each session gets its own copy, its own instance of the project scripts?

Project scripts are executed on the Gateway, so I would expect any project to use any sort of singleton created in a project script. Session properties do indeed belong to individual sessions.

1 Like

In Scripting Project Library I have a boolean variable
Globals.ViewWasCanceled = True

In the view’s onStartup I have this line
Globals.ViewWasCanceled = True

In the view’s button onActionPerformed I have this code

# other code here
Globals.ViewWasCanceled = False
system.perspective.closePopup('a123456')

In the view’s onShutdown I have this code

if Globals.ViewWasCanceled == True:
	# code here for ViewWasCanceled == True:

And this seems to do what I need. Am I missing something obvious or does this seem like it should work reliably?

How are you creating Globals ? And are you passing it around in function arguments? Because otherwise it is probably not session-specific (one client’s use of the popup would interfere with other clients).

Globals is the name if the Project Library (script)

like this . .

I’m not passing it around, I’m just accessing it directly from the mentioned events
I’m testing this on 2 different pcs. it seems to work though

Open the popup on both clients. Close correctly on one, then immediately escape from the other.

I tried opening the popup on two different PCs. It seems to work perfectly. To me, it seems that each has its own instance of the boolean variable Globals.ViewWasCanceled

It even seems that the script console has its own instance of it too?

I wouldn't expect so.

Definitely. Not executing in the same computer at all.

1 Like

Well, I don’t know where our disconnect might be but, I have another helping me test this now, we absolutely cannot force one client to change the boolean’s value on the other client?

I don’t understand how one could have a unique script instance (as it seems like you are agreeing with @rvaught) without having a unique session, session ID is even a property that can be tracked.

At the top level of the project script, use system.util.getLogger() to log a message to the gateway wrapper. See if it fires for every client session.

1 Like