catch more unicode errors on import, and improve error msg

This commit is contained in:
Damien Elmes 2013-01-15 07:10:26 +09:00
parent e610776bb0
commit 3048a8e137

View file

@ -73,6 +73,11 @@ class ImportDialog(QDialog):
self.frm.importMode.setCurrentIndex(self.mw.pm.profile.get('importMode', 0)) self.frm.importMode.setCurrentIndex(self.mw.pm.profile.get('importMode', 0))
self.exec_() self.exec_()
def _unicodeWarning(self):
showWarning(_(
"Selected file was not in UTF-8 format. Please see the "
" importing section of the manual."))
def setupOptions(self): def setupOptions(self):
self.model = self.mw.col.models.current() self.model = self.mw.col.models.current()
self.modelChooser = aqt.modelchooser.ModelChooser( self.modelChooser = aqt.modelchooser.ModelChooser(
@ -149,6 +154,9 @@ you can enter it here. Use \\t to represent tab."""),
self.mw.checkpoint(_("Import")) self.mw.checkpoint(_("Import"))
try: try:
self.importer.run() self.importer.run()
except UnicodeDecodeError:
self._unicodeWarning()
return
except Exception, e: except Exception, e:
msg = _("Import failed.\n") msg = _("Import failed.\n")
err = unicode(e) err = unicode(e)
@ -269,7 +277,7 @@ def importFile(mw, file):
try: try:
importer.open() importer.open()
except UnicodeDecodeError: except UnicodeDecodeError:
showWarning(_("Selected file was not in UTF-8 format.")) self._unicodeWarning()
return return
except Exception, e: except Exception, e:
msg = unicode(e) msg = unicode(e)