Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to combine multiple custom SikuliX commands into 1 line - some examples #251

Closed
ck81 opened this issue May 16, 2021 · 3 comments
Closed
Labels

Comments

@ck81
Copy link

ck81 commented May 16, 2021

Hi Ken,

How are you? Hope everything's ok on your side!

Have 3 questions here.

Question 1

Have a use case in which I would like to use multiple sikuli statements using vision().

As highlighted in your post: aisingapore/TagUI#96

In TagUI, you have

vision begin
vision statement 1
vision statement 2
vision statement 3
vision finish

May I know what's the corresponding syntax in RPA-Python?

Question 2

You commented in the same post that:

For TagUI, Sikuli's integration is done through Python language.

Is it possible that to run sikuli commands directly from within Python?

Question 3

In the same post, you have this sample code:

py begin
execfile('/Users/kensoh/Desktop/v2b')
py finish

What would be the corresponding code using RPA-Python?

If I put the multiple sikuli commands in the file /Users/kensoh/Desktop/v2b, is it possible to run this file directly from RPA-Python?

Thanks in advance for your help!
Stay safe, stay healthy!

@kensoh
Copy link
Member

kensoh commented May 18, 2021

Hi CK! How are you, how have you been?

Now still bad, but have gotten into the grove (ie work in 2 full-time jobs, 1 is AISG job, 1 is taking care of 2YO baby)

Question 1

In Python there is no flexibility to have such vision begin and finish structure, so it'll either be combining all lines into 1 with ; or do it line by line by breaking up into multiple r.vision() steps. However, you can't do if and for statements this way. Do the if and for loops instead within Python, and call vision step accordingly (see if this works for your scenarios).

r.vision('statement 1; statement 2; statement 3;')
r.vision('statement 1'); r.vision('statement 2'); r.vision('statement 3');

Question 2

SikuliX native scripting language is Jython, that's why you see above can use ; as separator btw lines. However Jython isn't Python, so you can't actually import some sikuli library and use sikuli commands directly. There is a WIP Python package by SikuliX creator/maintainer but it is not yet released - https://github.com/RaiMan/sikulix4python

Question 3

The execfile('filename.py') is a Python 2 function to run a Python script, for Python 3 it is exec(open('filename.py').read()). There is also a 2nd parameter to specify whether variable scope is global or local. However both won't work in your usage scenario of running SikuliX commands, because SikuliX while is using Jython language (a Java backend running Python-like syntax), it is not a Python package that you can run within Python. So running a Python script that has SikuliX commands won't work.

@kensoh kensoh changed the title vision begin How to combine multiple custom SikuliX commands into 1 line? - see examples May 18, 2021
@kensoh kensoh added the query label May 18, 2021
@kensoh kensoh changed the title How to combine multiple custom SikuliX commands into 1 line? - see examples How to combine multiple custom SikuliX commands into 1 line? - some examples May 18, 2021
@kensoh
Copy link
Member

kensoh commented May 18, 2021

Btw CK, I've just found a good solution on the Mac Retina display problem from issue #170 -


For mac computers with Retina display, the images captured are at double resolution. Running below in your Python script will auto-scale your supplied images down to the actual resolution to do visual automation. I don't have Retina display, but have tried and tested successfully with a fake double-sized image.

r.vision('Settings.AlwaysResize = 0.5')

@ck81
Copy link
Author

ck81 commented May 19, 2021

r.vision('statement 1; statement 2; statement 3;')
r.vision('statement 1'); r.vision('statement 2'); r.vision('statement 3');

Hi Ken,

For your info, both worked!

I actually wanted to use multiple vision statements because I want to click images in the second monitor. I googled. It seems I can achieve these with multiple vision statements.

But with your solution from #252, you have solved my problem with a one-liner:

r.vision('Screen(1).click("d:/tagui/img1.png")')

So no need multiple vision statements now. But it's good to know this in case I need to use this later.

Thanks a lot, Ken!

@kensoh kensoh closed this as completed May 19, 2021
@kensoh kensoh changed the title How to combine multiple custom SikuliX commands into 1 line? - some examples How to combine multiple custom SikuliX commands into 1 line - some examples May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants