Skip to content

Commit

Permalink
adrienverge#38: now remembers last visited directory.
Browse files Browse the repository at this point in the history
This works by file selection using the GUI, or by file addition with a
drag&drop operation.

Signed-off-by: Joël Bourgault <joel.bourgault@gmail.com>
  • Loading branch information
Joël BOURGAULT committed Nov 10, 2017
1 parent c46cb5f commit f475801
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions photocollage/gtkgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def __init__(self):
self.border_c = "black"
self.out_w = 800
self.out_h = 600
self.last_visited_dir = os.path.expanduser('~')

self.opts = Options()

Expand Down Expand Up @@ -261,6 +262,10 @@ def make_window(self):
self.update_photolist([])

def update_photolist(self, new_images):
if new_images:
self.opts.last_visited_dir = os.path.dirname(
os.path.abspath(new_images[-1])
)
try:
photolist = []
if self.history_index < len(self.history):
Expand All @@ -282,11 +287,13 @@ def update_photolist(self, new_images):
dialog.destroy()

def choose_images(self, button):
dialog = PreviewFileChooserDialog(title=_("Choose images"),
parent=button.get_toplevel(),
action=Gtk.FileChooserAction.OPEN,
select_multiple=True,
modal=True)
dialog = PreviewFileChooserDialog(
title = _("Choose images"),
folder = self.opts.last_visited_dir,
parent = button.get_toplevel(),
action = Gtk.FileChooserAction.OPEN,
select_multiple = True,
modal = True)

if dialog.run() == Gtk.ResponseType.OK:
files = dialog.get_filenames()
Expand Down Expand Up @@ -779,8 +786,10 @@ class PreviewFileChooserDialog(Gtk.FileChooserDialog):
PREVIEW_MAX_SIZE = 256

def __init__(self, **kw):
folder = kw.pop('folder', '.')
super(PreviewFileChooserDialog, self).__init__(**kw)

self.set_current_folder(folder)

self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)

Expand Down

0 comments on commit f475801

Please sign in to comment.