sikuli doesn't recognize an image on list in a loop

Asked by aorior

Hi,
I've a problem, I use this code: (sorry it's so ugly but...)
list_menu=[]
list_menu_triangle=[[] for _ in range(25)]
list_menu_triangle_carre=[[[] for _ in range(25)] for _ in range (75)]
count_menu=0
for j in findAll(image1):
    click(j)
    for menu in region1.findAll(image.menu):
        a=0
        click(menu)
        wait(1)
        stop=0
        itt=0
        finish=0
        verify=0
        for itt in range(0,count_menu):
            if menu==list_menu[itt]:
                verify=1
        if verify==1:
            list_triangle=[]
            count_triangle=0
            for triangle in region1.findAll(image.triangle):
                list_triangle.append(triangle)
                count_triangle=count_triangle+1
            for a in range(0,count_triangle):
                for itt in range(0,count_triangle):
                    if list_triangle[a]==list_menu_triangle[count_menu][itt]:
                        verify=2
                if verify==2:
                    click(list_triangle[a])
                    list_carre=[]
                    count_carre=0
                    for carre in region.findAll(image.carre):
                        list_triangle_carre[a].append(carre)
                        count_carre=count_carre+1
                    b=0
                    for b in range (0,count_carre):
                        for itt in range(0,count_carre):
                            if list_triangle_carre[a][b]==list_menu_triangle_carre[count_menu][a][itt]:
                                verify=3
                        if verify==3:
                            continue
                        else:
                            click(list_carre[b])
                            list_menu_triangle_carre.append[count_menu][a][b]
                            list_count_carre[count_menu][a]=list_count_carre[count_menu][a]+1
                            finish=1
                            b=b+1
                            break

                else:
                    click(list_triangle[a])
                    list_menu_triangle[count_menu].append(list_triangle[a])
                    carre=region1.find(image.carre)
                    click(carre)
                    list_menu_triangle_carre[count_menu][a].append(carre)
                    finish=1
                    a=a+1
        else:
            click(menu)
            list_menu.append(menu)
            count_menu=count_menu+1
            triangle=region1.find(image.triangle)
            click(triangle)
            wait(0.1)
            list_menu_triangle[count_menu].append(triangle)
            carre=region1.find(image.carre)
            click(carre)
            list_menu_triangle_carre[count_menu][a].append(carre)
            finish=1
        if finish==1:
            break
    click(ok)

In fact in the first turn of loop all it's right, but after, it's always the same buttom which is clicked.
It seems that the image which is on the list doesn't recognize the next step.
Sorry for my English.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
aorior (quentin26om) said :
#1

More informations:
the interface it's a menu.
When you click on one of this, an scrolling menu appear, and another click show squares.
Think's for listening.

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

you should add some print statements, to see what is happening.

I am sorry: though I am rather good in reading code, but this is too complex.

If you do not get on the road, feel free to send a zipped .sikuli silently to my mail at https://launchpad.net/~raimund-hocke (top left corner)

Revision history for this message
aorior (quentin26om) said :
#3

I will try to resolve my problem asking my colleague (I'm in internship, but they never programmed with Sikuli)
If I success I wrote the answer.
Else I will ask again but with an code more readable.
Thank's for answer me.

Revision history for this message
aorior (quentin26om) said :
#4

In fact, the code is not so complex.
The first time, list_menu is empty, so verify=0
So the programm goes to the last else.
Here I click on this menu, an scrolling menu appears, I add the current menu in list_menu (not the scrolling menu but the first...), I click on the first triangle i find, doesn't matter because it's first time I click on this menu. This menu permits to scroll squares).
I click on one of this squares. I click on ok to close the menu window.
Here I click on an other buttom which open the same window with the same menus, all of this menus have the same scrolling menus, which have the same squares. I can't click on the same square that the first time.
So for this, I can click on the same menu, because it has several scrolling menus. I can click on the same scrolling menu too, because it has several squares.
Here I look if I ever click on the square, if Yes I don't click because I've not the right to do this. so I look another square.
If all squares on the current scrolling menu have always been clicking, I click on another scrolling menu.
If all squares of all scrolling menus have always been clicking too, I click on another menu.
The problem seems to come of recognition of images. Because the progamm always go the last else.
I can't put images of the windows because of the confidentiality of the program i automatize

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

Not complex for you might be, but for someone else looking at 3 nested loops, that do not have the ending condition in the head and having to live with a poor naming and no comments it is indeed complex.

But anyway:
when you leave the second loop the first time this will be newly evaluated in the second turn:
region1.findAll(image.menu)

which will give you a completely new set of match objects.
Since you are saving objects in your containers, using:
if menu==list_menu[itt]:

will always end up in false, since the objects are not the same objects.

You need some equality evaluation like that:
def matchEquals(m1, m2):
  return m1.x == m2.x and m1.y == m2.y

if matchEquals(menu, list_menu[itt]):

BTW: this has surely nothing to do with Sikuli, but is a basic Python knowledge ;-)

Revision history for this message
aorior (quentin26om) said :
#6

Sorry if you think I'm arrogant or whatever, it's not that I wanted and I understand that the code seem complex, that I wanted to say it's that I didn't use complex functions of python, or class, or other things that I find complex and only loop and list. It's maybe because of my poor vocubalary and my poor english level, that I don't use the good word or sentence, but I didn't want to be arrogant.
Actually I'm french, and I comment my code but in french (I think you're not so you should not understand)... and my english level is not enough good to comment with technical words...
I forget a lot of things in my script (break,...) but doesn't matter.
I will test with a function to compare. I come back to say if that works.
In the function you look the position, is it?
Thank's again!

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

I have not felt you being arrogant, but at least a little bit naive, in thinking, that it is easy, to understand your script, by simply looking at your code, but comment #4 at least helped a bit.

It is good habit, to first talk about, what you want to achieve and then add some snippets, that might be suspect.

*** In the function you look the position, is it?
yes. this is sufficient in your case, since all the compared matches are based on the same image.
In general you would have to compare width, height and score too, to be sure it is the same match supposing both matches result from the same screen content (what a match does not know).

come back if more help is needed.

BTW: If you feel better talking in French, no problem. I already answered questions in foreign languages (spanish, chinese, …) using GoogleTranslate ;-)
And believe me based on my experience: any additional comment on what you want to achieve, already have tried or experienced helps a lot - no matter what "quality" of english language.

Can you help with this problem?

Provide an answer of your own, or ask aorior for more information if necessary.

To post a message you must log in.