From ea2dfaf59c69524fdec0b4559d78ab5aad947b13 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 21 May 2013 11:53:02 +0900 Subject: [PATCH] more exporting fixes - make sure we default to last saved export location - make sure we filter out backslash - use fname not initial_path, because we're not passing in a path --- aqt/exporting.py | 12 ++++-------- aqt/utils.py | 18 ++++++------------ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/aqt/exporting.py b/aqt/exporting.py index 42b11776c..588ea1893 100644 --- a/aqt/exporting.py +++ b/aqt/exporting.py @@ -68,19 +68,15 @@ class ExportDialog(QDialog): return else: verbatim = False - # Get deck name and remove invalid filename characters deck_name = self.decks[self.frm.deck.currentIndex()] - deck_name = re.sub('[/?<>\:*|"^]', '_', deck_name) - + deck_name = re.sub('[\\\\/?<>:*|"^]', '_', deck_name) filename = os.path.join(aqt.mw.pm.base, '{}.apkg'.format(deck_name)) - while 1: - file = getSaveFile( - self, _("Export"), "export", - self.exporter.key, self.exporter.ext, - initial_path=filename) + file = getSaveFile(self, _("Export"), "export", + self.exporter.key, self.exporter.ext, + fname=filename) if not file: return if checkInvalidFilename(os.path.basename(file), dirsep=False): diff --git a/aqt/utils.py b/aqt/utils.py index 550358c75..a5940cd55 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -252,28 +252,22 @@ def getFile(parent, title, cb, filter="*.*", dir=None, key=None): d.exec_() return ret and ret[0] -def getSaveFile(parent, title, dir_description, key, ext, - initial_path=None): +def getSaveFile(parent, title, dir_description, key, ext, fname=None): """Ask the user for a file to save. Use DIR_DESCRIPTION as config - variable. The file dialog will open with an initial path of - INITIAL_PATH (this may be the path of a file or directory).""" - - if initial_path is None: - initial_path = aqt.mw.pm.base - + variable. The file dialog will default to open with FNAME.""" + config_key = dir_description + 'Directory' + base = aqt.mw.pm.profile.get(config_key, aqt.mw.pm.base) + path = os.path.join(base, fname) file = unicode(QFileDialog.getSaveFileName( - parent, title, initial_path, "{0} (*{1})".format(key, ext), + parent, title, path, "{0} (*{1})".format(key, ext), options=QFileDialog.DontConfirmOverwrite)) if file: # add extension if not file.lower().endswith(ext): file += ext - # save new default - config_key = dir_description + 'Directory' dir = os.path.dirname(file) aqt.mw.pm.profile[config_key] = dir - # check if it exists if os.path.exists(file): if not askUser(