Drop down menu with Python

Hello,

I am programming a test step that is supposed to set an output of an instrument either “ON” or “OFF”. I have a property called “status” , which is the deisred status that is sent to the instrument. In the test step settings in editorx I want the user to be able to select either “ON” or “OFF” from a drop down menu as the value for status but I cannot figure out how to do it. Does someone know how to do it in Python?

image

Best regards
Thomas

hi @schoepfel,

You can use the AvailableValues attribute as described in the example: https://github.com/opentap/OpenTap.Python/blob/a23a508271a4090c8d8248ed4d1de28e3396c375/OpenTap.Python.Examples/BasicFunctionality.py#L52C14-L52C14

In your case it should be String instead of Int32, but otherwise the concept is the same. You’d probably want to hide the source property but that can also be done.

You can for example make a read-only property for that as it is done with “FrequencyIsDefault” https://github.com/opentap/OpenTap.Python/blob/a23a508271a4090c8d8248ed4d1de28e3396c375/OpenTap.Python.Examples/BasicFunctionality.py#L48C13-L48C13

In your case it should return a List[String] instead of a boolean.

Hello Rolf,

thanks for your hints, Unfortunately, I couldn’t get my code to work yet. In editorx there is a dropdown menu now , but the drop down menu has no options to select from. Can you spot my mistake? My code looks like this:

image

Ok, maybe it is not able to implicitly convert a python list to a List<string>. Maybe you could try this:

def Available(self):
     lst = List[String]()
     lst.Add("ON")
     lst.Add("OFF")
     return lst

That works, thank you!

1 Like