From 87d976a547703138e2de74883861095566a3037f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 30 Nov 2009 14:31:05 +0900 Subject: [PATCH] unify deck load messages, add help, add critical msg box func --- ankiqt/ui/main.py | 25 +++++++++---------------- ankiqt/ui/utils.py | 16 ++++++++++------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 264c6a054..f39f74cc6 100755 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -679,24 +679,17 @@ new: except Exception, e: if hasattr(e, 'data') and e.data.get('type') == 'inuse': 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: - fmt = traceback.format_exc().split("\n") - fmt1 = "\n".join(fmt[0:3]) - 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() + ui.utils.showCritical(_("""\ +File is corrupt or not an Anki database."""), help="DeckErrors") self.moveToState("noDeck") - return + return 0 if media is not None: self.deck.forceMediaDir = media if uprecent: diff --git a/ankiqt/ui/utils.py b/ankiqt/ui/utils.py index b189b41dd..b73c40c30 100644 --- a/ankiqt/ui/utils.py +++ b/ankiqt/ui/utils.py @@ -17,21 +17,25 @@ def openLink(link): def openWikiLink(page): openLink(ankiqt.appWiki + page) -def showWarning(text, parent=None): +def showWarning(text, parent=None, help=""): "Show a small warning with an OK button." - if not parent: - parent = ankiqt.mw - QMessageBox.warning(parent, "Anki", text) + return showInfo(text, parent, help, QMessageBox.warning) -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." if not parent: parent = ankiqt.mw + if not func: + func = QMessageBox.information sb = QMessageBox.Ok if help: sb |= QMessageBox.Help while 1: - ret = QMessageBox.information(parent, "Anki", text, sb) + ret = func(parent, "Anki", text, sb) if ret == QMessageBox.Help: openWikiLink(help) else: