# popupMenu

**URL:** <https://forum.inductiveautomation.com/t/popupmenu/6080>\
**Category:** Ignition\
**Created:** [March 22, 2013, 4:59am UTC](https://forum.inductiveautomation.com/t/popupmenu/6080 "2013-03-22T04:59:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![WKetcham](https://avatars.discourse-cdn.com/v4/letter/w/c57346/32.png) [@WKetcham](https://forum.inductiveautomation.com/u/WKetcham)\
**Post date:** [March 22, 2013, 4:59am UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/1 "2013-03-22T04:59:50Z")

</div>

Ok, this one has got to be stupid but can anyone tell me why the code below is not working. I have reduced it to a simple test…it is not throwing any error, but it is also not displaying a popupMenu.

app.nav script

[code]def opAdminPopup():  
import system, app

```
def swapArea():
	system.nav.swapTo('App Selection')
	openwin = system.gui.getOpenedWindowNames()
	for win in openwin:
		if '/' in win:
			system.nav.closeWindow(win)

adminPopup = system.gui.createPopupMenu(["Swap Process Area"],[swapArea])
return adminPopup[/code]

```

mousePressed and mouseReleased on a button

`menu = app.nav.opAdminPopup()
menu.show()`

Thanks for the help. I have been staring at the code for hours and I am not seeing it. If it is something really stupid please go easy on me 🙂

---

<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:** [March 22, 2013, 9:58am UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/2 "2013-03-22T09:58:56Z")

</div>

Hi Wes,

I think you’re forgetting to pass in the event reference. Your script code should be:[code]def opAdminPopup():  
import system, app

def swapArea(event):  
system.nav.swapTo(‘App Selection’)  
openwin = system.gui.getOpenedWindowNames()  
for win in openwin:  
if ‘/’ in win:  
system.nav.closeWindow(win)

adminPopup = system.gui.createPopupMenu([“Swap Process Area”],[swapArea])  
return adminPopup[/code]and the code in mousePressed and mouseReleased should be `menu = app.nav.opAdminPopup()
menu.show(event)`

---

<div class="post-metadata">

**Author:** ![WKetcham](https://avatars.discourse-cdn.com/v4/letter/w/c57346/32.png) [@WKetcham](https://forum.inductiveautomation.com/u/WKetcham)\
**Post date:** [March 22, 2013, 3:34pm UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/3 "2013-03-22T15:34:25Z")

</div>

I had previously tried the script with the event passing as you showed Al and it didn’t work either. I just added the event pass back in and still nothing. It’s odd, I have added debug print statements and I know I am getting to the return statement in opAdminPopup but no popupMenu. ☹

---

<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:** [March 22, 2013, 4:16pm UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/4 "2013-03-22T16:16:32Z")

</div>

I tried creating a new window (containing just a label) and script module using your code and it works ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

The only change I made was to comment out the code inside swapArea and instead put a print statement. This prints correctly every time I right-click the label and choose the ‘Swap Process Area’ option.

Maybe try it in a new window in case something hanging around from before is causing the problem.

---

<div class="post-metadata">

**Author:** ![WKetcham](https://avatars.discourse-cdn.com/v4/letter/w/c57346/32.png) [@WKetcham](https://forum.inductiveautomation.com/u/WKetcham)\
**Post date:** [March 22, 2013, 5:07pm UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/5 "2013-03-22T17:07:38Z")

</div>

This is goofy and it still won’t work. I just recoded a test popup (code below) and still no popup menu. I am getting the “Returning from testpopUp” in output console so I know I am getting in but thats about it.

In case it matters my dev machine is:

Win7 64 Bit  
Ignition 7.5.5  
Java 7

Here is my app script

[code]def testPopup():  
import system, app  
def printLabel(event):  
print ‘here is my label’

```
popUp = system.gui.createPopupMenu(['print label'],[printLabel])
print "Returning from testpopUp"
return popUp[/code]

```

Here is my mouse pressed and mouse released

`menu = app.nav.testPopup()
menu.show(event)`

Thanks

---

<div class="post-metadata">

**Author:** ![hmatlock](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@hmatlock](https://forum.inductiveautomation.com/u/hmatlock)\
**Post date:** [March 22, 2013, 8:29pm UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/6 "2013-03-22T20:29:10Z")

</div>

I set up a test window with both sets of your code and both worked without issue using the RIGHT mouse click on a button and label component. I could see the message in the console on LEFT click, but no menu on either.

Try adding this to the mousePressed and mouseReleased events

```auto
menu = app.nav.testPopup()
menu.show(event, event.x, event.y)
```

---

<div class="post-metadata">

**Author:** ![WKetcham](https://avatars.discourse-cdn.com/v4/letter/w/c57346/32.png) [@WKetcham](https://forum.inductiveautomation.com/u/WKetcham)\
**Post date:** [March 26, 2013, 2:10am UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/7 "2013-03-26T02:10:20Z")

</div>

Thanks,

Adding the event.x, event.y solved the problem for a left click (or touch push). This particular app will primarily be run on touch screens so I wasn’t even thinking about the right mouse click. My original code works fine with a right mouse click incidentally. It make sense (from a windows pop-up perspective) that this popup menu would fire from a right click but I didn’t see anything regarding this in the documentation. Anyways it’s working now and I thank you both (Al and Matlock) for your help. Incidentally nice work on the first post Matlock 😃

---

<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:** [March 26, 2013, 8:54am UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/8 "2013-03-26T08:54:36Z")

</div>

Good catch hmatlock! Glad you got it working.

---

<div class="post-metadata">

**Author:** ![hmatlock](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@hmatlock](https://forum.inductiveautomation.com/u/hmatlock)\
**Post date:** [March 26, 2013, 2:28pm UTC](https://forum.inductiveautomation.com/t/popupmenu/6080/9 "2013-03-26T14:28:31Z")

</div>

Thanks! Glad you have it working now. I incidentally had the same issue a couple of weeks ago when I was also working on a touch centric app and needed a drop down menu from a button, which you can create using the same approach, just replace the x and y portion.

```auto
menu = app.nav.testPopup()
menu.show(event, 0, event.source.getHeight())
```

[JavaDocs](http://docs.oracle.com/javase/7/docs/api/javax/swing/JPopupMenu.html#show%28java.awt.Component,%20int,%20int%29)  
[http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html#popup](http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html#popup)
