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
This commit is contained in:
parent
246bd27eb3
commit
ea2dfaf59c
@ -68,19 +68,15 @@ class ExportDialog(QDialog):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
verbatim = False
|
verbatim = False
|
||||||
|
|
||||||
# Get deck name and remove invalid filename characters
|
# Get deck name and remove invalid filename characters
|
||||||
deck_name = self.decks[self.frm.deck.currentIndex()]
|
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,
|
filename = os.path.join(aqt.mw.pm.base,
|
||||||
'{}.apkg'.format(deck_name))
|
'{}.apkg'.format(deck_name))
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
file = getSaveFile(
|
file = getSaveFile(self, _("Export"), "export",
|
||||||
self, _("Export"), "export",
|
self.exporter.key, self.exporter.ext,
|
||||||
self.exporter.key, self.exporter.ext,
|
fname=filename)
|
||||||
initial_path=filename)
|
|
||||||
if not file:
|
if not file:
|
||||||
return
|
return
|
||||||
if checkInvalidFilename(os.path.basename(file), dirsep=False):
|
if checkInvalidFilename(os.path.basename(file), dirsep=False):
|
||||||
|
18
aqt/utils.py
18
aqt/utils.py
@ -252,28 +252,22 @@ def getFile(parent, title, cb, filter="*.*", dir=None, key=None):
|
|||||||
d.exec_()
|
d.exec_()
|
||||||
return ret and ret[0]
|
return ret and ret[0]
|
||||||
|
|
||||||
def getSaveFile(parent, title, dir_description, key, ext,
|
def getSaveFile(parent, title, dir_description, key, ext, fname=None):
|
||||||
initial_path=None):
|
|
||||||
"""Ask the user for a file to save. Use DIR_DESCRIPTION as config
|
"""Ask the user for a file to save. Use DIR_DESCRIPTION as config
|
||||||
variable. The file dialog will open with an initial path of
|
variable. The file dialog will default to open with FNAME."""
|
||||||
INITIAL_PATH (this may be the path of a file or directory)."""
|
config_key = dir_description + 'Directory'
|
||||||
|
base = aqt.mw.pm.profile.get(config_key, aqt.mw.pm.base)
|
||||||
if initial_path is None:
|
path = os.path.join(base, fname)
|
||||||
initial_path = aqt.mw.pm.base
|
|
||||||
|
|
||||||
file = unicode(QFileDialog.getSaveFileName(
|
file = unicode(QFileDialog.getSaveFileName(
|
||||||
parent, title, initial_path, "{0} (*{1})".format(key, ext),
|
parent, title, path, "{0} (*{1})".format(key, ext),
|
||||||
options=QFileDialog.DontConfirmOverwrite))
|
options=QFileDialog.DontConfirmOverwrite))
|
||||||
if file:
|
if file:
|
||||||
# add extension
|
# add extension
|
||||||
if not file.lower().endswith(ext):
|
if not file.lower().endswith(ext):
|
||||||
file += ext
|
file += ext
|
||||||
|
|
||||||
# save new default
|
# save new default
|
||||||
config_key = dir_description + 'Directory'
|
|
||||||
dir = os.path.dirname(file)
|
dir = os.path.dirname(file)
|
||||||
aqt.mw.pm.profile[config_key] = dir
|
aqt.mw.pm.profile[config_key] = dir
|
||||||
|
|
||||||
# check if it exists
|
# check if it exists
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
if not askUser(
|
if not askUser(
|
||||||
|
Loading…
Reference in New Issue
Block a user