is it possible to create a combo box from input in sikuli

Asked by Shawn Robertson

Currently I use the input method for user accepted data input like this:

Settings.tsVersion = input("Enter your version ie.. 2013, 2014 etc:", "2015")
if Settings.tsVersion == "2015":
    defbuild = 'Build 23.0.0.'
elif Settings.tsVersion == "2014":
    defbuild = 'Build 22.0.0.'
elif Settings.tsVersion == "2013":
    defbuild = 'Build 21.0.0.'
elif Settings.tsVersion == "2012":
    defbuild = 'Build 20.0.0.'
elif Settings.tsVersion == "2011":
    defbuild = '19.0.0.'

I would love to change this to a combo box where the user can choose those items from a drop down list instead of having to manually type in the data possibly getting it wrong due to typo's or just incorrect entries.

I looked in the:

http://docs.python.org/2/library/functions.html

and read the input() function area but i'm not finding what i want.

Is it possible to do this in sikuli?

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Shawn Robertson
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Python is not relevant for GUI related stuff, since we are in the Jython/Java environment.
Since Jython does not have any GUI support, we have to step down to the Java level.
In fact input() is internally realized with the respective Java features.

this is a nice blog entry for that:
http://alvinalexander.com/java/joptionpane-showinputdialog-examples

the relevant part for Jython is

String favoritePizza = (String) JOptionPane.showInputDialog(frame,
        "What is your favorite pizza?",
        "Favorite Pizza",
        JOptionPane.QUESTION_MESSAGE,
        null,
        pizzas,
        pizzas[0]);

to Jythonize this:

import javax.swing.JOptionPane as JOP

pizzas = [ "Cheese", "Pepperoni", "Sausage", "Veggie" ]
val = JOP.showInputDialog(null,
        "What is your favorite pizza?",
        "Favorite Pizza",
        JOptionPane.QUESTION_MESSAGE,
        null,
        pizzas,
        pizzas[0])

hope it helps ;-)

Revision history for this message
RaiMan (raimund-hocke) said :
#2

sorry, again:

val = JOP.showInputDialog(null,
        "What is your favorite pizza?",
        "Favorite Pizza",
        JOP.QUESTION_MESSAGE,
        null,
        pizzas,
        pizzas[0])

Revision history for this message
Shawn Robertson (shawn-robertson) said :
#3

Thanks Raiman.

i wanted to test the above values to see what happens so i pasted this into a test script

import javax.swing.JOptionPane as JOP

pizzas = [ "Cheese", "Pepperoni", "Sausage", "Veggie" ]

val = JOP.showInputDialog(null,
        "What is your favorite pizza?",
        "Favorite Pizza",
        JOP.QUESTION_MESSAGE,
        null,
        pizzas,
        pizzas[0])

i hit play and this error appeared:

[error] Error message: Traceback (most recent call last):
 File "C:\Users\SROBER~1\AppData\Local\Temp\sikuli-tmp3292072478656519817.py", line 5, in
 val = JOP.showInputDialog(null,
NameError: name 'null' is not defined

What is supposed to be happening?

Revision history for this message
RaiMan (raimund-hocke) said :
#4

replace null with None, since null is None on the Java level.

sorry, was late in the night ;-)

Revision history for this message
Shawn Robertson (shawn-robertson) said :
#5

Thanks so much Raiman, was able to use your information to create exactly what we wanted. we were even able to create a loop so that before the combo box appears, logic has already been performed ot seek out and find the latest folder version number which was awesome.

Revision history for this message
Harry (iam-harishetty) said :
#6

Hi RaiMan

I am new to sikuli.
Can u plz tell me how to ask user to enter the data manually during runtime (iwhen the script is running) i.e Data should be dynamic and not static.
i am using IDE 1.0.1 jdk 7

Revision history for this message
RaiMan (raimund-hocke) said :
#7

if you are new, you should at least read across the docs, to get a feeling about the possibilities:
http://doc.sikuli.org

What you are looking for:
http://doc.sikuli.org/globals.html#interacting-with-the-user

Revision history for this message
RaiMan (raimund-hocke) said :
#8

@Harry
It is wiser, to post your own questions, since then the whole community could answer ;-)