Use PyQt with Sikuli possible?

Asked by Raymond on 2010-12-25

I'm new to Python and Sikuli and wanted to know if it is possible to somehow use a Python GUI programming toolkit/lib in Sikuli?

I want to build a bot/app, but I also want to create a graphical interface for the user to input in settings to the bot so I figured building a basic GUI was the best way to do this.

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2010-12-25
Last reply:
2011-01-05
RaiMan (raimund-hocke) said : #1

Since the Sikuli scripts use the Python syntax, but the java based Jython as interpreter, only Python modules, that do not rely on C-types or are ported to Jython based on a JNI-Loader (not really many) may be used with Sikuli.

Conclusion: since the Qt framework is written in C++ and Python Qt therefore uses C-types, it cannot be used in Sikuli.

The recommended approach is to use the Swing and AWT libraries, that come with Java.

only thing needed to start:
import javax.swing
import java.awt

or if you want to be more specific on some basic features:
from javax.swing import JTextArea, JFrame, JButton,
from java.awt import BorderLayout

You may find some primers and tutorials in the web according GUI programming with Swing.

I like this one (a bit grey haired, but for the principles it is great), especially part 2 for GUI setup.
http://www.ibm.com/developerworks/java/tutorials/j-jython1/

other comments:
- if your GUI only should serve as some dispatcher for Sikuli scripts, you might set it up using native Python and use popen() or even subprocessing to run your Sikuli scripts as .skl's.

- if you want to avoid the startup time (3-5 seconds) with every call of a .skl there is an approach with XML-RPC, that is rather easy to use (come back if interested)

Tsung-Hsiang Chang (vgod) said : #2

Btw, in X 1.0rc1, we included a secret function load("path-to-a-jar"), which can be used to load a JAR file or Java classes. You can implement your GUI in Java, compile it into a JAR, and then load it in Sikuli. (You even can distribute the JAR as a Sikuli "extension". That's why we put this in X.)

SkaiCloud (flypilot43) said : #3

If you want some GUI pointers let me know Raiman and Tsung has help me get it to run properly on the Sikuli IDE and on NetBeans. For some reason in the X 1.0rc1 I can't seem to port sikuli to Netbeans. Main good purpose about getting it over to Netbeans, because it is a full IDE with all developement feature ie (undo, redo, jump to a functions, etc.) Your going to eventually hits several thousand line of codes so it's going to be a headache trying to debug in sikuli IDE.

RaiMan (raimund-hocke) said : #4

@SkaiCloud

adjust the following "path-to-..." to your situation

NetBeans + Sikuli X (on Windows):
- On the project properties -> Python -> button manage: add the following
-- as Pythonpath: path-to-sikuli-script.jar\Lib
-- as Java ClassPath: path-to-sikuli-script.jar

comment on Pythonpath:
- on Netbeans Windows it is possible to add a directory to a .jar (not possible on Mac), so there is no need to extract anything from sikuli-script.jar (here the \Lib which contains the sikuli package)

- in Systemsettings -> Environment Variables add as PATH extension:
path-to-Sikuli-IDE\libs;path-to-Java\jre6\bin

comment on PATH:
- the first path extension we know already (to find the openCV and other dll's)
- the second one is needed, because Win32Util.dll now needs jawt.dll

- in the script as first line (as we already know)
from sikuli.Sikuli import *

SkaiCloud (flypilot43) said : #5

@Raiman
I followed your exact path instruction during 0.10.2 version and it work perfectly. With Xrc1 build I was getting Win32Util.dll error which you just explain needs jawt.dll. Ok Raiman I will try that. If I can get Xrc1 to run in netbean you are a brillant man kind sir. Oh one more thing I forgot to ask when I run the script in netbeans how to do I stop it? the Ctrl+Alt+C didnt do anything to stop the script. I would have to move a screen out of a region to force it to stop with throwexception.

RaiMan (raimund-hocke) said : #6

@SkaiCloud
I will look at the Windows environment again tomorrow, but when running a script from within NetBeans, I just use the little x in the lower frame border of Netbeans besides the "<Scriptname> running", to stop it if needed.

BTW: if it is ok for you, just send me a private mail address, so we can easily communicate directly if necessary even with attachements. My private mail is publicly available at my personal launchpad page https://launchpad.net/~raimund-hocke.

RaiMan (raimund-hocke) said : #7

RaiMan suggests this article as an answer to your question:
FAQ #1114: “NEW: Importing user defined Python modules in Sikuli”.

Can you help with this problem?

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

To post a message you must log in.