← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #200244]: __main__ changing after using sikuli in python script

 

Question #200244 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/200244

    Status: Open => Answered

RaiMan proposed the following answer:
I confirm this behavior.

This happens, if a new Region object is created by the so called spatial operators 
(docs: http://sikuli.org/docx/region.html#extending-a-region)
except inside(), which just returns the given region.

example:
r = Region(0,0,100,100)
# __main__ ok
r1 = r.right()
# __main__ modified

--- a possible workaround
at the beginning of your main script put this directly after the import of Sikuli
Settings.mymain = sys.modules["__main__"]

This will save the setting for access from everywhere for this script
run.

*** some comments on your usages of Sikuli features (but have no
influence on the above behavior)

--- import sikuli.Sikuli as sikuli
This is not a recommended way to import the Sikuli features, since sikuli is a module directory, containing the Sikuli Jpython class modules, the Sikuli.py globals modul (imports everything else needed from the Jpython and Java level) and an __init__.py, that imports Sikuli.py.
You should use:
from sikuli import *

--- sikuli.SCREEN.right()
Does not really make sense, since this will be a 0 width region with the height of Screen(0) at (x=Screen(0).w, y=0).

with the recommended import version this is the same as
right()

since all Screen and Region methods can be used in the Jpython
environment without qualification and are then redirected to the
predefined "standard" Screen object SCREEN which is a Screen(0) (primary
screen object).

So, what is your motivation for the above usage?

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.