how to use while len(string) > 1 : ??

Asked by VincentDugue

Hi everybody !
I need help for my script...
#1st line
def my_find(str):
    while len(str) > 1 :
        str2 = (str[len(str)-1:]
        return my_find(str2).nearby(30)
    RegionSearch = find(str+".png")
    return RegionSearch
#End my_find
#indent correct
doubleClick(my_find("AFR1234")

I'm working on an airport software and i want to create a "SearchingTool" :
Write the name of the airplane, doubleClick on the Airplane in the software...
My function is working but it doesn't click on the good airplane
I think THE while isn't working. I need help please :)

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
Eugene S (shragovich) said :
#1

When you say "it doesn't click", are you certain that what you are looking for was actually found? let's start from here

Revision history for this message
VincentDugue (poussinjetaimetroo) said :
#2

I think it's because of my <RegionSearch = find(str+"png")>
the script is actually working i change somethings, including index[]
so the program is looking for the good Letters (A, then B, then C...etc)
but my RegionSearch only take the last letter/number(for example 4) and then it clicked on a random 4 on the screen...
how to concatenate "A.png" + "B.png" ... + "4.png" ??

And yes all my screenshot letter/number are like : Pattern("A.png").exact #.similar(1)

Revision history for this message
Karl (k-d) said :
#3

It looks like you're trying to recursively create regions and then pass them to doubleClick. That won't work because doubleClick only works on one PSMRL at a time.
http://sikulix-2014.readthedocs.org/en/latest/region.html?highlight=doubleclick#Region.doubleClick

The recursion seems interesting enough. You can put the doubleClick in your definition.

def my_doubleClick(str):
    if len(str) == 1 :
        doubleClick(str+".png")
    else:
        str2 = str[:-1]
        return my_find(str2
my_doubleClick("AFR1234")

#You can simply use:
str = "AFR1234"
for letter in str:
    #type(str)
    doubleClick(letter+".png")

Revision history for this message
VincentDugue (poussinjetaimetroo) said :
#4

thank for you reply Karl,
I tried it and it works a little :P
My last script for this function was :
#first line
def my_find(region, str):
    if (len(str)>1):
        regioni = my_find(region, str[0])
        while regioni.hasNext():
            referenceRegion = regioni.next()
            try:
                return my_find(referenceRegion.nearby(50),str[1:])
            except:
                pass
    else:
            picti = str[0]+".png"
            try:
                regionfound = region.findAll(Pattern(picti).exact)
                return regionfound
            except:
                pass
#last line

It work a lil too but i think i have too mix both script to finally get my function
if you have any idea to do it, please say it to me
Thanks a lot for everything

Revision history for this message
Karl (k-d) said :
#5

The default region is your screen. If you search nearby 50 of this region, you'll just get your screen again.

Make sure you're getting all your regions from my_find.
When you call my_find put the returned regions in a variable, and loop over them to do your double clicking.
It sounds like you would need to do your double clicking in the function definition to have the name variables to write..

Lastly, it looks like you're only searching for a subset of the images when you use recursive input. If you do recursively find all possible images with nearby when two images are next to each other it would trigger an infinite loop.

Can you help with this problem?

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

To post a message you must log in.