[1.1.0] variable = <automatic image file name> overwrites existing images --- is by intention

Bug #1511078 reported by Zed Zulu on 2015-10-28
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Sikuli
Undecided
RaiMan

Bug Description

So in SikuliX 1.1, there seems to be a neat new feature which automatically sets the name of a new image capture to be same as variable name if you capture the image while the cursor is after the equals sign (ie, when the cursor is on the right side of "Menu = ", the image I capture will automatically be named to Menu.png).

However, this potentially has the unintended consequence overwriting any existing image in the bundle that already has the same name. I've encountered this myself when I tried to set a switch of using different images depending on the platform tied to the same variable name. Say I intended to do something like:

if not "10.11" in Settings.getOSVersion():
    Menu = Menu.png
else:
    Menu = Menu1011.png

When I try to do the capture for the second Menu statement, it ends up overwriting the image in the first Menu statement because of the automatic rename.

I think what's needed here is a check to make sure the image doesn't already exist in the bundle before setting the name for the new image, and using naming convention like a Menu(1).png, Menu(2).png, etc, if there are existing ones. Or alternatively, make it an explicit option in the Screen Capturing preferences panel so someone can disable it if it does give them problems.

RaiMan (raimund-hocke) on 2015-10-29
Changed in sikuli:
status: New → Won't Fix
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
summary: - Automatic image file names can accidentally overwrite existing images
+ [1.1.0] variable = <automatic image file name> overwrites existing
+ images --- is by intention
RaiMan (raimund-hocke) wrote :

This feature is there to support the easy creation of image sets, so you can switch between them at runtime.
... and the overwrite is to assure, that this is reliable, even if you recapture the image.

It can be best used together with import of .sikuli, that each represent image sets for different situations.

So the variable/variable.png always represents the same visual item named with the variable name.

So in your code, there is no need to do things like that:

if not "10.11" in Settings.getOSVersion():
    Menu = Menu.png
else:
    Menu = Menu1011.png

at every place needed.

The intention is that you once at the beginning of script evaluate the environment and setup a suitable image path and then just use the images either by using the variable or the image name.

If you do not want to switch to image sets this way, then in your case you have to do it this way:

Somewhere at the beginning:
Menu = Menu.png
Menu1011 = Menu1011.png

... and later
if "10.11" in Settings.getOSVersion():
    Menu = Menu1011

... so I will not change this feature.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers