# Multiple popup check

**URL:** <https://forum.inductiveautomation.com/t/multiple-popup-check/5029>\
**Category:** Ignition\
**Created:** [August 17, 2012, 12:53pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029 "2012-08-17T12:53:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [August 17, 2012, 12:53pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/1 "2012-08-17T12:53:56Z")

</div>

i have a script:

`param = event.source.parent.MotorID
if event.source.parent.EnablePopups:
	system.nav.openWindowInstance('popup', {'MotorID' : param})
	system.nav.centerWindow('popup')`

to open a popup for some motor information.  
I like being able to have many open at a time but would like to restrict 1 per motor. It doesn’t make sense to have 3 popups open for motor X… I’m assuming I need to add something in the event script to do this but I’m not sure how to handle it.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [August 17, 2012, 3:13pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/2 "2012-08-17T15:13:32Z")

</div>

Yes, we don’t care how many times you open the same popup window. Your script needs to check all of the opened windows to see if there is one with the same name and same parameter like this:`param = event.source.parent.MotorID
if event.source.parent.EnablePopups:
   windows = system.gui.getOpenedWindows()
   found = 0
   for win in windows:
      if win.name == "popup" and win.rootContainer.MotorID == param:
         found = 1
         break
   if not found:
      system.nav.openWindowInstance('popup', {'MotorID' : param})
      system.nav.centerWindow('popup')
   else:
      system.gui.messageBox("Motor already opened")`

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [September 6, 2012, 11:23am UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/3 "2012-09-06T11:23:01Z")

</div>

got it, thanks.  
How can I center the window I am opening only?  
It looks like it just keeps centering the first instance and the other windows open in the top left corner…

`system.nav.openWindowInstance('popup', {'MotorID' : param})
      system.nav.centerWindow('popup')`

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 6, 2012, 1:57pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/4 "2012-09-06T13:57:19Z")

</div>

It seems a bit counter-intuitive to allow multiple popups but always force them into the middle of the screen where they’ll overlap - usually it’s better to open popups for a specific item next to the item on the screen.

Anyway, the reason you’re having a problem with centring is because `system.nav.centerWindow('popup')`tries to get a window reference by name and finds the first one that you opened, ignoring the latest one.

To solve this you must use the reference to the window you just opened as follows:`param = event.source.parent.MotorID
if event.source.parent.EnablePopups:
   windows = system.gui.getOpenedWindows()
   found = 0
   for win in windows:
      if win.name == "popup" and win.rootContainer.MotorID == param:
         found = 1
         break
   if not found:
      newPopup = system.nav.openWindowInstance('popup', {'MotorID' : param})
      system.nav.centerWindow(newPopup)
   else:
      system.gui.messageBox("Motor already opened")`To make sure the popup window appears in front of the main window, set it’s Layer property to a value greater than the main window’s value.

The problem you still have however is demonstrated as follows: clicking on Motor 1 opens its popup OK; clicking on Motor 2 opens its popup OK; but clicking back on Motor 1 just displays a warning and does not bring its popup back to the top. So far I’ve not managed to find a way to force a window to the top of the z-order. Anyone else have any ideas?

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [September 6, 2012, 2:51pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/5 "2012-09-06T14:51:10Z")

</div>

Yes, I did realize that was why it was happening… I just wonder what would be the best way to open multiple popups. I think a random window centering would work well. So every time you order a window, it randomly selects its position…

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [September 6, 2012, 10:33pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/6 "2012-09-06T22:33:08Z")

</div>

To bring a window that is already open to the front, get a hold of the window itself and call setSelected(1)

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [September 7, 2012, 7:51am UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/7 "2012-09-07T07:51:35Z")

</div>

Thanks Carl. The following code works well:`param = event.source.parent.MotorID
if event.source.parent.EnablePopups:
   windows = system.gui.getOpenedWindows()
   found = 0
   for win in windows:
      if win.name == "popup" and win.rootContainer.MotorID == param:
         found = 1
         win.setSelected(1)
         break
   if not found:
      newPopup = system.nav.openWindowInstance('popup', {'MotorID' : param})
      system.nav.centerWindow(newPopup)`

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 23, 2020, 12:02am UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/8 "2020-01-23T00:02:49Z")

