adrienverge / PhotoCollage

Graphical tool to make photo collage posters
GNU General Public License v2.0
430 stars 73 forks source link

File chooser dialogs remember the last visited directory #38

Open frankMilde opened 7 years ago

frankMilde commented 7 years ago

Nice and really useful software. This is a feature request from having worked a bit with it.

It would be nice, when the Add and Save file chooser dialogs would remember (separately) the last visited dir instead of having to browse anew all the time.

adrienverge commented 7 years ago

That's true. Contributions are welcome! :)

frankMilde commented 7 years ago

I think it might be possible to hard code something and save the last visited dir and then set_current_folder upon opening the filechooser.

However, it seems, the behavior of the file chooser is partially controlled by the GTK system settings.

Until GTK+2 you could change the behavoir by changing ~/.config/gtk-2.0/gtkfilechooser.ini and choose as

StartupMode=cwd | recent | last

which would mean, when you open any file chooser, use initially cwd -> your home dir, or recent -> recently used or last -> last visited dir.

This changed with GTK+3. There is no more .ini, instead you have to

$ gsettings set org.gtk.Settings.FileChooser startup-mode cwd

Also last is no longer available as startup mode.

<enum id='org.gtk.Settings.FileChooser.StartupMode'>
    <value nick='recent' value='0'/>
    <value nick='cwd' value='1'/>
</enum>

There is still a key called last-folder-uri but it does not work as intended.

The GTK maintainers go a lot of flag for this sudden and unneccessary change, but they are a stubborn bunch and did not change anything.

ojob commented 7 years ago

Hi, Just a comment on this feature: why not save the location in a ~/.photocollage/session file? Would this be breaking any state-of-the-art development rule? If not, this is something I know how to do, and may be able to contribute in the coming weeks.

adrienverge commented 7 years ago

Hi @ojob,

Good idea, I think this would be a good way to do it.

If you want to contribute, can you split your change in two:

  1. Use a config file if present, using standard locations:

    # User-global config is supposed to be in ~/.config/photocollage/config
    if 'XDG_CONFIG_HOME' in os.environ:
       config_file = os.path.join(
           os.environ['XDG_CONFIG_HOME'], 'photocollage', 'config')
    else:
       config_file = os.path.expanduser('~/.config/photocollage/config')

    I'd like to use the YAML format for this config file, for example like this, what do you think?

    config:
     last_visited_directory: /home/adrien/photos
  2. Read / store the last visited directory in config.

ojob commented 6 years ago

Hi @adrienverge,

Ok, so I'll made two commits in the pull request I'll provide, one for file creation/handling, another for usage in the frame of visited directory storage/usage.

Concerning YAML, no problem with that. I had to read a little about it, but nothing too complicated considering the available PyYAML library.

I'll slowly start working on this in the coming weeks, as winter comes closer ;-)

adrienverge commented 6 years ago

Sounds good! :-)

ojob commented 6 years ago

I added an YamlOptionsManager class, in a config module. Not sure that the names are the best overall; feel free to propose more appropriate names (I hesitated between config and options).

In current state of branch, the Options class that existed in PhotoCollageWindow.__init__ is now handled by an instance of YamlOptionsManager, meaning that output size, border size and color, should be now tunable by manually editing the config file, or by changing the setting through the HMI and proper program exit. However, I could not yet test the code, as I still have to manage to install GTK dependencies.

ojob commented 6 years ago

@adrienverge I feel that I am, in fact, working on another topic than just remembering the last visited directory - this could have been limited to the current session.

Any idea how I could identify nicely the work on config file I'm doing, after creating a new GitHub Issue, without having to rebase all my commits with the new issue reference?

ojob commented 6 years ago

I merged the two branches.

See the result in my daily build.

ojob commented 6 years ago

I missed another location to remember: the output directory (which can be different from inputs directory). Will work on this later.