Sikuli Dropdown Menu
Interact with Users Using Sikuli DropDown Menu
One of the best UI to use when input is needed is the dropdown menu. I have some great news for you. You can create dropdown menus in Sikuli. Dropdown menus allow you to create a list where the user can make a choice to select from a dropdown. Use cases for this can be creating lists for months, years, files, and names. When writing Sikuli code, it good practice to make it as easy for the user as possible. We also do not want the code to be changed. Creating a UI allows a process to be dynamic in a way that allows for different inputs.
Here is how you do it:
First, you want to create a list of all the options that can be selected. Our example will be choosing between the top tech companies.
list = (“Google”,”Microsoft”,”Apple”)
The list above contains three choices. We can also add a default option for nothing selected.
list = (“Nothing selected”,”Google”,”Microsoft”,”Apple”)
Now once the user selects something from the menu, we want an action to happen. If we want something different for each selection, then If statements will come into play.
If the user selects nothing, we can make the script end:
list = (“Nothing selected”,”Google”,”Microsoft”,”Apple”)
choice = select(“Which company would you like to work for?”, options = list)
if choice == list[0]:
popup(“You selected none of the companies”)
exit(1)
This will stop the script as the user selected no option.
If we want to give more information when they select a company, we can use the same code but offer a different result.
list = (“Nothing selected”,”Google”,”Microsoft”,”Apple”)
choice = select(“Which company would you like to work for?”, options = list)
if choice == list[1]:
popup(“You have selected Google.”)
popup(“Google is taking over the world! Please upload your resume.”)
popFile()
Remember that in python, lists always start with 0, so if we want to create an action for when “Google” is selected, it would be number 1 in the list. popup() lets us bring up a popup to a user with information or a message. Think of it as a message box that they will read. popFile() allows a user to select a file from their local computer or shared drive for reference. In the example above, we are using popFile() to get a user to upload their resume. The result will be an absolute path to the file, so make sure to save the result in a variable that can be used later on or saved as a log.
Responses