unify error support, fix typos

This commit is contained in:
Damien Elmes 2008-11-21 13:54:57 +09:00
parent ac6abd61c0
commit 0fe089f532
2 changed files with 26 additions and 29 deletions

View file

@ -394,9 +394,8 @@ class AnkiQt(QMainWindow):
anki.deck.backupDir = os.path.join( anki.deck.backupDir = os.path.join(
self.config.configPath, "backups") self.config.configPath, "backups")
def loadDeck(self, deckPath, sync=True): def loadDeck(self, deckPath, sync=True, interactive=True):
"Load a deck and update the user interface. Maybe sync." "Load a deck and update the user interface. Maybe sync."
# return None if error should be reported
# return True on success # return True on success
try: try:
self.pauseViews() self.pauseViews()
@ -405,21 +404,26 @@ class AnkiQt(QMainWindow):
finally: finally:
self.restoreViews() self.restoreViews()
if not os.path.exists(deckPath): if not os.path.exists(deckPath):
self.moveToState("nodeck") self.moveToState("noDeck")
return return
error = False
try: try:
self.deck = DeckStorage.Deck(deckPath) self.deck = DeckStorage.Deck(deckPath)
except (IOError, ImportError): except Exception, e:
error = True if hasattr(e, 'data') and e.data['type'] == 'inuse':
except DeckWrongFormatError, e: if interactive:
ui.utils.showInfo(_( ui.utils.showInfo(_("Deck is already open."))
"Please open this deck with Anki < 0.9.8.7 to upgrade.")) else:
error = True ui.utils.showInfo(_("""\
except DeckAccessError, e: Unable to load deck.
error = True
if error: Possible reasons:
self.moveToState("nodeck") - file is not an Anki deck
- deck is read only
- directory is read only
- deck was created with Anki < 0.9
To upgrade an old deck, download Anki 0.9.8.7."""))
self.moveToState("noDeck")
return return
self.updateRecentFiles(self.deck.path) self.updateRecentFiles(self.deck.path)
if sync and self.config['syncOnLoad']: if sync and self.config['syncOnLoad']:
@ -444,27 +448,20 @@ class AnkiQt(QMainWindow):
else: else:
self.deck = None self.deck = None
return 0 return 0
self.moveToState("nodeck") self.moveToState("noDeck")
return True return True
def maybeLoadLastDeck(self, args): def maybeLoadLastDeck(self, args):
"Open the last deck if possible." "Open the last deck if possible."
# try a command line argument if available # try a command line argument if available
try: if args:
if args: f = unicode(args[0], sys.getfilesystemencoding())
f = unicode(args[0], sys.getfilesystemencoding()) return self.loadDeck(f)
return self.loadDeck(f)
except:
sys.stderr.write("Error loading deck path.\n")
traceback.print_exc()
# try recent deck paths # try recent deck paths
for path in self.config['recentDeckPaths']: for path in self.config['recentDeckPaths']:
try: r = self.loadDeck(path, interactive=False)
r = self.loadDeck(path) if r:
return r return r
except:
sys.stderr.write("Error loading last deck.\n")
traceback.print_exc()
self.onNew() self.onNew()
def getDefaultDir(self, save=False): def getDefaultDir(self, save=False):
@ -661,7 +658,7 @@ class AnkiQt(QMainWindow):
new = DeckStorage.newDeckPath() new = DeckStorage.newDeckPath()
shutil.copyfile(file, new) shutil.copyfile(file, new)
file = new file = new
ret = self.loadDeck(file) ret = self.loadDeck(file, interactive=True)
if not ret: if not ret:
if ret is None: if ret is None:
ui.utils.showWarning(_("Unable to load file.")) ui.utils.showWarning(_("Unable to load file."))

View file

@ -46,7 +46,7 @@ class LatestVersionFinder(QThread):
plat=sys.platform plat=sys.platform
pver=sys.version pver=sys.version
else: else:
deckSize = "nodeck" deckSize = "noDeck"
deckRecall = "" deckRecall = ""
pending = "" pending = ""
age = "" age = ""