generalize tooltips, make sync no contact msg a tooltip

This commit is contained in:
Damien Elmes 2009-04-23 02:30:08 +09:00
parent 0a1658de24
commit 2ab8b7a574
2 changed files with 26 additions and 16 deletions

View file

@ -830,14 +830,17 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
self.updateRecentFiles(file) self.updateRecentFiles(file)
return True 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( QToolTip.showText(
self.mainWin.statusbar.mapToGlobal(QPoint(0, -100)), self.mainWin.statusbar.mapToGlobal(QPoint(0, -40)),
_("""\ msg)
<h1>Unsaved Deck</h1>
Careful. You're editing an unsaved Deck.<br>
Choose File -> Save to start autosaving<br>
your deck."""))
def save(self, required=False): def save(self, required=False):
if not self.deck.path: if not self.deck.path:
@ -845,10 +848,11 @@ your deck."""))
# backed in memory, make sure it's saved # backed in memory, make sure it's saved
return self.onSaveAs() return self.onSaveAs()
else: else:
t = QTimer(self) self.showToolTip(_("""\
t.setSingleShot(True) <h1>Unsaved Deck</h1>
t.start(200) Careful. You're editing an unsaved Deck.<br>
self.connect(t, SIGNAL("timeout()"), self.onUnsavedTimer) Choose File -> Save to start autosaving<br>
your deck."""))
return return
if not self.deck.modifiedSinceSave(): if not self.deck.modifiedSinceSave():
return True return True
@ -1657,6 +1661,7 @@ it to your friends.
onlyMerge, self.sourcesToCheck) onlyMerge, self.sourcesToCheck)
self.connect(self.syncThread, SIGNAL("setStatus"), self.setSyncStatus) self.connect(self.syncThread, SIGNAL("setStatus"), self.setSyncStatus)
self.connect(self.syncThread, SIGNAL("showWarning"), self.showSyncWarning) 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("moveToState"), self.moveToState)
self.connect(self.syncThread, SIGNAL("noMatchingDeck"), self.selectSyncDeck) self.connect(self.syncThread, SIGNAL("noMatchingDeck"), self.selectSyncDeck)
self.connect(self.syncThread, SIGNAL("syncClockOff"), self.syncClockOff) self.connect(self.syncThread, SIGNAL("syncClockOff"), self.syncClockOff)
@ -1731,6 +1736,11 @@ it to your friends.
ui.utils.showWarning(text, self) ui.utils.showWarning(text, self)
self.setStatus("") self.setStatus("")
def noSyncResponse(self):
self.showToolTip(_("""\
<h1>Sync Failed</h1>
Couldn't contact Anki Online. Please check your internet connection."""))
def openSyncProgress(self): def openSyncProgress(self):
self.syncProgressDialog = QProgressDialog(_("Syncing Media..."), self.syncProgressDialog = QProgressDialog(_("Syncing Media..."),
"", 0, 0, self) "", 0, 0, self)

View file

@ -36,8 +36,11 @@ class Sync(QThread):
self.syncDeck() self.syncDeck()
def error(self, error): def error(self, error):
error = self.getErrorMessage(error) if error.data.get('type') == 'noResponse':
self.emit(SIGNAL("showWarning"), error) self.emit(SIGNAL("noSyncResponse"))
else:
error = self.getErrorMessage(error)
self.emit(SIGNAL("showWarning"), error)
if self.onlyMerge: if self.onlyMerge:
# new file needs cleaning up # new file needs cleaning up
self.emit(SIGNAL("cleanNewDeck")) self.emit(SIGNAL("cleanNewDeck"))
@ -49,9 +52,6 @@ class Sync(QThread):
msg=_("Please double-check your username/password.") msg=_("Please double-check your username/password.")
elif error.data.get('status') == "oldVersion": elif error.data.get('status') == "oldVersion":
msg=_("The sync protocol has changed. Please upgrade.") 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: else:
msg=_("Unknown error: %s" % `getattr(error, 'data')`) msg=_("Unknown error: %s" % `getattr(error, 'data')`)
return msg return msg