[1.1.4 PyJnius] How to set 'similar' from default 0.7 to 1.0 ?

Asked by Dirk Schiller on 2019-02-06

My Script:

import os, sys

# https://github.com/blackrosezy/gui-inspect-tool
# https://raiman.github.io/SikuliX1/downloads.html
# http://doc.sikuli.org/javadoc/index.html
# https://sikulix-2014.readthedocs.io/en/latest/genindex.html

# Windows 10 Screen Scale > 100% : [error] RobotDesktop: checkMousePosition: should be L[2880,540]@S(1)...
# https://github.com/RaiMan/SikuliX-2014/issues/292
# Solution: Scale back to 100% and remake all Screenshots if not done with 100% Scale

jarpath = ';' + os.path.dirname(os.path.realpath(__file__)) + '/sikulixapi-1.1.4.jar' # It's the sikulixapi.jar File; just renamed it to know the Version
if not 'CLASSPATH' in os.environ:
    os.environ['CLASSPATH'] = jarpath
    os.environ['CLASSPATH'] += jarpath

from jnius import autoclass

App = autoclass('org.sikuli.script.App')
Screen = autoclass('org.sikuli.script.Screen')
Pattern = autoclass('org.sikuli.script.Pattern')
Finder = autoclass('org.sikuli.script.Finder')
Settings = autoclass('org.sikuli.basics.Settings') # In Sikuli's JavaDoc this Package is named 'org.sikuli.script.Settings'; very Strange
Debug = autoclass('org.sikuli.basics.Debug')

user = 'DOP'
ext_drive = 'E'

class Sikuli:

    def start_app(self, path, app):
        app = App(os.path.join(path, app))

    def click_image(self, image, timeout=5):
        screen = Screen()
        # Debug.info("Screen: %s", screen)
        # pat = Pattern(image)
        # pat.similar(1.0) # Throw an Error: TypeError: 'float' object is not callable
        # pat.similar = 1.0 # Throw an Error: AttributeError: can't set attribute
        # screen.exists(pat, 0)
        Settings.MinSimilarity = 1.0 # Doesn't work / doesn't show any Effect
        Settings.setShowActions(True) # Doesn't work / doesn't show any Effect
        screen.wait(image, timeout)

My Question: How can I set the Similar Sikuli Attribute / Setting from it's default 0.7 Value to 1.0 ?

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Dirk Schiller
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

see the docs for the Python scripting level (comment on Java API in Python scripts later).


RaiMan (raimund-hocke) said : #2

I want to give a few comments on your approach.

--- # http://doc.sikuli.org/javadoc/index.html
this link is no longer supported and does not reflect the actual version
actual javadoc for 1.1.4: https://raiman.github.io/SikuliX1/javadocs/index.html
BE Aware: it is always a good idea to first look into the docs (https://sikulix-2014.readthedocs.io/en/latest) and afterwards may be at the Java API level.

--- from jnius import autoclass
I do not recommend, to use jnius:
this is intended to bridge Java Api's from C-Python.
SikuliX is Java based and uses Jython as interpreter (language level 2.7)
As such, you have direct access to all Java classes by just using import.
... if you use Jython either implizit via SikuliX IDE (sikulix.jar) or with plain Jython and sikulixapi.jar on classpath
... and if you use Jython, then there is no need for jnius, since the relevant classes are already pre-imported, when you run your scripts obeying the SikuliX rules for Python scripting.

Come back, if you have more questions, that might not be obvious when looking into the docs.

One more thing:
Please make a new question, for a new topic.
Do not change an existing question, to ask different things.
In doubt use the comment, to add information.

I get notified immediately by every change to every post on Launchpad and usually answer within 24 hours.

All the best

But finally of course it is your decision, how to get on the road.

Dirk Schiller (dschiller) said : #3

I exactly tried those things, but as I wrote in my Script ( see above ) it doesn't work. Any other Solutions ?


Dirk Schiller (dschiller) said : #4

Ok I understand. Thanks for your Answers. Unfortunetly I can not use Python 2.7 and for that I can not use Jython, it doesn't support Python 3.7.x.

Thanks for everything. It was a try to use your Framework.


RaiMan (raimund-hocke) said : #5

ok, understood.

Do you know that?

Dirk Schiller (dschiller) said : #6

Hey RaiMan, no i don't know it. I will try it as well, thank' s a lot. At the Moment I even try Jython and Sikuli but don't have luck so far.

Dirk Schiller (dschiller) said : #7

Found a Solution for the '# pat.similar(1.0) # Throw an Error: TypeError: 'float' object is not callable':

In 'C:\Users\DOP\AppData\Local\Programs\Python\Python37\Lib\site-packages\jnius\reflect.py' change ( Line 188 with pyjnius Version 1.2.0:

            if name != 'getClass' and bean_getter(name) and len(method.getParameterTypes()) == 0:
                lowername = lower_name(name[2 if name.startswith('is') else 3:])
                classDict[lowername] = (lambda n: property(lambda self: getattr(self, n)()))(name)


            if name != 'getClass' and bean_getter(name) and len(method.getParameterTypes()) == 0:
                lowername = lower_name(name[2 if name.startswith('is') else 3:])
                if lowername not in methods_name:
                 classDict[lowername] = (lambda n: property(lambda self: getattr(self, n)()))(name)