Closing stranded popup windows

Hello all… Ok, first and foremost, I am a complete noob to ignition.

I have a project where I am using multiple tab strips.

These tab strips are not docked and navigation is controlled by script (they actually appear below other docked templates). The tabs open naked popup windows (sans title, close, borders, etc). The tabs work correctly when the Main Window containing the tabs is open, however, when navigating away from this Main Window, the last sub-tab popup window opened does not close. Question: In script, how can I identify the currently opened popup window and close it when the parent window closes.

Here is the current code I have for tab navigation: Note that this is scripting for a single tab (hilighted) and is fired off the propertyChange of the Tab

if event.source.selectedTab == 'North Racks Layout'\
    and event.source.visible:
	system.nav.closeWindow('Main Windows/ASRS/SouthRacks')
	window = system.nav.openWindow('Main Windows/ASRS/NorthRacks')
	system.nav.centerWindow(window)
else:
	system.nav.closeWindow('Main Windows/ASRS/NorthRacks')
if event.source.selectedTab == 'South Racks Layout'\
	and event.source.visible:
	system.nav.closeWindow('Main Windows/ASRS/NorthRacks')
	window = system.nav.openWindow('Main Windows/ASRS/SouthRacks')
	system.nav.centerWindow(window)
else:
	system.nav.closeWindow('Main Windows/ASRS/SouthRacks')

Please feel free to suggest alternative options or best practice, but the main goal is to identify and close the stranded popup window.

I appreciate any assistance provided and thank you for this great resource.

Cheers,
Steve

Hi Steve,

Well, would it work to close all popup windows when the Main Window closes?

This could be done with the following script. You could put this script in the visionWindowClosed event of the Main Window or somewhere else.

for win in system.gui.getOpenedWindows():
	if not win.startMaximized:
		system.nav.closeWindow(win)
1 Like

Yes, closing all popups would work just fine. I appreciate the quick response and will test out the script.

Thanks!

I realized that you also need to check that the window is Floating for this to work. Here is the revised code:

for win in system.gui.getOpenedWindows():	
	if not win.startMaximized and win.dockPosition == 0:
		system.nav.closeWindow(win)
4 Likes

Hey Nick…

I ended up going on a slightly different route to solve my issue due to some lingering problems that surfaced later. This is the code I ended up using.

var = system.nav.getCurrentWindow() #assign the path of current max window
win = system.gui.getWindow(var) #convert path string to PyObject
par = system.gui.getParentWindow(event) #assign the event parent
tab = event.source.selectedTab #assign the selected tab name
allwin = system.gui.getOpenedWindows() #tuple all open windows

if win == par and event.source.visible: #if tab nav main window open & tab visible
	for pop in allwin:
		if pop.layer == 1:
			system.nav.closeWindow(pop) #close all open popups
		window = system.nav.openWindow(tab) #open popup of selected tab
		system.nav.centerWindow(window) #and center
else:
	for pop in allwin:
		if pop.layer == 1:
			system.nav.closeWindow(pop) #close all open popups when navigating away

This also generalized the code (from my original mess) to make it reusable.

Thank you for your input… you put me on the right flight path. :airplane:

Cheers,
Steve

I try to use this code with the visionWindowClosed event and I get an AttributeError: object has no attribute ‘getopenedwindows’

system.gui.getOpenedWindows() is case sensitive.

Yeah that fixed it, thanks!