Dialog to ask the user for a item from list // rv.runtime.eval

Dear Forum/Support,

i need the user to select a item from a dropdown / list.
i found an old post where something similar has been achieved,
a dialog with string input for user, as seen here:

i edited the given snippet, but struggle to get it displaying a dropdown menu.

here is my code:

def getUserInputList(itemlist):
title = “Select project”
label = “Projects”
# e.g. itemlist
itemlist= [“no1”, “no2”]
dialogCode = “”"
use qt;
(string,bool) ans = qt.QInputDialog.getItem(commands.mainWindowWidget(), “%s”, “%s”, “%s”, 0, False);
ans._0 + “|” + string(ans._1);
stringInput = “%s” % runtime.eval(dialogCode % (title, label, itemlist), [“qt”, “commands”])
stringInput = stringInput.replace(’’’"’’’, “”)
print stringInput
InputList = stringInput.split("|")
print InputList
if InputList[1] == “true”:
return InputList[0]
return None

on execution i get a syntax error; on line

stringInput = “%s” % runtime.eval(dialogCode % (title, label, itemlist), [“qt”, “commands”])

can please someone point me the error in the code?

my resources are:

thanks upfront!

Hey Marc,

This one’s a weird one. I’ve killed some time trying to figure out the Mu syntax and I can’t seem to get it… Technically, what you have should work if you cast your items as a string [], like so:

dialogCode = “”"
use qt;
string items = {“foo”, “bar”};
(string,bool) ans = qt.QInputDialog.getItem(commands.mainWindowWidget(), “%s”, “%s”, items, 0, False);

However, and this is a big however, I can’t seem to find whether qt.QInputDialog has getItem bound in Mu. I see the getText and setComboItems but not the method itself.

Personally I would avoid doing this in Mu in the first place and use PySide/PySide2 (depending which RV version you’re on) instead. You’d have less headaches with Mu syntax and also would benefit from all the PySide-ness.

We ship a PySide example under RV_INSTALL_PATH/Python/pyside_example.py if you’d like to take a look.

Hope this helps!