欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何在Eclipse和NetBeans中应用Sikuli?

最编程 2024-02-23 21:13:04
...

Netbeans

下面的例子是针对 Netbeans 6.9.的步骤:

安装python插件

你需要安装 Jython 2.5.1.

Go to menu Tools -> Plugins -> Available Plugins

In the list select everything that is in the category Python and install. If suggested by the install process always restart Netbeans.

Configure for using Sikuli script features at runtime

The plugin itself has nothing to configure, that is of value for the Sikuli usage. Everything is done on the project level, though some basic preferences act like plugin globals - we just have to know and accept this ;-)

下面是安装步骤:

  • Start a new project: File -> New Project -> Categories: Python -> Python Project -> click Next
  • In the second step Name and Location (last line), select as Python Platform: Jython 2.5.1.
  • you might want to click Make Default, if you have real Python also available (Remember: Sikuli scripts cannot be run with real Python!)
  • To integrate Sikuli: click the button Manage (only needed with the first project - it is remembered)
  • on the tab Python Path we need an additional entry, that points to path-to/sikuli-script.jar/Lib.
    • Windows: click the button Add and click through to path-to/sikuli-script.jar. Before clicking Open, edit the filename so that it shows sikuli-script.jar\Lib.
    • Mac: since the Netbeans file dialog does not allow to dive into a bundle like Sikuli-IDE.app, we have to edit the preference file directly. Since it is the same with the Java path, we have documented it seperatly below Mac/Netbeans: select library path.
  • on the tab Java Path we need an additional entry, that points to path-to/sikuli-script.jar. If you have other Java libraries, that you need in your project, add them here too.
    • Windows: click the button Add and click through to path-to/sikuli-script.jar. Clicking Open.
    • Mac: same again, see below Mac/Netbeans: Select library path.

Now you are able to run your first script. Remember, that in every script including the main script, that you are editing now, as the first line you need from sikuli.Sikuli import *, to have access to the Sikuli features at runtime.

Everytime later on you might come back to the project’s preferences with File -> Project Properties (your-project’s-name) . You will find the above information in the categorie Python.

Prepare to use Code Completion for the Sikuli methods

The NetBeans editor in the Python plugin editor is not able to recognize Python classes and methods, as long as the respective source code is embedded inside a jar-file as it is the fact with Sikuli. If you want Code Completion to work, you have to extract the folder Lib/sikuli from sikuli-script.jar, place it somewhere and add the reference to this folder to the Python Path in the project’s preferences (see above: Configure Python Path).

To extract the folder Lib/sikuli from sikuli-script.jar you might use the jar utility, that comes with the Java JDK or any other utility, that allows to unjar a jar-file.

This is a Mac example how to use the jar uility, supposing it can be found on the system path:

  • in a Terminal window go to an appropriate folder, that should contain Lib/sikuli afterwards
  • run: jar -xf /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar Lib/sikuli

You might decide, to use a folder, that is already on the Python path. One folder that is designated by Jython to contain complementary sources, that needs to be imported, is the folder Lib/site-packages in the Jython installation directory. If you copy the folder sikuli here, you do not need an additional Python path entry.

Mac/NetBeans: Select library path

To perpare the preference file modification we first add the path to Sikuli-IDE.app on both tabs: click the button Add and click through to /Applications/Sikuli-IDE.app. Depending on your selected language, the folder Applications is named like you see it in the Finder. Save the preferences by clicking close and/or ok.

The preference file is located at /Users/your-name/.netbeans/6.9/build.properties. Since it is hidden, you might have to use the Finder option “Go to Folder” (Shift-Command-G), to open the folder /Users/your-name/.netbeans/.

Open the file build.properties in your favorite editor and search for the text /Applications/Sikuli-IDE.app. It should be at the end of 2 lines beginning with pythonplatform..

On the line beginning pythonplatform. ... .javalib= extend /Applications/Sikuli-IDE.app so that it reads: /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar.

On the line beginning pythonplatform. ... .pythonlib= extend /Applications/Sikuli-IDE.app so that it reads: /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar/Lib.

Save the file and restart Netbeans. It is a good idea to check, that the correct entries are found on the 2 tabs now.