# Dropdown list separator

**URL:** <https://forum.inductiveautomation.com/t/dropdown-list-separator/16851>\
**Category:** Ignition\
**Created:** [February 2, 2018, 3:28pm UTC](https://forum.inductiveautomation.com/t/dropdown-list-separator/16851 "2018-02-02T15:28:19Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![JNelson](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JNelson](https://forum.inductiveautomation.com/u/JNelson)\
**Post date:** [February 7, 2018, 12:05am UTC](https://forum.inductiveautomation.com/t/dropdown-list-separator/16851/21 "2018-02-07T00:05:43Z")

</div>

I was trying to do the same thing! I found this post and it works great (click on the link below):

> [@Jython: Setting up a Popup Menu dynamically](http://forum.inductiveautomation.com/t/jython-setting-up-a-popup-menu-dynamically/6318/5):
>
> Well, I know this doesn’t exactly help you now, but in 7.6 you’ll be able to do something like this: from functools import partial def f1(event): print 'f1(event=%s)' % str(event) def f2(event): print 'f2(event=%s)' % str(event) def f3(event, param): print 'f3(event=%s, param=%s)' % (str(event), str(param)) f3\_partial = partial(f3, param='some value') menu = system.gui.createPopupMenu({ 'item1' : f1, 'item2' : f2, 'item3' : f3\_partial}) menu.show(event) This is valid Jython…

---

<div class="post-metadata">

**Author:** ![JNelson](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JNelson](https://forum.inductiveautomation.com/u/JNelson)\
**Post date:** [February 7, 2018, 3:05pm UTC](https://forum.inductiveautomation.com/t/dropdown-list-separator/16851/22 "2018-02-07T15:05:18Z")

</div>

Here’s a practical example:

```auto
#Place this code in the 'mousePressed' event
from functools import partial
from javax.swing import JMenuItem

def myFunc(event, parm1, parm2):
	msg = 'Selected value: %s\nSelected label: %s' %(parm1, parm2)
	system.gui.messageBox(msg)

if event.getButton() == 1: #This prevents right-click from triggering script
	itemList = ['Item 1', 'Item 2', 'Item 3']
	
	f1 = partial(myFunc, parm1 = 1, parm2 = itemList[0])
	f2 = partial(myFunc, parm1 = 2, parm2 = itemList[1])
	f3 = partial(myFunc, parm1 = 3, parm2 = itemList[2])
	
	itemNames = [itemList[0], '', itemList[1], itemList[2]]
	itemFunct = [f1, None, f2, f3]
	
	menu = system.gui.createPopupMenu(itemNames, itemFunct)
	menu.show(event, 2, event.source.height - 2)

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 26, 2019, 11:55pm UTC](https://forum.inductiveautomation.com/t/dropdown-list-separator/16851/23 "2019-08-26T23:55:12Z")

</div>

Late to the party… but you can pass arguments using a lambda function, or if you need to pass something more complex, by defining a function that **creates** the function you want to call and passes in the arguments you want to use, and then returns the function itself. Better with an example…

```auto
def make_addToTrend(event, tag):
	def addToTrend(event=event, tag=tag):
		system.gui.messageBox("Adding tag '%s' to trend." % tag, "Trend")
	return addToTrend
items = ['Running', 'Faulted', 'Mode']
functions = [make_addToTrend(event, items[i]) for i in range(len(items))]

menu = system.gui.createPopupMenu(items, functions)
menu.show(event, 0,0)

```

Explanation:  
Normally, when you add functions into the ‘functions’ variable with arguments, you’re actually **executing** this function and passing in the return value, instead of passing in the reference to the function itself.  
Therefore, you must pass in a function that creates the function to add into the list, and which returns the function object itself.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 26, 2019, 11:57pm UTC](https://forum.inductiveautomation.com/t/dropdown-list-separator/16851/24 "2019-08-26T23:57:05Z")

</div>

You could use:

```auto
	def make_setHOA(event, value):
		def setHOA(event=event, value=value):
			system.tag.write("deviceHOA", value)
		return setHOA
	
	names = ["Auto", None, "Off", "Hand"]
	functions = [setHOA(1), None, setHOA(0), setHOA(2)]
	menu = system.gui.createPopupMenu(names, functions)
	menu.show(event, event.x, event.y)

```

[Previous page](https://forum.inductiveautomation.com/t/dropdown-list-separator/16851.md?page=1)