</div>

I’m Working on the same but I supposed to have an error al little help with this.

"  
param1 = event.source.parent.Device

param2 = event.source.parent.getComponent(‘Group’).Auto

param3 = event.source.parent.getComponent(‘Group’).Close

param4 = event.source.parent.getComponent(‘Group’).Open

if event.source.parent.EnablePopups: windows = system.gui.getOpenedWindows()  
found = 0  
for win in windows:  
if win.name == “Popup\_SOV” and win.rootContainer.Device == param1: found = 1 win.setSelected(1)  
break  
if not found: newPopup = system.nav.openWindowInstance(‘Popup\_SOV’, {‘Device’ : param1, ‘Auto’ : param2, ‘Close’ : param3, ‘Open’ : param4}) system.nav.centerWindow(newPopup)  
"

---

<div class="post-metadata">

**Author:** ![AIO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aio/32/87549_2.png) [@AIO](https://forum.inductiveautomation.com/u/AIO)\
**Post date:** [January 23, 2020, 12:13am UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/9 "2020-01-23T00:13:10Z")

</div>

To put your code in a code block, use 3 backticks above and below it.

```auto
param1 = event.source.parent.Device

param2 = event.source.parent.getComponent(‘Group’).Auto

param3 = event.source.parent.getComponent(‘Group’).Close

param4 = event.source.parent.getComponent(‘Group’).Open

if event.source.parent.EnablePopups:
    windows = system.gui.getOpenedWindows()
    found = 0
    for win in windows:
        if win.name == “Popup_SOV” and win.rootContainer.Device == param1: 
            found = 1 
            win.setSelected(1)
            break
        if not found: 
            newPopup = system.nav.openWindowInstance(‘Popup_SOV’, {‘Device’ : param1, ‘Auto’ : param2, ‘Close’ : param3, ‘Open’ : param4})
            system.nav.centerWindow(newPopup)

```

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 23, 2020, 2:03pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/10 "2020-01-23T14:03:51Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f8af0c71efb2fa36d1220a11bd4c437f0f5572fe.png)

I try the code but still having some kind of error  
thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 23, 2020, 3:38pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/11 "2020-01-23T15:38:44Z")

</div>

You have a syntax error because you’ve cut and pasted code that had unicode curly quote marks. (where the error shows question marks). Replace those with proper single or double ASCII quote characters.

(Your initial code posted didn’t use a code formatting block, so the forum software made your quotes “pretty”. Which is why AIO’s attempt to format for you failed.)

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 23, 2020, 3:39pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/12 "2020-01-23T15:39:55Z")

</div>

Thank you Sr

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 23, 2020, 4:31pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/13 "2020-01-23T16:31:47Z")

</div>

ok well now I got another error at this line  
I’ll appreciate your help

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a97e924f98571f9f200891d260d1b616a8b04f27.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 23, 2020, 4:43pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/14 "2020-01-23T16:43:20Z")

</div>

You haven’t indented your code correctly.

```auto
for _ in some_collection:
    if some_condition:
        # do something

```

You can’t just throw left-aligned text into python/jython and expect it to work.

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 23, 2020, 5:24pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/15 "2020-01-23T17:24:41Z")

</div>

Thank you that works fine no errors on the code

```auto
param1 = event.source.parent.Device

param2 = event.source.parent.getComponent('Group').Auto

param3 = event.source.parent.getComponent('Group').Close

param4 = event.source.parent.getComponent('Group').Open

if event.source.parent.EnablePopups:
	windows = system.gui.getOpenedWindows()
	found = 0
	for win in windows:
		if win.name == "Popup_SOV" and win.rootContainer.Device == param1:
			found = 1
			win.setSelected(1)
			break 
		if not found: 
			newPopup = system.nav.openWindowInstance('Popup_SOV',{'Device':param1,'Auto':param2,'Close':param3,'Open':param4})
			system.nav.centerWindow(newPopup)

```

