-
-
Save Iunius118/83709c8915a1d44827aee8c07d39ee20 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python | |
# Original (by yahvuu): https://www.gimpusers.com/forums/gimp-developer/11718-autosave-plugin | |
import tempfile | |
import os | |
from time import * | |
from gimpfu import * | |
def autosave(image, layer): | |
# Backup interval in seconds (600 = 10 minutes) | |
backup_interval = 10 * 60 | |
print('Autosave activated') | |
backup_files = {} | |
while 1: | |
sleep(backup_interval) | |
print(ctime(time())) | |
cur_images = {} | |
for k in gimp.image_list(): | |
cur_images[k.ID] = k | |
cur_ids = cur_images.keys() | |
old_ids = backup_files.keys() | |
new_ids = [x for x in cur_ids if x not in old_ids] | |
del_ids = [x for x in old_ids if x not in cur_ids] | |
# create (empty) backup files for new images | |
for id in new_ids: | |
prefix = 'gimpbackup-ID' + str(id) + '-' | |
fn = tempfile.mkstemp(prefix=prefix, suffix='.xcf') | |
os.close(fn[0]) | |
backup_files[id] = fn[1] | |
# remove closed images' backups | |
for id in del_ids: | |
filename = backup_files[id] | |
del(backup_files[id]) | |
try: | |
os.remove(filename) | |
except: | |
gimp.message('ERROR: ' + sys.exc_info()[0]) | |
# backup images | |
for id, filename in backup_files.iteritems(): | |
img = cur_images[id] | |
try: | |
print('Saving ' + img.name + '-' + str(id) + ' to ' + filename) | |
pdb.gimp_xcf_save(1, img, img.active_drawable, filename, filename) | |
except: | |
gimp.message('ERROR: ' + sys.exc_info()[0]) | |
register( | |
"autosave", | |
"Autosave dirty hack", | |
"Periodically saves all opened images to a temp directory (/tmp, %temp%, etc.)", | |
"public domain", | |
"public domain", | |
"2016", | |
"<Image>/File/Activate Autosave", | |
"*", | |
[], | |
[], | |
autosave) | |
main() |
Plug-ins written in Python are no longer supported in the Linux version of GIMP, since Python 2 is no longer supported.
Update:
The flatpak build still seems to retain the ability to run Python plug-ins.
Plug-ins written in Python are no longer supported in the Linux version of GIMP, since Python 2 is no longer supported.
Update: The flatpak build still seems to retain the ability to run Python plug-ins.
Then how to rewrite these plugins, so gimp can use them?
Also gimp now require to put plugins in subdirectory, which means you first need to create a subdirectory in plugins directory then copy plugins in that directory, for example ~/../gimp-autosave/gimp-autosave.py
Also as much as i know python plugins still works in windows, i last tested this plugin with gimp-devel-2.8 or maybe it was 2.9, and this plugin was working fine on windows.
Extracted your plugin into /home/username/.gimp-2.10/plug-ins/ folder. Made it executable. Opened Gimp but the entry did not show up under File. So I deleted /home/username/.gimp-2.10/pluginrc. Restarted Gimp but it still didn't show up! I wonder if you could help me.
Gimp v 2.10
Operating System: Arch Linux
KDE Plasma Version: 6.1.0
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.1
Kernel Version: 6.9.5-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 12 × Intel® Core™ i5-10600 CPU @ 3.30GHz
Memory: 15.3 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics 630