pythonsikulisikuli-ide

Sikuli: How to prompt programatically to capture a region and save it as png in cwd


Instead of providing beforehand all the images as png to find UI elements on screen, I want to have an option for user to capture the region first time the program is run. For example, when program starts, I want user to provide image for button that fires a command and then from next time onwards, I will use that image to find that element and no user input is needed.

So basically, there is one user setup step which will capture all UI elements in the form of png images.

So question is - how to invoke region capture and wait for user to provide the region preferably by dragging and dropping mouse. At the end of this prompt, I should get a png which I will use in subsequent region.find calls. There is "Take screenshot" available in sikuli IDE. Is it exposed programatically? Also, I am working on Windows.


Solution

  • Please have a look at the docs here. With the respective setting you will be prompted for an action on FindFailed/ImageMissing. One possible action is to (re)capture the image.

    To make it work in your sense, you have to name the image in advance:

    find("image1")
    

    On prompt and capture the image will be named image1.png.

    RaiMan from SikuliX