Question #170439 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/170439
Status: Open => Answered
RaiMan proposed the following answer:
--1: observe handler:
the function gets the event object as parameter, so if a handler is
defined in a class, it has to be:
def releaseButton(self, e):
look: http://sikuli.org/docx/region.html#SikuliEvent for the features of
e
--2: observe(FOREVER, background=True)
The loop does not contain any time consuming actions, so it is done within a
short time of max a very few seconds.
The other loop contained the observe, that consumed about 0.5 seconds.
So put an equivalent wait() into the loop, to make it loop for the waiting time
of observe()
WindowUR_CT.onAppear(image , test.releaseButton)
WindowUR_CT.observe(FOREVER, background=True)
try:
for x in range(30):
test.movePoint(-1, 0)
if test.done == 1:
print 'done if'
break
wait(0.5)
if test.done == 1: # I guess is better
print 'in here'
mouseUp()
WindowUR_CT.stopObserver()
except:
WindowUR_CT.stopObserver()
mouseUp()
print 'except'
If you want to synchronize it with a waiting time for the observe(), use
something like this
runTime = 30
WindowUR_CT.observe(runTime, background=True)
start = time.time()
while time.time()-start < runTime:
instead of the for x in range():
BTW: switches like test.done should be boolean (True/False) so you can
write if test.done:
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.
_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help : https://help.launchpad.net/ListHelp