but on the running time  
I got new error to run the pop up

Error executing script for event: `actionPerformed`  
on component: `Button` .

Traceback (most recent call last):  
File “event:actionPerformed”, line 14, in   
AttributeError: ‘[com.inductiveautomation.factorypmi.application.com](http://com.inductiveautomation.factorypmi.application.com)’ object has no attribute ‘EnablePopups’

Ignition v8.0.7 (b2019122014)  
Java: Azul Systems, Inc. 11.0.5

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 23, 2020, 5:28pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/16 "2020-01-23T17:28:05Z")

</div>

That means that the container your Button resides in has no property named `EnablePopups`. I don’t know where you copied this script from, nor do I know the structure of the Window it’s being used in, so that’s all I can tell you from the stacktrace. Perhaps that is supposed to be a custom property on the container?

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 23, 2020, 6:03pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/17 "2020-01-23T18:03:52Z")

</div>

I took it from this post  
I had the same problem that the guy that start this post my code was done to open multiple pop ups but the problem was that if you click on the same object 3 times 3 times will bring a pop up no matter if it is already open.  
so my original code was this

```auto
param1 = event.source.parent.Device

param2 = event.source.parent.getComponent('Group').Auto

param3 = event.source.parent.getComponent('Group').Close

param4 = event.source.parent.getComponent('Group').Open

window = system.nav.openWindowInstance('Popup_SOV', {'Device' : param1, 'Auto' : param2, 'Close' : param3, 'Open' : param4})
system.nav.centerWindow(window) 

```

but then I saw the post and I figure the actual code will work now I don’t know what should be the function of “EnablePopups” I guess it’s the action of trying to open a new pop up

So I replace that for componentEnabled it works kind off one click in the first object bring the pop up  
a second click will show the pop up currently open to the front  
but if I click on the first object and the the second both pop ups will open  
the problem is if I click on the first one again it will open a repeated pop up

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 23, 2020, 6:29pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/18 "2020-01-23T18:29:06Z")

</div>

It looks like the EnablePopups property is only used in the script to determine if Popups are enabled. To place this property, select the parent container of your Button, then right-click the parent container and select “Custom Properties” under the “Customizers” expandable menu. create a new property named “EnablePopups”, and select a data type of boolean. Apply your changes, and make sure to set the property’s value to be True, otherwise your script will be bypassed.

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 24, 2020, 7:56pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/19 "2020-01-24T19:56:49Z")

</div>

https:/uploads/iatesting/original/2X/1/1e946e5d090a3d0d3ce47d348224f3616a87cc4e.mp4

I did the change and the same is happening I guess it have to be something with this section

```auto
for win in windows:
		if win.name == "Popup_SOV" and win.rootContainer.Device == param1:
			found = 1
			win.setSelected(1)
			break 

```

but I don’t know how to watch that sentence while is running

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 24, 2020, 8:51pm UTC](https://forum.inductiveautomation.com/t/multiple-popup-check/5029/20 "2020-01-24T20:51:57Z")

</div>

```auto
logger = system.util.getLogger('TROUBLESHOOTING')
if event.source.parent.EnablePopups:
	windows = system.gui.getOpenedWindows()
	found = 0
	for win in windows:
        logger.info('Window name: {0}\t| param1: {1}'.format(win.name, param1))
		if win.name == "Popup_SOV" and win.rootContainer.Device == param1:
			found = 1
			win.setSelected(1)
			break 
		if not found: 
            logger.info('Popup with name \'Popup_SOV\' not found; making a new instance now.')
			newPopup = system.nav.openWindowInstance('Popup_SOV',{'Device':param1,'Auto':param2,'Close':param3,'Open':param4})
			system.nav.centerWindow(newPopup)

```

[Next page](https://forum.inductiveautomation.com/t/multiple-popup-check/5029.md?page=2)
