RaiMan / SikuliX-2014

SikuliX version 1.1.2 (until February 2018)
http://sikulix.com
806 stars 235 forks source link

FindFailedHandlers not available with Java? --- revised 1.1.1 2016-11-03 #233

Closed cschlisner closed 7 years ago

cschlisner commented 7 years ago

I have been trying to register a default findfailedhandler in Java, as it says it is possible (or at least used to be possible) on the wiki here, but I've found that that code doesn't work at all. In fact, the only way to use the setFindFailedHandler() functions in either the Region class or the FindFailed class is if you do it with python or ruby.

Here's the code that would create a handler in FindFailed.java

Is there a reason for this restriction? I feel like the callback method would work fine with java.

RaiMan commented 7 years ago

in the docs (what you name wiki above) there is a note on java usage, which should work. A given observer callback is only reassigned in case the call is coming from Jython or Ruby. But anyways: the code snippet you mention above is not relevant, since the feature is implemented in class Region.

cschlisner commented 7 years ago

@RaiMan The example code does not work, because when you initialize a ObserverCallback Object with the default constructor, the obsType property is left as Type.GENERIC (seen here), so when the Region class tries to call the Handler and checks for a obsType property of type Type.FINDFAILED (seen here), the given Observer won't match and then the handler will never be called.

cschlisner commented 7 years ago

@RaiMan I have managed to get a findFailed handler working through Java with this code:

someRegion.setFindFailedHandler(new ObserverCallBack(new Object(), ObserveEvent.Type.FINDFAILED) {
    @Override
     public void findfailed(ObserveEvent e) {
         // handling code
     }
});

The non-working example code on the website should be replaced with this or something else that actually works.

Best wishes

RaiMan commented 7 years ago

@cschlisner thanks for not giving up and finding a solution (which needs ugly redundancies), that finally convinced me of having to do some revision of code and docs ;-) Now it is possible to simply use new ObserveCallBack() and override the respective method, as mentioned in the docs.

On top I now mention in the docs the possibility to define global handlers for all newly created regions .