sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #05809
Re: [Question #172860]: While loop
Question #172860 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/172860
RaiMan proposed the following answer:
@ Harry
Yes and yes and one more yes:
When setting up a workflow in Sikuli, restricting the region is the best
you can do to speed things up and get more reliability and robustness.
But in many cases, the content of the restricted region (as the system
tray in this example) is changing over the time. So taking a screen shot
of the region and find it, does not help.
The other thing, most people try on the first run, to define a fixed
with absolute coordinates (which might help e.g. with content, that is
always at the same place: most games, full screen apps, ...).
@ Dylan
This could be an alternative in your situation:
sdim = getBounds() # the screen dimensions
# to be adjusted to your needs
trayW = 300
trayH = 30
# the tray region
tray = Region(sdim.x-trayW, sdim.y-trayH, trayW, trayH)
put this at the beginning of your script and use it later to restrict
the find as suggested by Harry.
--- your workflow
your script will contain a loop, that runs forever without having a stop condition. So be aware, that you have to kill it, if you want it to stop (abort key alt-shift-c).
I would do it less complex: what you are interested in, is that you are offline and that you are back online again.
So you just have to observer the existence of the symbol being online.
Another challenge I think you have: the 3 pictures are to similar, so
you have to raise the needed similarity to try to differentiate the
images. Concentrating on one image (the being online symbol would even
help to make it robust).
So the script could be:
sdim = getBounds() # the screen dimensions
# to be adjusted to your needs
trayW = 300
trayH = 30
# the tray region
tray = Region(sdim.x-trayW, sdim.y-trayH, trayW, trayH)
while True: # we run it forever
while tray.exists(Pattern("wlan-online.png"), similar(0.9))
wait(1) # looking every second is enough
# now we are offline
popup("Now offline, waiting for reconnect")
while not tray.exists(Pattern("wlan-online.png"), similar(0.9))
wait(1) # looking every second is enough
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.