Recursive Processing of a List

Asked by Joe Murphy

Let me preface by saying that if I were to call myself a programming neophyte, I'd be over stating my knowledge.

That said, I've read FAQ #1437 (thanks to RaiMan!) but I don't really feel I understand well enough to proceed. What I need to do is something like (the image will be a text box):

let i = (apple, orange, grape, banana)

click(img)
paste (i)
click(img)
paste (i)
click(img)
paste (i)
next i

Again... I know from the FAQ that this type of method doesn't exist in Python, but it was the easiest way I could think of to show what I was trying to do.

So, for something like this, would I use "myListFixed =" ? And if so, how do I identify the list, and how do I make it place the current value in the paste()?

Thanks in advance for your patience and help.

Joe

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Hi,

It is not very clear what are you trying to do so I would assume, according to my understanding, that you have multiple text boxes and you want to populate each one of them with the the items from you list in the following fashion:

1. Paste the first item in list into all text boxes
2. Paste the second item in list into all text boxes
3. ..
4. Stop when there are no more items in the list

So if that's true, you can do something like that:

lst = [apple, orange, grape, banana] #define a list

for item in lst:
    for textBox in findAll(<img>):
        type(item)

Take a look at that and see if that answers your question. Feel free to ask if I got you wrong or if something is unclear.

Regards,
Eugene

Revision history for this message
Joe Murphy (jmurphy-j) said :
#2

Eugene S, thanks so much for the reply!

You have correctly read through my muddy description and understood it correctly! :)

I want to try your code, as it seems that it's very close to what I need. The one thing that is different is that all the text boxes will be different. Here's the whole scenario:

I've got a piece of software that's used in the Postal Industry. I need to print out a large number of 3 different reports, but the way software works, I have to manually enter the query name into each of three different pop-up boxes that appear during the processing.

Manually, it would require me to initiate the report process and then, as the boxes pop up, enter the same data in each and click "OK". When that report finishes, I have to re-initiate the report process and enter the next query name in each box as it pops up and click "OK". And again, and again, and again... ad nausuem.

SO.... I figured I'd go through the process one time, taking images of each of the slightly different pop-ups. Then have Sikuli do the work of initiating the process, entering the data in the pop ups (and clicking "OK" to each), and then re-initiating for the next report. I know I can get the rest of it working easily with just the basic Sikuli IDE buttons, but am was lost when it came to creating a list of variables and having Sikuli work through them recursively.

I see how your example would work if I had a static set boxes all at once, but I've got to do one, then wait for the next and paste (or type) in that one and wait again.

Thoughts? And THANKS!

Joe

Revision history for this message
Eugene S (shragovich) said :
#3

Hi Joe,

Happy that helps.

So if your text boxes are different you can try that:
1. Create and save the images for all 3 text boxes (I will call them "textbox1.png", "textbox2.png" and "textbox3.png")
2. Create a new list consisting of these images:
    textBoxList = ["textbox1.png", "textbox2.png", "textbox3.png"]
3. Run the loop:

    textBoxList = ["textbox1.png", "textbox2.png", "textbox3.png"]
    lst = [apple, orange, grape, banana] #define a list

    for item in lst: # For each item in the lst
        for text in textBoxList: #Do that for each text box
            click(item) #assuming that you have to click on the actual text box before you start input
            type(text)

Make sure that Sikuli has access to the images you save. To do that you might want to take a look at "setBundlePath()". You can find more details about it here:

http://doc.sikuli.org/globals.html#setBundlePath

It lets you set the path for searching images in all Sikuli Script methods.

Cheers,
Eugene

Revision history for this message
Joe Murphy (jmurphy-j) said :
#4

Eugene,

I'm sorry I've taken so long. Work pulled me under water. :(

I hope to start testing this week, and will be back in touch.

Continued gratitude!

Joe

Revision history for this message
Joe Murphy (jmurphy-j) said :
#5

Well, I tried some different things with your help, but I've failed. :(

This is the closest I've managed to get (down below), but it almost immediately halts with the following error when I want it to type the first item in the list:

[error] script [ *Untitled ] stopped with error in line 6
[error] TypeError ( type(): 1st arg can't be coerced to String )

What I'm trying to do is have it loop through the lst, and use the same item in the lst for all the type(text) and then have it loop back through again.

Scratching my head and feeling dumb,

Joe

==========================================================

lst = ["Batch - Allegany Ballot Sytle 1", "Batch - Allegany Ballot Sytle 3", "Batch - Allegany Ballot Sytle 4", "Batch - Allegany Ballot Sytle 6"]
for item in lst:
        click("1400538997860.png")
        click("1400539015092.png")
        wait("1400539035645.png")
        type(text)
        click("1400539361509.png")
        wait("1400539035645.png")
        type(text)
        click("1400539361509.png")
        wait("1400539035645.png")
        type(text)
        click("1400539361509.png")
        wait("1400539035645.png")
        type(text)
        click("1400539361509.png")
        wait("1400539035645.png")
        type(text)
        click("1400539361509.png")
        wait("1400539035645.png")
        type(text)
        click("1400539361509.png")

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

Since you have said, that the next entry of the list should be in item (for item in list), you have to use it in the type: type(item)

Am 20.05.2014 um 01:41 schrieb Joe Murphy:

Question #248290 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/248290

   Status: Answered => Open

Joe Murphy is still having a problem:
Well, I tried some different things with your help, but I've failed. :(

This is the closest I've managed to get (down below), but it almost
immediately halts with the following error when I want it to type the
first item in the list:

[error] script [ *Untitled ] stopped with error in line 6
[error] TypeError ( type(): 1st arg can't be coerced to String )

What I'm trying to do is have it loop through the lst, and use the same
item in the lst for all the type(text) and then have it loop back
through again.

Scratching my head and feeling dumb,

Joe

==========================================================

lst = ["Batch - Allegany Ballot Sytle 1", "Batch - Allegany Ballot Sytle 3", "Batch - Allegany Ballot Sytle 4", "Batch - Allegany Ballot Sytle 6"]
for item in lst:
       click("1400538997860.png")
       click("1400539015092.png")
       wait("1400539035645.png")
       type(text)
       click("1400539361509.png")
       wait("1400539035645.png")
       type(text)
       click("1400539361509.png")
       wait("1400539035645.png")
       type(text)
       click("1400539361509.png")
       wait("1400539035645.png")
       type(text)
       click("1400539361509.png")
       wait("1400539035645.png")
       type(text)
       click("1400539361509.png")
       wait("1400539035645.png")
       type(text)
       click("1400539361509.png")

--
You received this question notification because you are an answer
contact for Sikuli.

Revision history for this message
Joe Murphy (jmurphy-j) said :
#7

Thanks RaiMan, that solved my question.

Revision history for this message
Joe Murphy (jmurphy-j) said :
#8

MANY thanks to both Eugene S and RaiMan! You have no idea how much easier your help has made my life. On this project alone, I'll probably save 20 hours of click and paste drudgery! THANK YOU, THANK YOU, THANK YOU!

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

Your feedback makes us happy and keeps us motivated.

Thanks.