Closing a vision popup by pressing Esc

Hi,

How can I close a custom popup window by pressing Esc ?

On Buttons there is a property “Default Button” making it respond to an Enter pressed on the window, but how can I do a similar behavior with a cancel or close button when pressing Esc ?

Thanks for the help

We use the code below (as a client event script, triggering on the ESC key)

windows = system.gui.getOpenedWindows()

for window in windows:
	try:
		isPopUp = ((not window.startMaximized) and (window.closable))
		if (isPopUp and window.isSelected()):
			system.nav.closeWindow(window)
			break
	except:
		pass
1 Like

How do you do such a script ?
When you say a “client event script” is this a script you put in the Scripting/Project Library folder ?

No, here:

2 Likes

In V8 it was in a slightly different place but it is still quite similar to your printscreen:

It’s now working well. Thank you very much for your help !

I was looking at this code earlier today because I wanted to add this functionality to my project, but my project uses multiple desktop instances, and I discovered that this solution only works with the primary desktop. I developed the code a little bit further, so that it will work no matter how many desktop instances are open. I’m still running it off of the ESCAPE(Released) Client Event Script.

Here is the code in case anybody could use it:

def closeTheWindow(testWindow,selectedDesktop):
	import system
	if testWindow.isFocused():
		windows = system.gui.desktop(selectedDesktop).getOpenedWindows()
		for window in windows:
			try:
				isPopUp = ((not window.startMaximized) and (window.closable))
				if (isPopUp and window.isSelected()):
					system.nav.desktop(selectedDesktop).closeWindow(window)
					break
			except:
				pass
from javax.swing import JFrame,SwingUtilities
header = ["DesktopHeaders"]
desktopList = system.gui.getDesktopHandles();
desktopColumn = [[desktop] for desktop in desktopList]
desktopSet = system.dataset.toDataSet(header, desktopColumn)
desktopCount = desktopSet.getRowCount()
closeTheWindow(SwingUtilities.getAncestorOfClass(JFrame,system.gui.desktop().getWindow(system.nav.desktop().getCurrentWindow())),system.gui.getCurrentDesktop())
for desktop in range(desktopCount):
	selectedDesktop =  desktopSet.getValueAt(desktop, 0)
	closeTheWindow(SwingUtilities.getAncestorOfClass(JFrame,system.gui.desktop(desktopSet.getValueAt(desktop, 0)).getWindow(system.nav.desktop(desktopSet.getValueAt(desktop, 0)).getCurrentWindow())),selectedDesktop)
1 Like