← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #252048]: How to create resolution independent sikuli scripts .

 

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

RaiMan proposed the following answer:
since I was asked privately for the solution, here my answer I gave:

1. setting screen resolution
Yes, if this is possible, then you might set the screen resolution to the needed values, that your images are made for.
But be aware: I do not know how to find out the resolution, that the current screen is running with or even the application itself.
Simply taking the screen bounds might not be enough.

But you might find out, that it is the wrong setup, by driving the
workflow to a point without the need of images and then search for an
image that MUST be there. If it is not, then you might try to setup the
screen (but be aware: images cannot be used here, so it must either be
some API calling or running an external command, that does the job). If
you succeed, you have to restart the script (with RC3) or issue a
resetScreens() with 1.0.1+.

2. Knowing the screen resolution and activate the appropriate image set
Since you seem to use Sikuli scripting, this is the easiest solution:

The general approach is this:
have one script, that contains a series of images, that are used to find out in which environment (resolution) you are running:
# --- content of evalResolution.sikuli
# the same image captured in different env's
evalResImages = ( "env1eval.png", "env2eval.png", "env3eval.png", ...) 
# every member of the list corresponds to a specific env

for every known environment we have an imageset this way:
# content of envNImages.sikuli (where N corresponds to the index in evalResImages of the eval-image for this environment)
image1 = "some image file.png"
image2 = "some image file.png"
image3 = "some image file.png"
image4 = "some image file.png"
...
# same variable name for same image in all envNImages

# --- content of main.sikuli
from evalResolution import *
# drive the workflow to a point, where the image must be there
found = False
for i in range(len(evalResImages):
   if exists(evalResImages[i], 0): 
       found = True
       break
if found:
   print "running environment:", i
else:
   print "could not detect environment"
   exit(1)
# now we know, we need the imageset for env i
# we create and execute the respective import statement: from env${N}Images import *
exec("from env%dImages import *" % i)
# now the image variable names are available and the images will be found, because import .sikuli put the folder on the image path.
find(image1) # from here, the workflow can be written independently from resolution, since the fitting images are used
....

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