unify deck load messages, add help, add critical msg box func

This commit is contained in:
Damien Elmes 2009-11-30 14:31:05 +09:00
parent ba3298cf3b
commit 87d976a547
2 changed files with 19 additions and 22 deletions

View file

@ -679,24 +679,17 @@ new:
except Exception, e: except Exception, e:
if hasattr(e, 'data') and e.data.get('type') == 'inuse': if hasattr(e, 'data') and e.data.get('type') == 'inuse':
if interactive: if interactive:
ui.utils.showInfo(_("Deck is already open.")) ui.utils.showWarning(_("Deck is already open."))
else:
return
elif hasattr(e, 'data') and e.data.get('type') == 'corrupt':
ui.utils.showCritical(_("\
File is corrupt.\nPlease restore from backup."), help="DeckErrors")
else: else:
fmt = traceback.format_exc().split("\n") ui.utils.showCritical(_("""\
fmt1 = "\n".join(fmt[0:3]) File is corrupt or not an Anki database."""), help="DeckErrors")
fmt2 = "\n".join(fmt[-3:])
ui.utils.showInfo(_("""\
Unable to load deck.
Possible reasons:
- 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."""))
traceback.print_exc()
self.moveToState("noDeck") self.moveToState("noDeck")
return return 0
if media is not None: if media is not None:
self.deck.forceMediaDir = media self.deck.forceMediaDir = media
if uprecent: if uprecent:

View file

@ -17,21 +17,25 @@ def openLink(link):
def openWikiLink(page): def openWikiLink(page):
openLink(ankiqt.appWiki + page) openLink(ankiqt.appWiki + page)
def showWarning(text, parent=None): def showWarning(text, parent=None, help=""):
"Show a small warning with an OK button." "Show a small warning with an OK button."
if not parent: return showInfo(text, parent, help, QMessageBox.warning)
parent = ankiqt.mw
QMessageBox.warning(parent, "Anki", text)
def showInfo(text, parent=None, help=""): def showCritical(text, parent=None, help=""):
"Show a small critical error with an OK button."
return showInfo(text, parent, help, QMessageBox.critical)
def showInfo(text, parent=None, help="", func=None):
"Show a small info window with an OK button." "Show a small info window with an OK button."
if not parent: if not parent:
parent = ankiqt.mw parent = ankiqt.mw
if not func:
func = QMessageBox.information
sb = QMessageBox.Ok sb = QMessageBox.Ok
if help: if help:
sb |= QMessageBox.Help sb |= QMessageBox.Help
while 1: while 1:
ret = QMessageBox.information(parent, "Anki", text, sb) ret = func(parent, "Anki", text, sb)
if ret == QMessageBox.Help: if ret == QMessageBox.Help:
openWikiLink(help) openWikiLink(help)
else: else: