Sikuli Library Script
- Move the function into a new file
- Make the encapsulated import script Sikuli aware.
from sikuli import *
..\\mLib.sikuli\\HelloWorldLib.py
# Import Script - Filename: .\HelloWorldLib.sikuli from sikuli import * # Instantiate a Hello World Popup Window # The parameters are comma delimited def helloWorld(Title, Body): popup( Body, Title)
Sikuli Main Script
- Add the import script path to the Jython path
- import the library
- Reload the library to incorporate changes
- Add the library image path to the Sikuli image path
- Make the call to the library
myScriptPath = "c:\\..\\<library>\\" if not myScriptPath in sys.path: sys.path.append(myScriptPath)
import <library>
reload(<library>)
myImagePath = "c:\\..\\<image library>\\" addImagePath(myImagePath)
library.function()
..\\HelloWorld.sikuli\\HelloWorld.py
# Jython will recursively search this path for .py files # Backslash must be escaped. \\ instead of \ myScriptPath = "c:\\Documents and Settings\\admin\\My Documents\\Sikuli\\mLib.sikuli" # Since the Sikuli IDE does not reload the modules while running a script each # time, Import and reload the library to make sure new changes are incorporated import HelloWorldLib reload(HelloWorldLib) # Add search path for images myDefaultImagePath = "c:\\Documents and Settings\\admin\\My Documents\\Sikuli\\images\\" myImagePath = "c:\\Documents and Settings\\admin\\My Documents\\Sikuli\\mLib.sikuli\\images" addImagePath(myDefaultImagePath) addImagePath(myImagePath) # The parameter order is Title, Body HelloWorldLib.helloWorld("Hello", "World")
As always, check all the changes into source control.
Further Reading:
Importing Sikuli Scripts¶
Image Search Path
03-08-2012
Sikuli X-1.0rc3 (r905)
No comments:
Post a Comment