mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Couple of small improvements to make it easier to add new toolbar buttons.
* Force icon size to 16x16, otherwise they blow up the toolbar. * Refactor button callbacks into a dict instead of the "case" statement to make it easier to add new callbacks for buttons from within plugins.
This commit is contained in:
parent
288cd67d0c
commit
21b5aba0f8
1 changed files with 35 additions and 20 deletions
|
@ -3,7 +3,6 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.webview import AnkiWebView
|
|
||||||
|
|
||||||
class Toolbar(object):
|
class Toolbar(object):
|
||||||
|
|
||||||
|
@ -13,6 +12,14 @@ class Toolbar(object):
|
||||||
self.web.page().mainFrame().setScrollBarPolicy(
|
self.web.page().mainFrame().setScrollBarPolicy(
|
||||||
Qt.Vertical, Qt.ScrollBarAlwaysOff)
|
Qt.Vertical, Qt.ScrollBarAlwaysOff)
|
||||||
self.web.setLinkHandler(self._linkHandler)
|
self.web.setLinkHandler(self._linkHandler)
|
||||||
|
self.link_handlers = {
|
||||||
|
"decks": self._deckLinkHandler,
|
||||||
|
"study": self._studyLinkHandler,
|
||||||
|
"add": self._addLinkHandler,
|
||||||
|
"browse": self._browseLinkHandler,
|
||||||
|
"stats": self._studyLinkHandler,
|
||||||
|
"sync": self._syncLinkHandler,
|
||||||
|
}
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.web.stdHtml(self._body % (
|
self.web.stdHtml(self._body % (
|
||||||
|
@ -52,33 +59,41 @@ class Toolbar(object):
|
||||||
def _rightIcons(self):
|
def _rightIcons(self):
|
||||||
buf = ""
|
buf = ""
|
||||||
for ln, icon, title in self._rightIconsList():
|
for ln, icon, title in self._rightIconsList():
|
||||||
buf += '<a class=hitem title="%s" href="%s"><img src="%s"></a>' % (
|
buf += '<a class=hitem title="%s" href="%s"><img width="16px" height="16px" src="%s"></a>' % (
|
||||||
title, ln, icon)
|
title, ln, icon)
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
# Link handling
|
# Link handling
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def _linkHandler(self, l):
|
def _linkHandler(self, link):
|
||||||
# first set focus back to main window, or we're left with an ugly
|
# first set focus back to main window, or we're left with an ugly
|
||||||
# focus ring around the clicked item
|
# focus ring around the clicked item
|
||||||
self.mw.web.setFocus()
|
self.mw.web.setFocus()
|
||||||
if l == "decks":
|
if link in self.link_handlers:
|
||||||
|
self.link_handlers[link]()
|
||||||
|
|
||||||
|
def _deckLinkHandler(self):
|
||||||
self.mw.moveToState("deckBrowser")
|
self.mw.moveToState("deckBrowser")
|
||||||
elif l == "study":
|
|
||||||
|
def _studyLinkHandler(self):
|
||||||
# if overview already shown, switch to review
|
# if overview already shown, switch to review
|
||||||
if self.mw.state == "overview":
|
if self.mw.state == "overview":
|
||||||
self.mw.col.startTimebox()
|
self.mw.col.startTimebox()
|
||||||
self.mw.moveToState("review")
|
self.mw.moveToState("review")
|
||||||
else:
|
else:
|
||||||
self.mw.onOverview()
|
self.mw.onOverview()
|
||||||
elif l == "add":
|
|
||||||
|
def _addLinkHandler(self):
|
||||||
self.mw.onAddCard()
|
self.mw.onAddCard()
|
||||||
elif l == "browse":
|
|
||||||
|
def _browseLinkHandler(self):
|
||||||
self.mw.onBrowse()
|
self.mw.onBrowse()
|
||||||
elif l == "stats":
|
|
||||||
|
def _statsLinkHandler(self):
|
||||||
self.mw.onStats()
|
self.mw.onStats()
|
||||||
elif l == "sync":
|
|
||||||
|
def _syncLinkHandler(self):
|
||||||
self.mw.onSync()
|
self.mw.onSync()
|
||||||
|
|
||||||
# HTML & CSS
|
# HTML & CSS
|
||||||
|
|
Loading…
Reference in a new issue