← Back to team overview

sikuli-driver team mailing list archive

[Bug 1413399] Re: onAppear() performs function but gives error and halts script. does not happen in 1.0.1

 

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.


** Changed in: sikuli
       Status: New => Invalid

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1413399

Title:
  onAppear() performs function but gives error and halts script. does
  not happen in 1.0.1

Status in Sikuli:
  Invalid

Bug description:
  Version using 1.1.0
  Windows 7 64 bit
  use onAppear command

  I use onAppear quite often to read dialog boxes and perform commands.
  one example is:

  onAppear("1421877826215.png", paste('List Item'))

  in 1.0.1 it performs this fine and continues script.

  in 1.1.0 it performs this but then stops, supplies an error and the
  script halts.

  i am calling this function from another script so the error just says
  error in line XXX where im calling it so I end up having to go find
  the parent script and run it individually to get the actual error
  which asys:

  [error] script [ TestScratchpad2 ] stopped with error in line 1
  [error] java.lang.ClassCastException ( java.lang.ClassCastException: java.lang.Integer cannot be cast to org.sikuli.script.ObserverCallBack )

  you can use any parameter with onAppear and it will run with the
  parameter but always gives an error. the error changes depending on
  which parameter you call.

  if you call it like this:

  onAppear("1421877826215.png", popup('List Item')

  then you get this error:

  [error] script [ TestScratchpad2 ] stopped with error in line 1
  [error] java.lang.NullPointerException ( java.lang.NullPointerException )

  
  for now I am falling back to 1.0.1 since i use this in so many areas I can not change them all to wait() functions to work around it.

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1413399/+subscriptions


References