Control pop-ups based on which window is currently open

I have one particular popup window that is bound with a boolean tag but I only want it to open when 2 of my 18 windows are the current window and the boolean tag is true. I'm not sure where to even start for this. I don't see any simple way to do this so I assume it will take some more involved level of scripting than I am comfortable/capable in doing. I'm sure there are probably others doing this same thing. Any help would be appreciated.

This seems like something you might be able to do on a client event Tag Change script using system.nav.getCurrentWindow and comparing it against a list of windows you are wanting it to open while open.

1 Like

Thanks for the input. I think you are correct but I am unsure of the scripting required to do this. Script programming is not my forte' and I am struggling to try and better understand it. I've spent 30 years programming Panelviews and never used much scripting. I was hoping for a little more guidance on the scripting required to do that.

Something along the lines of this should give you a start:

def valueChangeEvent(event, initialChange):
	""" """

	# Do nothing if the value goes low, or this is the initial startup of the script
	if event.currentValue == 0 or initialChange:
		return

	# Windows that we need to have open to let the popup be shown
	allowedWindowPaths = ["path/to/window/1", "path/to/window/2"]

	# Get a list of all the currently opened vision windows
	openedWindows = system.gui.getOpenedWindows()

	# Make a list of all the window paths for the opened windows
	openedWindowPaths = [window.path for window in openedWindows]

	# Path to the popup we want to open
	popupPath = "path/to/popup"

	# Check to see if any of our allowed windows are opened
	if any(1 for x in allowedWindowPaths if x in openedWindowPaths):
		# If popup already exists, don't open it
		if popupPath in openedWindowPaths:
			return

		# open the popup and center it
		newPopup = system.nav.openWindow(popupPath)
		system.nav.centerWindow(newPopup)

Toss this into a library script and then call it from the actual script for the Client Tag Change Event.

Note: if your navigation method is not using swap windows, my script will still show the popup if the required screens are open in the background.

If you haven't browsed them already the manual and inductive university are free resources that explain quite a bit.

2 Likes

In Client Tag Change Scripts, add your tag and give the script a name ('conditional-open'). So if the tag you've selected changes the script will execute. Then in the script check to see if the tag change is True and the current window is in a list window paths (best to use the 'Copy Path' on the window).


1 Like

@user100 , post a copy of the code as well, for easy copy and pasting.

I like your approach overall, Ryan, but did a little bit of golfing/polish:

def valueChangeEvent(event, initialChange):
	# Do nothing if the value goes low, or this is the initial startup of the script
	if not event.currentValue or initialChange:
		return

	# Path to the popup we want to open
	popupPath = "path/to/popup"

	# If any of these window paths are open, the popup is allowed
	allowedWindowPaths = ["path/to/window/1", "path/to/window/2"]

	# Explicitly prevent these windows from opening the popup
	preventedWindowPaths = [popupPath]

	# Get a list of all the currently opened vision windows
	openedWindows = system.gui.getOpenedWindows()

	# Check to see if any of our allowed windows are opened
	anyAllowedWindowOpen = any(window.path in allowedWindowPaths for window in openedWindows)
	noPreventedWindowsOpen = all(window.path not in preventedWindowPaths for window in openedWindows)

	if anyAllowedWindowOpen && noPreventedWindowsOpen:
		# open the popup and center it
		newPopup = system.nav.openWindow(popupPath)
		system.nav.centerWindow(newPopup)

Disclaimer: Untested :smile:

2 Likes

Thank you all! I will give this a try and let you know how I make out.

So I loaded and tested the script from ryan.white and it worked fine once I realized how to call the script in the Project Library. I thought I just needed the name that I saved it as which was L2AlloyReq but with some trial and error, and help from a Python programmer in our company, we found we needed to put it into the event script as follows??

L2AlloyReq.valueChangeEvent(event,initialChange)

The following explanation will probably show how "green" I am at scripting.

I wasn't totally clear what I was looking for. I wanted the pop-up to come up on the 2 screens anytime the tag event was true. For example, If the event triggers and I am not on one of these 2 windows, I didn't want the pop up to open until I open one of those windows but I now realize that as it is written, if the event is "fired" and I'm not already on one of the windows that the script allows the pop up to open, I'll never see it. I wasn't thinking of the event script being a once and done deal (I thought the script would be called continuously as long as the event was true). I need to come up with a way to trigger the script only when the boolean event happens and one of the two windows is opened. In other words, I need the script to run that "one time" only when the boolean event is true and I have one of the two windows open that I want the pop up to be visible on.

Any thoughts on doing that?

You could change up Ryan/Paul's logic a little bit:

If the required window is already open, open the pop-up as normal

If neither window is open, instead set a session prop, e.g. popUpPending.

Then, on either window's startup event, check if popUpPending is True and if so, open the pop-up.

You can adapt the above as needed to suit the complexity required.

Edit: don't forget to also reset popUpPending after opening the pop-up, or it'll keep on opening every time.

1 Like