mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add deck name to tray icons, change tooltip behaviour, coding style
This commit is contained in:
parent
a0ba32f263
commit
340a521f2f
1 changed files with 63 additions and 56 deletions
|
@ -4,70 +4,77 @@
|
|||
from PyQt4 import QtGui, QtCore
|
||||
Qt = QtCore.Qt
|
||||
|
||||
class AnkiTrayIcon( QtCore.QObject ):
|
||||
class AnkiTrayIcon(QtCore.QObject):
|
||||
"""
|
||||
Enable minimize to tray
|
||||
"""
|
||||
|
||||
def __init__( self, mw ):
|
||||
QtCore.QObject.__init__( self, mw )
|
||||
def __init__(self, mw):
|
||||
QtCore.QObject.__init__(self, mw)
|
||||
self.mw = mw
|
||||
self.anki_visible = True
|
||||
if (QtGui.QSystemTrayIcon.isSystemTrayAvailable() and
|
||||
mw.config['showTrayIcon']):
|
||||
self.ti = QtGui.QSystemTrayIcon( mw )
|
||||
self.ti = QtGui.QSystemTrayIcon(mw)
|
||||
if self.ti:
|
||||
self.mw.addHook("quit", self.onQuit)
|
||||
self.ti.setIcon( QtGui.QIcon(":/icons/anki.png") )
|
||||
self.ti.setToolTip( "Anki" )
|
||||
|
||||
self.ti.setIcon(QtGui.QIcon(":/icons/anki.png"))
|
||||
self.ti.setToolTip("Anki")
|
||||
# hook signls, and Anki state changes
|
||||
mw.addView( self )
|
||||
mw.connect(self.ti, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), lambda i: self.activated(i))
|
||||
mw.addView(self)
|
||||
mw.connect(self.ti, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"),lambda i: self.activated(i))
|
||||
mw.connect(self.ti, QtCore.SIGNAL("messageClicked()"), lambda : self.messageClicked())
|
||||
self.ti.show()
|
||||
|
||||
def showMain( self ):
|
||||
def showMain(self):
|
||||
self.mw.showNormal()
|
||||
self.mw.activateWindow()
|
||||
self.mw.raise_()
|
||||
self.anki_visible = True
|
||||
self.updateTooltip()
|
||||
|
||||
def hideMain( self ):
|
||||
def hideMain(self):
|
||||
self.mw.hide()
|
||||
self.anki_visible = False
|
||||
self.updateTooltip()
|
||||
|
||||
def activated( self, reason ):
|
||||
def activated(self, reason):
|
||||
if self.anki_visible:
|
||||
self.hideMain()
|
||||
else:
|
||||
self.showMain()
|
||||
|
||||
def messageClicked( self ):
|
||||
def messageClicked(self):
|
||||
if not self.anki_visible:
|
||||
self.showMain()
|
||||
|
||||
def setToolTip( self, message ):
|
||||
self.ti.setToolTip( message )
|
||||
def setToolTip(self, message):
|
||||
self.ti.setToolTip(message)
|
||||
|
||||
def showMessage( self, message ):
|
||||
def showMessage(self, message):
|
||||
if self.ti.supportsMessages():
|
||||
self.ti.showMessage( "Anki", message )
|
||||
self.ti.showMessage("Anki", message)
|
||||
|
||||
def setState( self, state ):
|
||||
if state == "showQuestion":
|
||||
if not self.anki_visible:
|
||||
self.showMessage( "A new card is available for review, click this message to display Anki" )
|
||||
self.setToolTip( "Anki - displaying question" )
|
||||
elif state == "showAnswer":
|
||||
self.setToolTip( "Anki - displaying answer" )
|
||||
elif state == "noDeck":
|
||||
self.setToolTip( "Anki - no deck" )
|
||||
elif state == "deckFinished":
|
||||
if self.mw and self.mw.deck:
|
||||
self.setToolTip( "Anki - next card in " + self.mw.deck.earliestTimeStr() )
|
||||
def setState(self, state):
|
||||
self.state = state
|
||||
self.updateTooltip()
|
||||
|
||||
def updateTooltip(self):
|
||||
state = self.state
|
||||
if self.mw.deck:
|
||||
name = self.mw.deck.name()
|
||||
else:
|
||||
self.setToolTip( "Anki" )
|
||||
name = "Anki"
|
||||
msg = name + ":<br>"
|
||||
if state == "deckFinished":
|
||||
msg += _("<b>Today's reviews are finished</b><br>")
|
||||
elif self.mw.deck:
|
||||
msg += _("<b>Cards are waiting</b><br>")
|
||||
if self.anki_visible:
|
||||
msg += _("Click to hide Anki")
|
||||
else:
|
||||
msg += _("Click to show Anki")
|
||||
self.setToolTip(msg)
|
||||
|
||||
def onQuit(self):
|
||||
self.ti.deleteLater()
|
||||
|
|
Loading…
Reference in a new issue