From c916fa533f235c44b1997c316e6e532afac3fe68 Mon Sep 17 00:00:00 2001 From: Hans Engel Date: Sat, 29 Jun 2013 15:08:37 -0700 Subject: [PATCH] Handle invalid import file argument in both launch cases (single-profile and multi-profile launch) (#924) --- aqt/main.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/aqt/main.py b/aqt/main.py index c5781f809..5ff2babd2 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -227,8 +227,8 @@ Are you sure?""")): showInfo(_("""\ To import into a password protected profile, please open the profile before attempting to import.""")) else: - import aqt.importing - aqt.importing.importFile(self, self.pendingImport) + self.handleImport(self.pendingImport) + self.pendingImport = None runHook("profileLoaded") @@ -723,6 +723,13 @@ and check the statistics for a home deck instead.""")) # Importing & exporting ########################################################################## + def handleImport(self, path): + import aqt.importing + if not os.path.exists(path): + return showInfo(_("Please use File>Import to import this file.")) + + aqt.importing.importFile(self, path) + def onImport(self): import aqt.importing aqt.importing.onImport(self) @@ -1106,7 +1113,5 @@ Please ensure a profile is open and Anki is not busy, then try again."""), # import if not isinstance(buf, unicode): buf = unicode(buf, "utf8", "ignore") - if not os.path.exists(buf): - return showInfo(_("Please use File>Import to import this file.")) - import aqt.importing - aqt.importing.importFile(self, buf) + + self.handleImport(buf)