From 9707786eea6183232c078edf517f3310e1bb84a4 Mon Sep 17 00:00:00 2001 From: Hans Engel Date: Sat, 18 May 2013 09:24:53 -0700 Subject: [PATCH] default to deckname.apkg on single deck export (#618) --- aqt/exporting.py | 7 ++++++- aqt/utils.py | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/aqt/exporting.py b/aqt/exporting.py index 0eae65964..7ff68d739 100644 --- a/aqt/exporting.py +++ b/aqt/exporting.py @@ -66,10 +66,15 @@ class ExportDialog(QDialog): return else: verbatim = False + deck_name = self.decks[self.frm.deck.currentIndex()] + 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) + self.exporter.key, self.exporter.ext, + initial_path=filename) if not file: return if checkInvalidFilename(os.path.basename(file), dirsep=False): diff --git a/aqt/utils.py b/aqt/utils.py index f046d209f..550358c75 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -252,19 +252,28 @@ def getFile(parent, title, cb, filter="*.*", dir=None, key=None): d.exec_() return ret and ret[0] -def getSaveFile(parent, title, dir, key, ext): - "Ask the user for a file to save. Use DIR as config variable." - dirkey = dir+"Directory" +def getSaveFile(parent, title, dir_description, key, ext, + initial_path=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 + file = unicode(QFileDialog.getSaveFileName( - parent, title, aqt.mw.pm.base, "{0} (*{1})".format(key, ext), + parent, title, initial_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[dirkey] = dir + aqt.mw.pm.profile[config_key] = dir + # check if it exists if os.path.exists(file): if not askUser(