2012-12-21 08:51:59 +01:00
|
|
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
from aqt.qt import *
|
|
|
|
|
2017-02-06 23:21:33 +01:00
|
|
|
class Toolbar:
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def __init__(self, mw, web):
|
|
|
|
self.mw = mw
|
|
|
|
self.web = web
|
|
|
|
self.link_handlers = {
|
|
|
|
"decks": self._deckLinkHandler,
|
|
|
|
"study": self._studyLinkHandler,
|
|
|
|
"add": self._addLinkHandler,
|
|
|
|
"browse": self._browseLinkHandler,
|
2012-12-23 04:28:06 +01:00
|
|
|
"stats": self._statsLinkHandler,
|
2012-12-21 08:51:59 +01:00
|
|
|
"sync": self._syncLinkHandler,
|
|
|
|
}
|
2017-06-22 08:56:29 +02:00
|
|
|
self.web.setFixedHeight(30)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2016-06-07 06:27:33 +02:00
|
|
|
def onLoaded(self):
|
|
|
|
self.web.evalWithCallback("$(document.body).height()", self.onHeight)
|
|
|
|
|
|
|
|
def onHeight(self, qvar):
|
|
|
|
height = int(qvar*self.web.zoomFactor())
|
|
|
|
self.web.setFixedHeight(height)
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def draw(self):
|
2016-06-07 06:27:33 +02:00
|
|
|
self.web.onBridgeCmd = self._linkHandler
|
|
|
|
self.web.onLoadFinished = self.onLoaded
|
2017-06-23 06:03:18 +02:00
|
|
|
self.web.stdHtml(self._body % self._centerLinks(), self._css)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Available links
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def _centerLinks(self):
|
|
|
|
links = [
|
|
|
|
["decks", _("Decks"), _("Shortcut key: %s") % "D"],
|
|
|
|
["add", _("Add"), _("Shortcut key: %s") % "A"],
|
|
|
|
["browse", _("Browse"), _("Shortcut key: %s") % "B"],
|
2017-06-23 06:03:18 +02:00
|
|
|
["stats", _("Stats"), _("Shortcut key: %s") % "Shift+S"],
|
|
|
|
["sync", _("Sync"), _("Shortcut key: %s") % "Y"],
|
2012-12-21 08:51:59 +01:00
|
|
|
]
|
|
|
|
return self._linkHTML(links)
|
|
|
|
|
|
|
|
def _linkHTML(self, links):
|
|
|
|
buf = ""
|
|
|
|
for ln, name, title in links:
|
2016-05-31 10:51:40 +02:00
|
|
|
buf += '''
|
2016-06-06 07:50:03 +02:00
|
|
|
<a class=hitem title="%s" href=# onclick="pycmd('%s')">%s</a>''' % (
|
2012-12-21 08:51:59 +01:00
|
|
|
title, ln, name)
|
|
|
|
buf += " "*3
|
|
|
|
return buf
|
|
|
|
|
|
|
|
# Link handling
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def _linkHandler(self, link):
|
|
|
|
if link in self.link_handlers:
|
2016-05-31 10:51:40 +02:00
|
|
|
self.link_handlers[link]()
|
|
|
|
return False
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def _deckLinkHandler(self):
|
2012-12-23 04:28:06 +01:00
|
|
|
self.mw.moveToState("deckBrowser")
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def _studyLinkHandler(self):
|
2012-12-23 04:28:06 +01:00
|
|
|
# if overview already shown, switch to review
|
|
|
|
if self.mw.state == "overview":
|
|
|
|
self.mw.col.startTimebox()
|
|
|
|
self.mw.moveToState("review")
|
|
|
|
else:
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw.onOverview()
|
|
|
|
|
|
|
|
def _addLinkHandler(self):
|
2012-12-23 04:28:06 +01:00
|
|
|
self.mw.onAddCard()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def _browseLinkHandler(self):
|
2012-12-23 04:28:06 +01:00
|
|
|
self.mw.onBrowse()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def _statsLinkHandler(self):
|
2012-12-23 04:28:06 +01:00
|
|
|
self.mw.onStats()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def _syncLinkHandler(self):
|
2012-12-23 04:28:06 +01:00
|
|
|
self.mw.onSync()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# HTML & CSS
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
_body = """
|
2016-06-07 06:27:33 +02:00
|
|
|
<center id=outer>
|
2012-12-21 08:51:59 +01:00
|
|
|
<table id=header width=100%%>
|
|
|
|
<tr>
|
2017-06-23 06:03:18 +02:00
|
|
|
<td class=tdcenter align=center>%s</td>
|
2012-12-21 08:51:59 +01:00
|
|
|
</tr></table>
|
2016-06-07 06:27:33 +02:00
|
|
|
</center>
|
2012-12-21 08:51:59 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
_css = """
|
|
|
|
#header {
|
2016-06-07 06:27:33 +02:00
|
|
|
padding:3px;
|
2012-12-21 08:51:59 +01:00
|
|
|
font-weight: bold;
|
2016-06-07 06:27:33 +02:00
|
|
|
border-bottom: 1px solid #aaa;
|
2017-06-22 10:06:40 +02:00
|
|
|
background: %s;
|
2013-05-24 05:40:41 +02:00
|
|
|
}
|
|
|
|
|
2017-06-23 06:03:18 +02:00
|
|
|
.tdcenter { white-space: nowrap; }
|
|
|
|
|
2013-05-24 05:40:41 +02:00
|
|
|
body {
|
|
|
|
margin:0; padding:0;
|
2012-12-21 08:51:59 +01:00
|
|
|
-webkit-user-select: none;
|
2016-06-07 06:27:33 +02:00
|
|
|
overflow: hidden;
|
2012-12-21 08:51:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
* { -webkit-user-drag: none; }
|
|
|
|
|
|
|
|
.hitem {
|
|
|
|
padding-right: 6px;
|
|
|
|
text-decoration: none;
|
|
|
|
color: #000;
|
|
|
|
}
|
|
|
|
.hitem:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
2016-06-07 06:27:33 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
class BottomBar(Toolbar):
|
|
|
|
|
|
|
|
_css = Toolbar._css + """
|
|
|
|
#header {
|
|
|
|
border-bottom: 0;
|
|
|
|
border-top: 1px solid #aaa;
|
|
|
|
margin-bottom: 6px;
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
_centerBody = """
|
2016-06-07 06:27:33 +02:00
|
|
|
<center id=outer><table width=100%% id=header><tr><td align=center>
|
2012-12-21 08:51:59 +01:00
|
|
|
%s</td></tr></table></center>
|
|
|
|
"""
|
|
|
|
|
|
|
|
def draw(self, buf):
|
2016-06-07 06:27:33 +02:00
|
|
|
self.web.onBridgeCmd = self._linkHandler
|
|
|
|
self.web.onLoadFinished = self.onLoaded
|
2012-12-21 08:51:59 +01:00
|
|
|
self.web.stdHtml(
|
|
|
|
self._centerBody % buf,
|
2017-06-23 05:07:59 +02:00
|
|
|
self._css)
|