← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #194681]: Use String to call Function?

 

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

RaiMan proposed the following answer:
Ah gut, mal wieder jemand aus Germany ;-)

--- Screen(1) for ALL calls which come after this statement?

--1. use with region:
saying:
with Screen(1):
    click(some_image)

will search for some_image on Screen(1).
All function calls in the with block are implicitly qualified as Screen(1).function()

If this looks ugly or makes problems (which might be ;-), this is

--2. redefine SCREEN
When a script is started (or first time in the IDE), the a "from sikuli import *" is executed, which in turn makes some initialization.
One aspect is to define SCREEN as Screen(0) and copy all methods to the global dictionary, so that the Screen/Region methods called without a region qualifier are executed as SCREEN.method().

So you might try the following once at the beginning of the main script.

dict = globals()
dict['SCREEN'] = Screen(1)
dict['SCREEN']._exposeAllMethods(__name__)

This is the same code that is used to setup/initialize the SCREEN as
Screen(0).

I cannot test it, since I currently have no multi monitor environment.

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