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
|
from PyQt4 import QtGui, QtCore
|
||||||
Qt = QtCore.Qt
|
Qt = QtCore.Qt
|
||||||
|
|
||||||
class AnkiTrayIcon( QtCore.QObject ):
|
class AnkiTrayIcon(QtCore.QObject):
|
||||||
"""
|
"""
|
||||||
Enable minimize to tray
|
Enable minimize to tray
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__( self, mw ):
|
def __init__(self, mw):
|
||||||
QtCore.QObject.__init__( self, mw )
|
QtCore.QObject.__init__(self, mw)
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.anki_visible = True
|
self.anki_visible = True
|
||||||
if (QtGui.QSystemTrayIcon.isSystemTrayAvailable() and
|
if (QtGui.QSystemTrayIcon.isSystemTrayAvailable() and
|
||||||
mw.config['showTrayIcon']):
|
mw.config['showTrayIcon']):
|
||||||
self.ti = QtGui.QSystemTrayIcon( mw )
|
self.ti = QtGui.QSystemTrayIcon(mw)
|
||||||
if self.ti:
|
if self.ti:
|
||||||
self.mw.addHook("quit", self.onQuit)
|
self.mw.addHook("quit", self.onQuit)
|
||||||
self.ti.setIcon( QtGui.QIcon(":/icons/anki.png") )
|
self.ti.setIcon(QtGui.QIcon(":/icons/anki.png"))
|
||||||
self.ti.setToolTip( "Anki" )
|
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.connect(self.ti, QtCore.SIGNAL("messageClicked()"), lambda : self.messageClicked())
|
||||||
|
self.ti.show()
|
||||||
|
|
||||||
# hook signls, and Anki state changes
|
def showMain(self):
|
||||||
mw.addView( self )
|
self.mw.showNormal()
|
||||||
mw.connect(self.ti, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), lambda i: self.activated(i))
|
self.mw.activateWindow()
|
||||||
mw.connect(self.ti, QtCore.SIGNAL("messageClicked()"), lambda : self.messageClicked())
|
self.mw.raise_()
|
||||||
self.ti.show()
|
self.anki_visible = True
|
||||||
|
self.updateTooltip()
|
||||||
|
|
||||||
def showMain( self ):
|
def hideMain(self):
|
||||||
self.mw.showNormal()
|
self.mw.hide()
|
||||||
self.mw.activateWindow()
|
self.anki_visible = False
|
||||||
self.mw.raise_()
|
self.updateTooltip()
|
||||||
self.anki_visible = True
|
|
||||||
|
|
||||||
def hideMain( self ):
|
def activated(self, reason):
|
||||||
self.mw.hide()
|
if self.anki_visible:
|
||||||
self.anki_visible = False
|
self.hideMain()
|
||||||
|
else:
|
||||||
|
self.showMain()
|
||||||
|
|
||||||
def activated( self, reason ):
|
def messageClicked(self):
|
||||||
if self.anki_visible:
|
if not self.anki_visible:
|
||||||
self.hideMain()
|
self.showMain()
|
||||||
else:
|
|
||||||
self.showMain()
|
|
||||||
|
|
||||||
def messageClicked( self ):
|
def setToolTip(self, message):
|
||||||
if not self.anki_visible:
|
self.ti.setToolTip(message)
|
||||||
self.showMain()
|
|
||||||
|
|
||||||
def setToolTip( self, message ):
|
def showMessage(self, message):
|
||||||
self.ti.setToolTip( message )
|
if self.ti.supportsMessages():
|
||||||
|
self.ti.showMessage("Anki", message)
|
||||||
|
|
||||||
def showMessage( self, message ):
|
def setState(self, state):
|
||||||
if self.ti.supportsMessages():
|
self.state = state
|
||||||
self.ti.showMessage( "Anki", message )
|
self.updateTooltip()
|
||||||
|
|
||||||
def setState( self, state ):
|
def updateTooltip(self):
|
||||||
if state == "showQuestion":
|
state = self.state
|
||||||
if not self.anki_visible:
|
if self.mw.deck:
|
||||||
self.showMessage( "A new card is available for review, click this message to display Anki" )
|
name = self.mw.deck.name()
|
||||||
self.setToolTip( "Anki - displaying question" )
|
else:
|
||||||
elif state == "showAnswer":
|
name = "Anki"
|
||||||
self.setToolTip( "Anki - displaying answer" )
|
msg = name + ":<br>"
|
||||||
elif state == "noDeck":
|
if state == "deckFinished":
|
||||||
self.setToolTip( "Anki - no deck" )
|
msg += _("<b>Today's reviews are finished</b><br>")
|
||||||
elif state == "deckFinished":
|
elif self.mw.deck:
|
||||||
if self.mw and self.mw.deck:
|
msg += _("<b>Cards are waiting</b><br>")
|
||||||
self.setToolTip( "Anki - next card in " + self.mw.deck.earliestTimeStr() )
|
if self.anki_visible:
|
||||||
else:
|
msg += _("Click to hide Anki")
|
||||||
self.setToolTip( "Anki" )
|
else:
|
||||||
|
msg += _("Click to show Anki")
|
||||||
|
self.setToolTip(msg)
|
||||||
|
|
||||||
def onQuit(self):
|
def onQuit(self):
|
||||||
self.ti.deleteLater()
|
self.ti.deleteLater()
|
||||||
|
|
Loading…
Reference in a new issue