sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #30343
Re: [Question #261418]: onAppear() performs function but gives error and halts script. does not happen in 1.0.1
Question #261418 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/261418
Status: Open => Answered
RaiMan proposed the following answer:
You just ran into a trap with version 1.0.1:
Despite the fact, that nominally a function object (simply the name of the function, that should be called back in case of event happened and which is clearly stated in the docs), your usage worked (meaning: did not produce an error) due to a sloppy implementation.
But though it "works" in 1.0.1, it does not do anything, that makes sense (or might look ok accidentally):
at the time, the script executes the line with the onAppear, the given function (paste or popup in your case) is executed.
A following observe() simply does nothing (due to a bug: if you want an infinite observe you have to specify a very long timeout).
But if you use an observe(someTime), you will get an exception in 1.0.1 as well.
The correct usage for that what you want according to the Python
language specs, is to use an anonymous function, which is a so called
lambda expression in Python (for 1.0.1):
onAppear(img, lambda e:popup("image appeared"))
observe(60*60*24) # waits one day ;-)
and with 1.1.0:
onAppear(img, lambda e: popup("image appeared"))
observe() # waits forever
with the next build of 1.1.0 even this works:
onAppear(img, lambda: popup("image appeared"))
observe() # waits forever
So since you have to adjust your code anyways, I suggest to go back to
1.1.0 again, since the observe feature in 1.1.0 is dramatically enhanced
and observe() does what it should.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.