Close popup window using close button template

I have several templates I'd like to use a close button template on.
I have the close button template with a template parameter of currentWindow. Here is the script I have applied to the button.

I dragged the template over on another template. I am having difficulties on what to bind the currentWindow template property to?

Is there a tag I should be creating which updates all the time when a new popup window is opened?

from javax.swing import SwingUtilities # https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/SwingUtilities.html#getAncestorOfClass(java.lang.Class,java.awt.Component)
from com.inductiveautomation.factorypmi.application import FPMIWindow # https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.45/com/inductiveautomation/factorypmi/application/FPMIWindow.html

window = SwingUtilities.getAncestorOfClass(FPMIWindow, event.source)
system.nav.closeWindow(window)

Should work on any button anywhere to close whatever window it's contained on.

Use the system function @zacht highlighted.

Is
window = SwingUtilities.getAncestorOfClass(FPMIWindow, event.source)
different from
window = system.gui.getParentWindow(event)

1 Like

Essentially, no:

But the system function is definitely preferred - first, you don't have to do any awkward importing, and second it takes care of some extra threading niceties and error messaging for you.

Totally forgot that it existed :smile:

1 Like