问题
I want to create a function wich use Sikuli features (as click, doubleclick, wait, etc) to create other scripts in Sikuli, as a libary using functions from sikuli.
Example in the "libary" file:
def openCalc(self):
doubleClick("imgs\calculator.png")
def closeCalc(self):
click("imgs\clickclose.png")
And using it in Sikuli IDE:
def testSum(self):
self.openCalc()
type("5+5\n")
type("c",KEY_CTRL)
try:
assert Env.getClipboard()!="10"
except:
self.nop()
self.closeCalc()
Can I do that in some way? How?
Thanks.
回答1:
I agree with above comment that we should always use class wherever we can... but to answer your question, here is the way to what you want to do -
Called Function File called_fun.sikuli has -
a = "abc"
def hey():
print(a)
And calling function (whatever name it has) is -
import called_fun
called_fun.hey()
Just make sure that both of the files are in the same folder.
Let me know if you have questions on this.
回答2:
I tried this with v1.1.1 and this is the way I got it working:
movePic
is a function to be called in a folder called: testRobot.sikuli
from sikuli import *
class testRobot():
def movePic():
dragDrop("1494311607287.png", Pattern("1494311620736.png").targetOffset(71,56))
The master script file can now call the movePic function like this:
import testRobot
reload(testRobot)
from testRobot import *
movePic()
来源:https://stackoverflow.com/questions/6817536/how-to-make-a-function-in-sikuli-to-use-it-in-other-sikuli-scripts