Changing settings in a bundle Sikulix + py4j
Miksser opened this issue · 5 comments
Hey! At the moment I am writing my mini framework using Sikuli + py4j. But I just can't seem to solve one problem
How can I change the settings? For example, I want to change the search precision, but changing "JavaGW.jvm.org.sikuli.basic.Settings.MinSimilarity" does nothing.
RaiMan I would really appreciate a hint on how to get around this. I think the problem is in Settings.synchronized init () but I'm not sure.
Code example:
from py4j.java_gateway import JavaGateway
JavaGW = JavaGateway()
SXPKG = JavaGW.jvm.org.sikuli
SXPKG.basic.Settings.AutoWaitTimeout = 100.0
Screen = SXPKG.script.Screen()
print(SXPKG.basic.Settings.AutoWaitTimeout) # <py4j.java_gateway.JavaPackage object at 0x7f3a09724a30>
print(Screen.getAutoWaitTimeout()) # 3.0
SikuliX version?
I am rather sure, that setting a value for a static variable in a class, that cannot be instantiated (which is true for Settings), needs other methods (e.g. reflection) to set the value, than simply saying:
SXPKG.basic.Settings.AutoWaitTimeout = 100.0
I am sorry, but currently I do not have the time to support you further.
Version 2.0.5)
No problem RaiMan. Thank you for taking the time to answer!
I think I will then try to fix the Sikuli source code myself and rebuild the api
I think I will then try to fix the Sikuli source code myself and rebuild the api
I would not do that, since your solution will then be dependant on your version of 2.0.5 and not work with next versions of SikuliX out of the box.
But if this does not matter for you: ok, do it.
I am sure, that there is a way to set a value for a static field - most probably using reflection, which is also supported by py4j.
BTW: the Settings class can indeed be instantiated (Settings()).
Maybe this is already enough:
settings = ......Settings()
settings.Auto.... = value
@RaiMan @Miksser I have been running into the same issue. Being new to py4j
resolving this is quite a challenge to me. The following are my primitive attempts, which do not work as you've pointed out.
print(SXPKG.basics.Settings.MoveMouseDelay) # 0.5
SXPKG.basics.Settings.MoveMouseDelay = float(9.8)
print(SXPKG.basics.Settings.MoveMouseDelay) # 0.5
Have you found any workaround to this and would mind sharing it? Building it into the Sikuli source isn't the way to go for me. Thank you very much in advance!
I'm using sikulixapi
Version 2.0.5 for Windows