← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #235440]: Region() example help

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
To tell Sikuli, to only search in a specific region, you have to qualify
the actions with the region using the dot-chaining or use with: to
restrict all actions in the given block.

#Test if the department sale button is there
if not exists("department.png"):
    popup("Oops...!!! Check that you are on the sales menu")
    exit(1)
else:
    hover("department.png")
    click()

#This is where I get stuck

reg = Region(131,154,512,415) #This is the region I would like Sikuli to scan
reg.highlight(5) #This confirms it is looking at the area

#And this where I don't know how to tell "while not exists" to only scan in the area above
while not reg.exists ("dept_list.png"):
    reg.click("scroll_btn.png")
    click(reg.getLastMatch()) # this will again click on "scroll_btn.png" - wanted?
# else: # for a while is only additional noise and 1 more indent
# only makes sense, when break is used in the loop, since this would skip the else
# so if the loop ends, you are here anyway

if reg.exists("dept_list.png"):
    reg.click("ok_btn.png")
    type("1000" + Key.ENTER)
else:
    print "not found: dept_list"
    # what should we do here?
wait("total_scrn.png") 

If this is too complicated and/or tedious there are 2 other options:

--- 1:
with reg:
# all following lines with one indent (like with while)
# instead of whole screen all actions will only be done in reg

---2:
setROI(reg)
this will "shrink" the screen's active search area to reg
advantage: no indent needed
disadvantage: you must reset it, if no longer needed - and in a longer code snippet it might not be obvious, that you are working on a restricted screen area
to reset it:
setROI(SCREEN)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.