Push/Pop and addImagePath

Asked by Zeks

To avoid name clashes and simplify development all of my screenshots are organized as Project/Module/Window/Name1.png ...

Sometines there can be intersection as in
Project/Module/Window/Name1.png
Project/Module2/Window/Name1.png

therefore I use a pattern everywhere:
A module.py contains a part of the path to add while searching for its images and invokes search function as

findEntity(globalProjectPath + moduleImagePath)
which is in the function used as:
    addImagePath(path)
....
    remove imagePath(path)

repeated everywhere. This does resolve any possible name clashes but this removeImagePath seems excessive.
I kinda remember OpenGL programming where you could glPushContext/glPopContext.

Can we have stuff like that for imagePath in sikuli?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

With Python scripting and SikuliX, the smoothest way to organise your images is the following:

what you name a context can be a module named someContext.sikuli, containing:

img1 = "someImage.png"
img1P1 = Pattern(img1).exact() #optional
img1P2 = Pattern(img1P1).targetOffset(x, y) #optional

the variableness of course should be along some naming convention and "speaking" to some extent.

Having such a module you now can do the following in your main workflow:

import someContext

click(someContext.img1P2)

now you have separated code and images.

With the latest build of 1.1.0 this is supported in the IDE:

write in a blank line
someImage =

leave the cursor in that line, press the capture button and capture.
Coming back to the IDE, you will see that the image file is named "someImage.png" automatically.
Repeating the action (e.g. to optimise the image shot) the image file will be overwritten without notice (which is what one would expect)

Revision history for this message
RaiMan (raimund-hocke) said :
#2

to address your question:
I do not understand the difference between a combination of addImagePath/removeImagePath and glPushContext/glPopContext.
in both cases you have to say somewhere setupNewContext and somewhere else later teardownNewContext.

Revision history for this message
Zeks (enmarantispam) said :
#3

Hm, but what will happen if the image name is in someContext.sikuli, but the actual search function is in entirely separate module?

I usually do stuff like SupportModule.findEntity(imageName). will it search ONLY the context of someContext? Otherwise it will either not find it or there will be a clash.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Image names not given as absolute path will always be searched on the current image path, where the current bundle path (main script) will always be the first entry.
addImagePath() always adds to the end.
To find an imagefile, the imagePath is scanned from first to last entry and stops with the first success.

LOL, writing this, I have to admit, that you are half right:
- an imagefile will always be found, since each import of a .sikuli adds to the image path as well (where ever it was issued)
- but nameclashes are still possible, since the file search is not restricted and always on the complete current image path (and we do not have an unimport yet)

So to implement your approach, the directory structure has to be converted into a structure filename:

instead of
Project/Module/Window/Name1.png

you would have
Project/Module/Images.sikuli

and in Images.Sikuli
img1 = "Window_someImage.png"

supposing the level Window is the differentiating level.

Another possibility would be:
Project/Module.sikuli

and inside you have subdirectories
Project/Module.sikuli/Window/Name1.png

and then
img1 = "Window/someImage.png"

nevertheless: interesting discussion - adds to what I will implement in version 2 with ImageGroup. Thanks.

Revision history for this message
Zeks (enmarantispam) said :
#5

Kinda related to that:
I want some selector in the ide where I can (with 1 click) choose from a set of directories one that is currently used to save screenshots.

Say, I want to do some mail screenshots, I click Drive:\Project\Mail in this element and the next time I make a screenshot it will save into that folder.

The reason I need this for is because of the way my screenshots are organized I always have to
1) make a screenshot into .sikuli folder
2) copy/paste it into folder it really supposed to live in

Revision history for this message
RaiMan (raimund-hocke) said :
#6

@Zeks
could you please post a [request] bug for that.
So you can see, how and when I plan to implement this.

Can you help with this problem?

Provide an answer of your own, or ask Zeks for more information if necessary.

To post a message you must log in.