sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #12792
Re: [Question #206657]: Wait for image A or B or C forever, then take action accordingly
Question #206657 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/206657
Status: Open => Answered
RaiMan proposed the following answer:
looking at your workflow logic, I understand the following
-1 the script starts and sets up some regions and observer events
-2 a loop is entered, that starts observers A..D
-3 you wait until one of these events is fired
-4 you stop the observers
-5 you evaluate, which of the events A..D was fired (exclusive or, first one wins)
-6 if it is A or B or D, some actions are taken and the loop is ended (comment: again: the exit after the break is useless, because never executed, if you want to terminate your script here, just use exit (written exit() !!) instead of break.
-7 in case of C, you take some actions and start observing E...G (same approach as with steps 2...5 for A...D)
-8 if one of these events fires, you evaluate which one
-9 if it is E or F, it seems, you want to start all over again (import pointblank)
-10 if it is G, you do something and then break the inner loop (the exit does not matter), which finally brings your workflow back to step -2.
The critical part now is step 9.
If I am right, that you want to start your script all over, then it is the same as going back to step -2 (before starting the loop are only one-time-executed statements, which will have the same values, wether you loop again from step -2. or start the script again.
So just replace the import with a break and you have what you want.
your script with modifications:
type("d",KEY_WIN)
doubleClick(Pattern("1346049773218.png").similar(0.85))
RegA = Region(SCREEN)
RegB = Region(SCREEN)
RegC = Region(SCREEN)
RegD = Region(SCREEN)
RegE = Region(SCREEN)
RegF = Region(SCREEN)
RegG = Region(SCREEN)
def handler(e):
global isImgA_or_ImgB_or_ImgC_or_ImgD
isImgA_or_ImgB_or_ImgC_or_ImgD = True
RegA.onAppear(Pattern("XPBLauncherF.png").similar(0.81), handler)
RegB.onAppear(Pattern("ICIMuhunmaaf.png").similar(0.91), handler)
RegC.onAppear(Pattern("1346051181203.png").similar(0.89), handler)
RegD.onAppear(Pattern("1346049877203.png").similar(0.92), handler)
def handler2(e):
global isImgE_or_ImgF_or_ImgG
isImgE_or_ImgF_or_ImgG = True
RegE.onAppear("XPBLauncherG.png", handler2)
RegF.onAppear(Pattern("QondErrorRep.png").similar(0.88), handler2)
RegG.onAppear(Pattern("1346088182875.png").similar(0.79), handler2)
while True:
RegA.observe(FOREVER,background=True)
RegB.observe(FOREVER,background=True)
RegC.observe(FOREVER,background=True)
RegD.observe(FOREVER,background=True)
isImgA_or_ImgB_or_ImgC_or_ImgD = False
while not isImgA_or_ImgB_or_ImgC_or_ImgD:
wait(1)
RegA.stopObserver()
RegB.stopObserver()
RegC.stopObserver()
RegD.stopObserver()
if RegA.exists(Pattern("XPBLauncherF.png").similar(0.81),0):
click(Pattern("OK.png").similar(0.86))
break
elif RegB.exists(Pattern("ICIMuhunmaaf.png").similar(0.91),0):
click(Pattern("OK.png").similar(0.86))
break
elif RegC.exists(Pattern("1346051181203.png").similar(0.89),0):
doubleClick(Pattern("1346051181203.png").similar(0.89))
while True:
RegE.observe(FOREVER,background=True)
RegF.observe(FOREVER,background=True)
RegG.observe(FOREVER,background=True)
isImgE_or_ImgF_or_ImgG = False
while not isImgE_or_ImgF_or_ImgG:
wait(1)
RegE.stopObserver()
RegF.stopObserver()
RegG.stopObserver()
if RegE.exists("XPBLauncherG.png"):
click(Pattern("OK.png").similar(0.86))
break
elif RegF.exists(Pattern("QondErrorRep.png").similar(0.88),0):
click(Pattern("1345976311187.png").similar(0.92))
break
elif RegG.exists(Pattern("1346088182875.png").similar(0.79)):
click(Pattern("Y.png").similar(0.83))
click(Pattern("1346050299265.png").similar(0.83))
break
elif RegD.exists(Pattern("1346049877203.png").similar(0.92),0):
click(Pattern("Y.png").similar(0.83))
click(Pattern("1346050299265.png").similar(0.83))
break
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.