Unable to use Finder with Jython where Screen works OK

Asked by forrest

I have a Jython2.7 Project setup in Eclipse
 eclipse.PYTHONPATH in IDE set to:
  ( "C:\sikulix\sikulixapi.jar",
    "C:\Users\m\AppData\Roaming\Sikulix\Lib

Using sikulix 1.1.2-20180113.160948-72

Here is my code:

 # Run and Debug as JYTHON
 # Note: for any jython sikuli, use sikulixapi.jar NOT sikulix.jar
 import org.sikuli.script.SikulixForJython
 from org.sikuli.script import Region, Finder

 if __name__ == "__main__":
  # imageview = Region(Screen(0).getBounds())
  imageview = Finder("emsample/emsample_screenshot.png")
  topLeft = imageview.find("emsample/rtviewLeftMenu.png")
  topRight = imageview.find("emsample/rtviewRightMenu.png")
  pass

I get things to work fine when using "Region(Screen(0).getBounds())" but
when I try to use Finder, then both topLeft, and topRight always end up with
unicode str that is like "C:\...\emsample\rtviewLeftMenu" path.
I have also tried findAll() as well as find().

Any ideas what the issue may be?
Many thanks,
forrest

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

please read the docs about class Finder.

Finder.find() does not directly return a match, but an Iterator<Match>.

Revision history for this message
forrest (fjohnston) said :
#2

Yes, I would expect that but it does not.
Here is same code with prints to demonstrate:

    import org.sikuli.script.SikulixForJython
    from org.sikuli.script import Region, Finder

    imageview = Finder("emsample/emsample_screenshot.png")
    topLeft = imageview.find("emsample/rtviewLeftMenu.png")
    topRight = imageview.find("emsample/rtviewRightMenu.png")

    print("topLeft: %s, class: %s" % (topLeft, topLeft.__class__.__name__))
    print("topRight: %s, class: %s" % (topRight, topRight.__class__.__name__))
    pass

Eclipse Console Output:
    console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
    topLeft: C:\forrest\workspace\slqa_jython\slqa\sikuli\emsample\rtviewLeftMenu.png, class: unicode
    topRight: C:\forrest\workspace\slqa_jython\slqa\sikuli\emsample\rtviewRightMenu.png, class: unicode

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Sorry, partly wrong:
Finder.find() does not directly return a match, but an Iterator<Match>.

must read:
Finder.find() does not directly return a match, but the image file name on success.

How to get your match:
as mentioned: read the docs (hasNext(), next() ;-)

Can you help with this problem?

Provide an answer of your own, or ask forrest for more information if necessary.

To post a message you must log in.