← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #144772]: Python style Dictionary, string as key

 

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

RaiMan posted a new comment:
Oh yes, it is really a good idea, to use a dictionary to store your
image references. This gives some more options, than simply having a
bunch of "imgXXXX = 12345678.png" in the image-library.

But why don't you put the dictionary setup and the wrapper class in the
imagelib too? If you need more than one imageset (your resolution case),
you could solve that, when initializing the class.

So in the latter case, you had:

--1. the image containers: e.g.
imagesHiRes.sikuli
imagesStandard.sikuli
imagesLowRes.sikuli

each of these contain a dictionary like this (with same name to be reusable ;-)
theImgDict = {}
theImgDict["image1"] = "some-image1.png"
theImgDict["image2"] = "some-image2.png"
theImgDict["image3"] = "some-image3.png"
.....
may be many more - should have some naming convention

--2. now we need a wrapper for that, to select an image set and access the images
we put it in a file imageDictWrapper.sikuli

class imageDictWrapper():
 
   def __init__(self, imageSet = "HiRes"):
# image set is evaluated to load (import) one of the image sets
# if not given, the HiRes is loaded
      from imagesXXXX import *
# the imported dictionary is assigned to an object variable e.g. images
      self.images = theImgDict

   def getImage(self, imageName):
# we need some logic to assure image exists
      return images[imageName]

--3. now we have a script that uses all this stuff
# supposing sys.path is ready
from imageDictWrapper import *
imgSet = imageDictWrapper("LowRes") # we want the LowRes image set

# and now our first action:
click(imgSet.getImage("image1"))

... and so on

do not blame me please, if something is not correct ;-)
Only wanted to put my idea on the whiteboard.

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