mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
resize toolbars to fit content
This commit is contained in:
parent
d7339d9a27
commit
4e2bd3f739
7 changed files with 49 additions and 54 deletions
|
@ -375,7 +375,6 @@ class Browser(QMainWindow):
|
|||
|
||||
def setupToolbar(self):
|
||||
self.toolbarWeb = AnkiWebView()
|
||||
self.toolbarWeb.setFixedHeight(32 + self.mw.fontHeightDelta)
|
||||
self.toolbar = BrowserToolbar(self.mw, self.toolbarWeb, self)
|
||||
self.form.verticalLayout_3.insertWidget(0, self.toolbarWeb)
|
||||
self.toolbar.draw()
|
||||
|
@ -1717,12 +1716,10 @@ class BrowserToolbar(Toolbar):
|
|||
"Bulk Remove Tags (Ctrl+Alt+T)")))
|
||||
right += borderImg("delete", "delete16", False, _("Delete"))
|
||||
right += "</div>"
|
||||
# fixme
|
||||
#self.web.page().currentFrame().setScrollBarPolicy(
|
||||
# Qt.Horizontal, Qt.ScrollBarAlwaysOff)
|
||||
self.web.onBridgeCmd = self._linkHandler
|
||||
self.web.onLoadFinished = self.onLoaded
|
||||
self.web.stdHtml(self._body % (
|
||||
"", #<span style='display:inline-block; width: 100px;'></span>",
|
||||
#self._centerLinks(),
|
||||
"",
|
||||
right, ""), self._css + """
|
||||
#header { font-weight: normal; }
|
||||
a { margin-right: 1em; }
|
||||
|
|
|
@ -349,12 +349,6 @@ where id > ?""", (self.mw.col.sched.dayCutoff-86400)*1000)
|
|||
buf += """
|
||||
<button title='%s' onclick='pycmd(\"%s\");'>%s</button>""" % tuple(b)
|
||||
self.bottom.draw(buf)
|
||||
if isMac:
|
||||
size = 28
|
||||
else:
|
||||
size = 36 + self.mw.fontHeightDelta*3
|
||||
self.bottom.web.setFixedHeight(size)
|
||||
self.bottom.web.resetHandlers()
|
||||
self.bottom.web.onBridgeCmd = self._linkHandler
|
||||
|
||||
def _onShared(self):
|
||||
|
|
|
@ -502,7 +502,6 @@ title="%s" %s>%s</button>''' % (
|
|||
tweb = aqt.webview.AnkiWebView()
|
||||
tweb.setObjectName("toolbarWeb")
|
||||
tweb.setFocusPolicy(Qt.WheelFocus)
|
||||
tweb.setFixedHeight(32+self.fontHeightDelta)
|
||||
self.toolbar = aqt.toolbar.Toolbar(self, tweb)
|
||||
self.toolbar.draw()
|
||||
# main area
|
||||
|
@ -512,8 +511,6 @@ title="%s" %s>%s</button>''' % (
|
|||
self.web.setMinimumWidth(400)
|
||||
# bottom area
|
||||
sweb = self.bottomWeb = aqt.webview.AnkiWebView()
|
||||
#sweb.hide()
|
||||
sweb.setFixedHeight(100)
|
||||
sweb.setObjectName("bottomWeb")
|
||||
sweb.setFocusPolicy(Qt.WheelFocus)
|
||||
# add in a layout
|
||||
|
|
|
@ -201,11 +201,6 @@ text-align: center;
|
|||
buf += """
|
||||
<button title="%s" onclick='pycmd("%s")'>%s</button>""" % tuple(b)
|
||||
self.bottom.draw(buf)
|
||||
if isMac:
|
||||
size = 28
|
||||
else:
|
||||
size = 36 + self.mw.fontHeightDelta*3
|
||||
self.bottom.web.setFixedHeight(size)
|
||||
self.bottom.web.onBridgeCmd = self._linkHandler
|
||||
|
||||
# Studying more
|
||||
|
|
|
@ -44,11 +44,6 @@ class Reviewer(object):
|
|||
self.web.resetHandlers()
|
||||
self.mw.keyHandler = self._keyHandler
|
||||
self.web.onBridgeCmd = self._linkHandler
|
||||
if isMac:
|
||||
self.bottom.web.setFixedHeight(46)
|
||||
else:
|
||||
self.bottom.web.setFixedHeight(52+self.mw.fontHeightDelta*4)
|
||||
self.bottom.web.resetHandlers()
|
||||
self.bottom.web.onBridgeCmd = self._linkHandler
|
||||
self._reps = None
|
||||
self.nextCard()
|
||||
|
@ -182,7 +177,7 @@ function _typeAnsPress() {
|
|||
self.web.stdHtml(self._revHtml, self._styles(), head=base)
|
||||
# show answer / ease buttons
|
||||
self.bottom.web.show()
|
||||
self.bottom.web.onLoadFinished = self._showAnswerButton
|
||||
self.bottom.web.onLoadFinished = self._onBottomLoadFinished
|
||||
self.bottom.web.stdHtml(
|
||||
self._bottomHTML(),
|
||||
self.bottom._css + self._bottomCSS)
|
||||
|
@ -501,13 +496,7 @@ Please run Tools>Empty Cards""")
|
|||
|
||||
_bottomCSS = """
|
||||
body {
|
||||
background: -webkit-gradient(linear, left top, left bottom,
|
||||
from(#fff), to(#ddd));
|
||||
border-bottom: 0;
|
||||
border-top: 1px solid #aaa;
|
||||
margin: 0;
|
||||
padding: 0px;
|
||||
padding-left: 5px; padding-right: 5px;
|
||||
margin: 0; padding: 0;
|
||||
}
|
||||
button {
|
||||
min-width: 60px; white-space: nowrap;
|
||||
|
@ -519,11 +508,21 @@ min-width: 60px; white-space: nowrap;
|
|||
.nobold { font-weight: normal; display: inline-block; padding-top: 4px; }
|
||||
.spacer { height: 18px; }
|
||||
.spacer2 { height: 16px; }
|
||||
#outer {
|
||||
border-top: 1px solid #aaa;
|
||||
background: -webkit-gradient(linear, left top, left bottom,
|
||||
from(#fff), to(#ddd));
|
||||
}
|
||||
#innertable {
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
def _bottomHTML(self):
|
||||
return """
|
||||
<table width=100%% cellspacing=0 cellpadding=0>
|
||||
<center id=outer>
|
||||
<table id=innertable width=100%% cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td align=left width=50 valign=top class=stat>
|
||||
<br>
|
||||
|
@ -536,6 +535,7 @@ min-width: 60px; white-space: nowrap;
|
|||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<script>
|
||||
var time = %(time)d;
|
||||
var maxTime = 0;
|
||||
|
@ -584,6 +584,9 @@ function showAnswer(txt) {
|
|||
downArrow=downArrow(),
|
||||
time=self.card.timeTaken() // 1000)
|
||||
|
||||
def _onBottomLoadFinished(self):
|
||||
self._showAnswerButton()
|
||||
|
||||
def _showAnswerButton(self):
|
||||
self._bottomReady = True
|
||||
if not self.typeCorrect:
|
||||
|
@ -600,6 +603,7 @@ function showAnswer(txt) {
|
|||
maxTime = 0
|
||||
self.bottom.web.eval("showQuestion(%s,%d);" % (
|
||||
json.dumps(middle), maxTime))
|
||||
self.bottom.onLoaded()
|
||||
|
||||
def _showEaseButtons(self):
|
||||
self.bottom.web.setFocus()
|
||||
|
|
|
@ -9,8 +9,6 @@ class Toolbar(object):
|
|||
def __init__(self, mw, web):
|
||||
self.mw = mw
|
||||
self.web = web
|
||||
self.web.resetHandlers()
|
||||
self.web.onBridgeCmd = self._linkHandler
|
||||
self.link_handlers = {
|
||||
"decks": self._deckLinkHandler,
|
||||
"study": self._studyLinkHandler,
|
||||
|
@ -20,7 +18,16 @@ class Toolbar(object):
|
|||
"sync": self._syncLinkHandler,
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
def draw(self):
|
||||
self.web.onBridgeCmd = self._linkHandler
|
||||
self.web.onLoadFinished = self.onLoaded
|
||||
self.web.stdHtml(self._body % (
|
||||
# may want a context menu here in the future
|
||||
' '*20,
|
||||
|
@ -99,34 +106,29 @@ class Toolbar(object):
|
|||
######################################################################
|
||||
|
||||
_body = """
|
||||
<center id=outer>
|
||||
<table id=header width=100%%>
|
||||
<tr>
|
||||
<td width=16%% align=left>%s</td>
|
||||
<td align=center>%s</td>
|
||||
<td width=15%% align=right>%s</td>
|
||||
<td width=15%% valign=middle align=right>%s</td>
|
||||
</tr></table>
|
||||
</center>
|
||||
"""
|
||||
|
||||
_css = """
|
||||
#header {
|
||||
margin:0;
|
||||
margin-top: 4px;
|
||||
padding:3px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
html {
|
||||
height: 100%;
|
||||
border-bottom: 1px solid #aaa;
|
||||
background: -webkit-gradient(linear, left top, left bottom,
|
||||
from(#ddd), to(#fff));
|
||||
margin:0; padding:0;
|
||||
}
|
||||
|
||||
body {
|
||||
margin:0; padding:0;
|
||||
position:absolute;
|
||||
top:0;left:0;right:0;bottom:0;
|
||||
-webkit-user-select: none;
|
||||
border-bottom: 1px solid #aaa;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
* { -webkit-user-drag: none; }
|
||||
|
@ -139,6 +141,7 @@ color: #000;
|
|||
.hitem:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
class BottomBar(Toolbar):
|
||||
|
@ -155,12 +158,13 @@ margin-top: 0;
|
|||
"""
|
||||
|
||||
_centerBody = """
|
||||
<center><table width=100%% height=100%% id=header><tr><td align=center>
|
||||
<center id=outer><table width=100%% id=header><tr><td align=center>
|
||||
%s</td></tr></table></center>
|
||||
"""
|
||||
|
||||
def draw(self, buf):
|
||||
self.web.show()
|
||||
self.web.onBridgeCmd = self._linkHandler
|
||||
self.web.onLoadFinished = self.onLoaded
|
||||
self.web.stdHtml(
|
||||
self._centerBody % buf,
|
||||
self._css)
|
||||
|
|
|
@ -134,16 +134,17 @@ class AnkiWebView(QWebEngineView):
|
|||
if oldFocus:
|
||||
oldFocus.setFocus()
|
||||
|
||||
def zoomFactor(self):
|
||||
screen = QApplication.desktop().screen()
|
||||
dpi = screen.logicalDpiX()
|
||||
return max(1, dpi / 96.0)
|
||||
|
||||
def stdHtml(self, body, css="", bodyClass="", js=None, head=""):
|
||||
if isMac:
|
||||
button = "font-weight: bold; height: 24px;"
|
||||
else:
|
||||
button = "font-weight: normal;"
|
||||
|
||||
screen = QApplication.desktop().screen()
|
||||
dpi = screen.logicalDpiX()
|
||||
zoomFactor = max(1, dpi / 96.0)
|
||||
|
||||
self.setHtml("""
|
||||
<!doctype html>
|
||||
<html><head><style>
|
||||
|
@ -159,7 +160,7 @@ button {
|
|||
|
||||
</head>
|
||||
<body class="%s">%s</body></html>""" % (
|
||||
zoomFactor, button, css, js or anki.js.jquery+anki.js.browserSel,
|
||||
self.zoomFactor(), button, css, js or anki.js.jquery+anki.js.browserSel,
|
||||
head, bodyClass, body))
|
||||
|
||||
def setCanFocus(self, canFocus=False):
|
||||
|
@ -172,6 +173,9 @@ button {
|
|||
def eval(self, js):
|
||||
self.page().runJavaScript(js)
|
||||
|
||||
def evalWithCallback(self, js, cb):
|
||||
self.page().runJavaScript(js, cb)
|
||||
|
||||
def _openLinksExternally(self, url):
|
||||
openLink(url)
|
||||
|
||||
|
|
Loading…
Reference in a new issue