I'm trying to create some GIMP plug-in and here I have gtk FileDialog:
chooser = gtk.FileChooserDialog(title="Save as...",
action=gtk.FILE_CHOOSER_ACTION_SAVE,
buttons=(gtk.STOCK_SAVE,
gtk.RESPONSE_OK,
gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL))
chooser.set_do_overwrite_confirmation(True)
I want to set current folder of the FileChoserDialog to the last used directory, like that
chooser.set_current_folder(">>>>>HERE I NEED THE DIRECTORY OF THE LAST SAVED IMAGE<<<<<<<<")
How could I do that?
The only thing I came up with is to save filenames to image.filename and then purge it.
chooser.set_current_folder(choose_set_dir())
response = chooser.run()
filename = chooser.get_filename()
chooser.destroy()
if response == gtk.RESPONSE_OK
<...>
pdb.file_jpeg_save(image, drawable, filename, filename, 0.9, 0, 0, 0, "", 2, 1, 0, 0)
clear_filenames()
image.filename = filename
image.clean_all()
def choose_set_dir():
for img in gimp.image_list():
if img.filename:
return path.dirname(img.filename)
return path.expanduser("~/Desktop")
def clear_filenames():
for img in gimp.image_list():
if img.filename:
img.filename = ""
But it's some sort of hack, and I'd like to get things right way.
Maybe not a good idea... The FileChoose doc says:
In addition, the file chooser dialog has a "Recently used" bookmark so users can quickly find any of their recently used directories.
If this isn't enough:
~/.local/share/recently-used.xbel
which is where (most, including Gimp, but not all) apps share information about recently used files. The last files are the recent ones.A couple more hints:
gimp.user_directory(n)
(n in [0..8]) returns the path of some directories: Desktop, Documents, Pictures....run_mode=RUN_INTERACTIVE
to thefile_jpeg_save
makes it elicit the JPEG options dialog, so you don't need to hardcode options, and you can userun_mode=RUN_WITH_LAST_VALS
in the following calls to reuse the same settings.