Preventing a popup window to open twice with same parameter, title

I am using a template to call a popup window for device config.

The same popup is used for many devices of the same type.
when opening the device config popup, i change the title to allow the user to know wich device it is configuring. this works nice, using : system.nav.openWindowInstance(windowpath [, parameters])

the only thing i dislike is that if the window is already opened, the user can reopen the window for the same device multiple times.

Note that the same popup can be opened more than once simultaneously if different devices are opened.

i would like to prevent the user to open the same device popup window twice (same parameter, title), if window is already opened i would like to bring focus on it instead or reopening it.

system.gui.getOpenedWindows() and system.gui.getOpenedWindowNames() gives me name of the window, but every popup of the window is the same. i cannot distinguished wich devicee it is.

on the client system menu bar, the window menu displays the correct title. I would like to get the same list as the windows system menu displays to filter either open or bring to front the popup window.

how can i get this title or parameter tupple instead of the names?
or is there a way to do it efficiently other than what described?

thanks

Martin!

When opening the Popup, I think you probably want to use something like system.gui.getWindowNames() to check if the Window (Popup) you’re about to open is already open.

We do something similar.

This is a set of functions that we use to find a window and then look for a parameter named “Tag”. If that is found then the window isn’t opened again.

Originally we referenced this post: Nav Helper system.nav.openWindowInstace

window is the path to the popup
instanceId is the value of the tag that we are looking for. You can modify tag to be your unique parameter that is being passed.

# this finds a window based on the path passed and the Tag parameter
def findInstance(window,instanceId):
	import system
	for row in system.gui.getOpenedWindows():
		if row.getPath() == window and row.getRootContainer().Tag == instanceId:
			return row
	return None
	
#This will open an instance of the passed window
def openInstance(window,properties=None):
	import system
	windowInstance = findInstance(window,properties['Tag'])
	if windowInstance == None:
		windowInstance = system.nav.openWindowInstance(window,properties)
	#system.nav.centerWindow(windowInstance)
	windowInstance.toFront()
	windowInstance.setSelected(1)
	return windowInstance

#This will close an instance of the passed parameter
def closeInstance(window,instanceId):
	import system
	windowInstance = findInstance(window,properties['Tag'])
	if windowInstance != None:
		system.nav.closeWindow(windowInstance)
1 Like

Nest the property check inside the window match to avoid an error if some open windows may not have the root container property you are checking for.

# Find matching window instance.
def findInstance(window,instanceId):
	import system
	for row in system.gui.getOpenedWindows():
		if row.getPath() == window:
			if row.getRootContainer().Tag == instanceId:
				return row
	return None