Adicionar uma biblioteca? (Add a library)

Asked by Luiz Carlos on 2010-07-08

É possível adicionar uma biblioteca de funções feita em um outro arquivo *.sikuli ou *.py ou *.skl?

Algo do tipo:

include("funções.sikuli")

print func1("Olá Mundo")

----------------------------------------------

You can add a library of functions done in another file type (*. Sikuli or *. py or *. skl)?

Something like:

include ("functions.sikuli)

print func1 ("Hello World")

Question information

Language:
Brazilian Portuguese Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2010-07-22
Last query:
2010-07-22
Last reply:
2010-07-22
RaiMan (raimund-hocke) said : #1

This is really a missing feature in Sikuli script.

There are some possibilities to get it going:

1. very easy: a common file with only python code
I have a basics.py somewhere and use it at the beginning of a relevant script by:
excefile("full-path-to-my-basics.py")
This works everytime on all systems. It is built-in Python/Jython.

2. not really easy: a common file with only python code using some common images
same as 1. but you have to hardcode the references to the used images that reside in an image repository (which could be another .sikuli folder)

3. medium complicated: same as 1. but portable
you have to copy your basics.py into your scriptfolder before running your script the first time.
baseDir = getBundlePath() + "/" # slash/backslash depends on system (use getOS())
execfile(baseDir + "basics.py")

4. rather complicated: same as 2 but portable
in addition to 3. you copy all your common images to your script folder before running it the first time.
Watch Out!:all your common images have to be referenced somewhere either in basics.py or in your script, since not referenced images are deleted, when the script is saved. To preserve the images in all cases, you can put statements of the form < variable = "image.png" > for every common image into your basics.py.
Tip: to see the thumbnails for your common images after adding something like find("commonImage1.png"), you have to save and reload your script.

Luiz Carlos (luizcarlospj) said : #2

Thanks for your kind attention, had no idea how to do this, and I'll consider all options that passed me and learn and post here the result. I am fascinated by Sikuli, I really liked that program, he has done wonderful things for me, even expedited my work.

Thanks for everything.

Sincerely,
Luiz Carlos

RaiMan (raimund-hocke) said : #3

RaiMan suggests this article as additional information to your question: (a bit more complicated, but no problem with slashes/backslashes)
FAQ #1114: “Importing user defined Python modules in Sikuli”.

Luiz Carlos (luizcarlospj) said : #4

It worked perfectly doing this:
execfile ("D: \ Luiz Carlos \ Desktop \ Sikuli \ includes.sikuli \ includes.py")

K = func ()
K.aReg Region = (...)
K.click (...)

And within that file got another call:
execfile ("D: / Luiz Carlos / Desktop / Sikuli / includes.sikuli / navegador.sikuli / navegador.py ")

nav ("http://www.google.com.br")

But he had not wanted to put the whole file directory py,
for each new function that I create.
So I created the command

> Def include (pModule)
>> Execfile ("D: / Luiz Carlos / Desktop / Sikuli / includes.sikuli / " + pModule + ". Sikuli / " + pModule + " .py ")

And I modified the call for the browser, stop:
include ("navegador")

But by closing time the method call, the system complains that the methodology
does not exist.

I believe the definition of the function of the method was within "INCLUDE", and only access is there,
I do like to be accessed outside the definition of this method?

Best RaiMan (raimund-hocke) said : #5

good idea. but yes you are right, the scope of the inner def()'s is local.

good news: easy to repair:

just put a global func just before each def func():

your case:
navegador.sikuli should contain:

global nav
def nav(url):
   # here comes your code

have fun.

Luiz Carlos (luizcarlospj) said : #6

Thank you for helping me,
Now is perfect, simply call the method include ('navegador'), and I can call the methods of this.

I am very pleased with the support of such software