How to Convert Sikuli Script to Standalone Python Script

Asked by Chathura

I wanted to convert my python
I wanted to convert following psduo python code into stand alone Python code with correct imports:

print getNumberScreens()
print getBounds()
click("1449256116692.png")
doubleClick("1449256144784.png")
doubleClick("1449256178824.png")
doubleClick("1449256193974.png")
wait(1)
click(Pattern("1449257220351.png").exact().targetOffset(0,1))
click(Pattern("1449257220351.png").exact().targetOffset(0,1))
wait(1)
click(Pattern("1449256244357.png").exact().targetOffset(0,6))
type('textpatter*')
click("1449256977173.png")
myregion_primscreen = selectRegion()
print myregion_primscreen.text()

How would I do this?

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
Revision history for this message
Chathura (chathuragune) said :
#2

Can you show me a working sikuli pure python example with correct imports for click()?

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

what about the information in comment #1?

what did you try until know?

Revision history for this message
Chathura (chathuragune) said :
#4

Hi Raiman,
I use bbfreeze to convert .py scripts to standalone .exe in windows 7 machine. It works great for pure python script. Since Sikuli .py are jython version of python, I am not sure even to get it working. I wrote following pure python script:

import org.sikuli.script.SikulixForJython
from sikuli.sikuli import *
import sys
importPath = r"C:\Users\uername\Desktop\Sikuli\app_test"
if not importPath in sys.path: sys.path.append(importPath)
def test():
    popup("works!")
    wait(10)
    pass

def launch():
    App.open("C:\Program Files\Myprogram\app.exe")

test()
launch()

I am getting following error message at line 1:
ImportError: No module named org.sikuli.script.SikulixForJython

my Jython works in command line. My Jython version is 2.2.1 on java1.7_55.
I am using PyCharm IDE running Python 2.7 _32bit version.

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

- SikuliX scripts are written in Python language
- to run them you need a Jython interpreter (with version 1.1.0+ it is Jython 2.7, that is bundled with sikulix.jar (IDE))
- Jython and SikuliX in general need Java to run

hence a Python-exe-packer does not help, since the runtime environment is Python and not Java.

A comparable packer in the Java world is Launch4J, that principally does what it should.

My trials until now did not succeed with what you want to do: parts of the Jython interpreter package cannot be loaded from the jar, that is packed into the exe. It has to be exported at runtime by a Sikuli feature, that I did not implement until now.

An alternative to exe-packing is the packaging into a jar, which is simply possible in various ways with SikuliX.
Please scan the docs about that:

Revision history for this message
Chathura (chathuragune) said :
#6

Can you point to "exe-packing is the packaging into a jar, which is simply possible in various ways with SikuliX" docs?

Thanks RaiMan :)

Revision history for this message
Chathura (chathuragune) said :
#7

Raiman, what version on has those runtime features implemented in Sikuli?

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

@ comment #6
start here: http://sikulix-2014.readthedocs.org/en/latest/scripting.html#load

@ comment #7
here we are talking generally only about 1.1.0+

older versions are no longer supported for such special cases.

Revision history for this message
Jon Winsley (glitchassassin) said :
#9

I've been working on a pure Python library to run Sikuli scripts without the Java dependency. Some of my systems don't have Java due to enterprise restrictions, so I too needed to be able to run them from Python:

https://github.com/glitchassassin/lackey

It's still in alpha, but it has the basic features covered and the rest are being actively developed. Hope this helps someone.

Revision history for this message
Dominic Paré (tune.bot.yoda) said :
#10

Jon Winsley (glitchassassin)

Nice work on that lackey!
I have played around with Jython and there are a lot of problems when it comes to virtualenv and pip etc. which are quite important during development and usage of a test suite/framework. With your solution I can just use some of what I have done and still have an easier and more stable Python environment (at least from what I know about Jython and Python...).

Can you help with this problem?

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

To post a message you must log in.