Pascal Tänzer
Pascal Tänzer

Reputation: 47

Open files with python script in Gimp like File->Open

TL;DR: How to open an Image in Gimp with Python like you do with (File->Open) in order to get the Overwrite file.png option and avoid the Save the changes to image 'sample.png' before closing? Dialog.

I wrote a Python script for Gimp which does a few modifications on a selected area, and then saves it as a PNG. After that I want to open the file so the user can check, whether everything is correct or change something. Since the users of the plugin dont necessarily know how to use Gimp, so the "Save the changes to image 'sample.png' before closing?" Dialog might be confusing.
The method I currently use is

pdb.file_png_save(image, drw, new_file, new_file,0,9,0,0,0,0,0)
gimp.Display(pdb.gimp_file_load(new_file, new_file))

Upvotes: 2

Views: 2957

Answers (2)

Júlio Reis
Júlio Reis

Reputation: 173

This cleans the “dirty” bit – you will not be asked to save the image if you close it afterwards (unless you do further edits):

        image.clean_all()

See it referred to here: https://www.gimp.org/docs/python/

Upvotes: 1

Michael Schumacher
Michael Schumacher

Reputation: 538

Have a look at gimp_image_clean_all. This resets the image's dirty flag and allows it to be closed.

Note that you can't prevent it from being set again if the users change something in the image.

Upvotes: 0

Related Questions