How to set the default open path for a Gtk.FileChooserWidget?

gtk, python

Solution

From the docs:

Old versions of the file chooser's documentation suggested using gtk_file_chooser_set_current_folder() in various situations, with the intention of letting the application suggest a reasonable default folder. This is no longer considered to be a good policy, as now the file chooser is able to make good suggestions on its own. In general, you should only cause the file chooser to show a specific folder when it is appropriate to use gtk_file_chooser_set_filename() - i.e. when you are doing a File/Save As command and you already have a file saved somewhere.

You may or may not like the reasoning for this behavior. If you're curious about how it came about, see File chooser recent-files in the mailing list and Help the user choose a place to put a new file on the GNOME wiki.

Problem

If I set the current folder via the method `Gtk.FileChooserWidget.set_current_folder()`, the first time I open the file chooser, it opens on the location used as argument for `set_current_folder()` But, if I select a file, the I re-open the file-chooser, it opens on the "most_recent_used_files". I'd like it opens on the last selected file's folder path. How to do it? Thank you.

Original source