From 2ab8b7a57492ee1f4f32c4cc9e91da51e845828c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 02:30:08 +0900 Subject: [PATCH] generalize tooltips, make sync no contact msg a tooltip --- ankiqt/ui/main.py | 32 +++++++++++++++++++++----------- ankiqt/ui/sync.py | 10 +++++----- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 8e944fcbf..4d6521c36 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -830,14 +830,17 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) self.updateRecentFiles(file) return True - def onUnsavedTimer(self): + def showToolTip(self, msg): + t = QTimer(self) + t.setSingleShot(True) + t.start(200) + self.connect(t, SIGNAL("timeout()"), + lambda msg=msg: self._showToolTip(msg)) + + def _showToolTip(self, msg): QToolTip.showText( - self.mainWin.statusbar.mapToGlobal(QPoint(0, -100)), - _("""\ -

Unsaved Deck

-Careful. You're editing an unsaved Deck.
-Choose File -> Save to start autosaving
-your deck.""")) + self.mainWin.statusbar.mapToGlobal(QPoint(0, -40)), + msg) def save(self, required=False): if not self.deck.path: @@ -845,10 +848,11 @@ your deck.""")) # backed in memory, make sure it's saved return self.onSaveAs() else: - t = QTimer(self) - t.setSingleShot(True) - t.start(200) - self.connect(t, SIGNAL("timeout()"), self.onUnsavedTimer) + self.showToolTip(_("""\ +

Unsaved Deck

+Careful. You're editing an unsaved Deck.
+Choose File -> Save to start autosaving
+your deck.""")) return if not self.deck.modifiedSinceSave(): return True @@ -1657,6 +1661,7 @@ it to your friends. onlyMerge, self.sourcesToCheck) self.connect(self.syncThread, SIGNAL("setStatus"), self.setSyncStatus) self.connect(self.syncThread, SIGNAL("showWarning"), self.showSyncWarning) + self.connect(self.syncThread, SIGNAL("noSyncResponse"), self.noSyncResponse) self.connect(self.syncThread, SIGNAL("moveToState"), self.moveToState) self.connect(self.syncThread, SIGNAL("noMatchingDeck"), self.selectSyncDeck) self.connect(self.syncThread, SIGNAL("syncClockOff"), self.syncClockOff) @@ -1731,6 +1736,11 @@ it to your friends. ui.utils.showWarning(text, self) self.setStatus("") + def noSyncResponse(self): + self.showToolTip(_("""\ +

Sync Failed

+Couldn't contact Anki Online. Please check your internet connection.""")) + def openSyncProgress(self): self.syncProgressDialog = QProgressDialog(_("Syncing Media..."), "", 0, 0, self) diff --git a/ankiqt/ui/sync.py b/ankiqt/ui/sync.py index 45979e105..1452bf6c3 100644 --- a/ankiqt/ui/sync.py +++ b/ankiqt/ui/sync.py @@ -36,8 +36,11 @@ class Sync(QThread): self.syncDeck() def error(self, error): - error = self.getErrorMessage(error) - self.emit(SIGNAL("showWarning"), error) + if error.data.get('type') == 'noResponse': + self.emit(SIGNAL("noSyncResponse")) + else: + error = self.getErrorMessage(error) + self.emit(SIGNAL("showWarning"), error) if self.onlyMerge: # new file needs cleaning up self.emit(SIGNAL("cleanNewDeck")) @@ -49,9 +52,6 @@ class Sync(QThread): msg=_("Please double-check your username/password.") elif error.data.get('status') == "oldVersion": msg=_("The sync protocol has changed. Please upgrade.") - elif error.data.get('type') == 'noResponse': - msg=_("""\ -Couldn't contact Anki Online. Please check your internet connection.""") else: msg=_("Unknown error: %s" % `getattr(error, 'data')`) return msg