overhaul font handling

- set the default webview font to the system font
- remove explicit font size settings in favour of the default
- remove card list size customization in favour of the default
This commit is contained in:
Damien Elmes 2012-05-26 20:28:30 +09:00
parent a6c9c8203c
commit 064803bce7
13 changed files with 39 additions and 82 deletions

View file

@ -10,7 +10,7 @@ import anki, anki.utils, aqt.forms
from anki.utils import fmtTimeSpan, ids2str, stripHTMLMedia, isWin, intTime
from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
saveHeader, restoreHeader, saveState, restoreState, applyStyles, getTag, \
showInfo, askUser, tooltip, openHelp, fontForPlatform, showWarning
showInfo, askUser, tooltip, openHelp, showWarning
from anki.errors import *
from anki.db import *
from anki.hooks import runHook, addHook, remHook
@ -345,7 +345,7 @@ class Browser(QMainWindow):
def setupToolbar(self):
self.toolbarWeb = AnkiWebView()
self.toolbarWeb.setFixedHeight(32)
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()
@ -358,7 +358,6 @@ class Browser(QMainWindow):
c(f.actionCram, s, self.cram)
c(f.actionChangeModel, s, self.onChangeModel)
# edit
c(f.actionOptions, s, self.onOptions)
c(f.actionUndo, s, self.mw.onUndo)
c(f.actionInvertSelection, s, self.invertSelection)
c(f.actionSelectNotes, s, self.selectNotes)
@ -389,11 +388,8 @@ class Browser(QMainWindow):
runHook('browser.setupMenus', self)
def updateFont(self):
self.form.tableView.setFont(QFont(
self.mw.pm.profile['editFontFamily'],
self.mw.pm.profile['editFontSize']))
self.form.tableView.verticalHeader().setDefaultSectionSize(
self.mw.pm.profile['editLineSize'])
max(16, self.mw.fontHeight * 1.4))
def closeEvent(self, evt):
saveSplitter(self.form.splitter_2, "editor2")
@ -653,9 +649,6 @@ by clicking on one on the left."""))
p = QPalette()
p.setColor(QPalette.Base, QColor("#d6dde0"))
self.form.tree.setPalette(p)
f = QFont()
f.setFamily(fontForPlatform())
self.form.tree.setFont(f)
self.buildTree()
def buildTree(self):
@ -779,7 +772,6 @@ by clicking on one on the left."""))
from anki.stats import CardStats
cs = CardStats(self.col, self.card)
rep = cs.report()
rep = "<style>table * { font-size: 12px; }</style>" + rep
m = self.card.model()
rep = """
<div style='width: 400px; margin: 0 auto 0;
@ -847,9 +839,9 @@ border: 1px solid #000; padding: 3px; '>%s</div>""" % rep
cs.time(taken)) + "</tr>"
s += "</table>"
if cnt != self.card.reps:
s += '<div style="font-size: 12px;">' + _("""\
s += _("""\
Note: Some of the history is missing. For more information, \
please see the browser documentation.""") + "</div>"
please see the browser documentation.""")
return s
# Menu helpers
@ -1092,30 +1084,6 @@ update cards set usn=?, mod=?, did=? where odid=0 and id in """ + ids2str(
if on:
self.form.actionUndo.setText(self.mw.form.actionUndo.text())
# Options
######################################################################
def onOptions(self):
d = QDialog(self)
frm = aqt.forms.browseropts.Ui_Dialog()
frm.setupUi(d)
frm.fontCombo.setCurrentFont(QFont(
self.mw.pm.profile['editFontFamily']))
frm.fontSize.setValue(self.mw.pm.profile['editFontSize'])
frm.lineSize.setValue(self.mw.pm.profile['editLineSize'])
# disabled for now
frm.fullSearch.setShown(False)
frm.fullSearch.setChecked(self.mw.pm.profile['fullSearch'])
if d.exec_():
self.mw.pm.profile['editFontFamily'] = (
unicode(frm.fontCombo.currentFont().family()))
self.mw.pm.profile['editFontSize'] = (
int(frm.fontSize.value()))
self.mw.pm.profile['editLineSize'] = (
int(frm.lineSize.value()))
self.mw.pm.profile['fullSearch'] = frm.fullSearch.isChecked()
self.updateFont()
# Edit: replacing
######################################################################

View file

@ -70,7 +70,6 @@ or importing text files."""))
_dragIndicatorBorderWidth = "1px"
_css = """
tr { font-size: 12px; }
a.deck { color: #000; text-decoration: none; min-width: 5em;
display:inline-block; }
a.deck:hover { text-decoration: underline; }
@ -78,7 +77,6 @@ tr.deck td { border-bottom: %(width)s solid #e7e7e7; }
tr.top-level-drag-row td { border-bottom: %(width)s solid transparent; }
td { white-space: nowrap; }
tr.drag-hover td { border-bottom: %(width)s solid #aaa; }
.extra { font-size: 90%%; }
body { margin: 1em; -webkit-user-select: none; }
.current { background-color: #e7e7e7; }
.decktd { min-width: 15em; }
@ -265,7 +263,11 @@ body { margin: 1em; -webkit-user-select: none; }
buf += """
<button title='%s' onclick='py.link(\"%s\");'>%s</button>""" % tuple(b)
self.bottom.draw(buf)
self.bottom.web.setFixedHeight(isMac and 28 or 36)
if isMac:
size = 28
else:
size = 36 + self.mw.fontHeightDelta*3
self.bottom.web.setFixedHeight(size)
self.bottom.web.setLinkHandler(self._linkHandler)
def _onShared(self):

View file

@ -10,7 +10,7 @@ from anki.hooks import runHook, runFilter
from aqt.sound import getAudio
from aqt.webview import AnkiWebView
from aqt.utils import shortcut, showInfo, showWarning, getBase, getFile, \
openHelp, fontForPlatform
openHelp
import aqt
import anki.js
from BeautifulSoup import BeautifulSoup
@ -37,9 +37,7 @@ _html = """
clear: both;
visibility: hidden;
}
.fname { font-size: 10px; vertical-align: middle; padding: 0;
font-family: "%s"; }
#dupes { font-size: 12px; }
.fname { vertical-align: middle; padding: 0; }
img { max-width: 90%%; }
body { margin: 5px; }
</style><script>
@ -538,7 +536,7 @@ class Editor(object):
# change timer
if self.note:
self.web.setHtml(_html % (
getBase(self.mw.col), fontForPlatform(), anki.js.jquery,
getBase(self.mw.col), anki.js.jquery,
_("Show Duplicates")), loadCB=self._loadFinished)
self.updateTags()
self.updateKeyboard()

View file

@ -54,13 +54,13 @@ class AnkiQt(QMainWindow):
self.hideSchemaMsg = False
self.setupKeys()
self.setupThreads()
self.setupSystemSpecific()
self.setupMainWindow()
self.setupStyle()
self.setupProxy()
self.setupMenus()
self.setupProgress()
self.setupErrorHandler()
self.setupSystemSpecific()
self.setupSignals()
self.setupAutoUpdate()
self.setupSchema()
@ -416,7 +416,7 @@ title="%s">%s</button>''' % (
tweb = aqt.webview.AnkiWebView()
tweb.setObjectName("toolbarWeb")
tweb.setFocusPolicy(Qt.WheelFocus)
tweb.setFixedHeight(32)
tweb.setFixedHeight(32+self.fontHeightDelta)
self.toolbar = aqt.toolbar.Toolbar(self, tweb)
self.toolbar.draw()
# main area
@ -980,6 +980,15 @@ will be lost. Continue?"""))
##########################################################################
def setupSystemSpecific(self):
# use system font for webviews
f = QFontInfo(self.font())
ws = QWebSettings.globalSettings()
self.fontHeight = f.pixelSize()
self.fontFamily = f.family()
self.fontHeightDelta = max(0, self.fontHeight - 13)
ws.setFontFamily(QWebSettings.StandardFont, self.fontFamily)
ws.setFontSize(QWebSettings.DefaultFontSize, self.fontHeight)
# mac tweaks
addHook("macLoadEvent", self.onMacLoad)
if isMac:
qt_mac_set_menubar_icons(False)

View file

@ -125,7 +125,7 @@ class Overview(object):
counts[n] = "1000+"
but = self.mw.button
if finished:
return '<div class=fin style="white-space: pre-wrap;">%s</div>' % (
return '<div style="white-space: pre-wrap;">%s</div>' % (
self.mw.col.sched.finishedMsg())
else:
return '''
@ -157,10 +157,7 @@ class Overview(object):
_css = """
.smallLink { font-size: 10px; }
h3 { margin-bottom: 0; }
.fin { font-size: 12px; font-weight: normal; }
td { font-size: 14px; }
.descfont {
font-size: 12px;
padding: 1em; color: #333;
}
.description {
@ -202,7 +199,11 @@ text-align: center;
buf += """
<button title="%s" onclick='py.link(\"%s\");'>%s</button>""" % tuple(b)
self.bottom.draw(buf)
self.bottom.web.setFixedHeight(isMac and 28 or 36)
if isMac:
size = 28
else:
size = 36 + self.mw.fontHeightDelta*3
self.bottom.web.setFixedHeight(size)
self.bottom.web.setLinkHandler(self._linkHandler)
# Today's limits

View file

@ -11,7 +11,7 @@ import os, sys, time, random, cPickle, shutil, locale, re, atexit, urllib
from anki.db import DB
from anki.utils import isMac, isWin, intTime, checksum
from anki.lang import langs
from aqt.utils import showWarning, fontForPlatform
from aqt.utils import showWarning
import anki.sync
import aqt.forms
@ -40,9 +40,6 @@ profileConf = dict(
searchHistory=[],
lastColour="#00f",
stripHTML=True,
editFontFamily=fontForPlatform(),
editFontSize=12,
editLineSize=20,
pastePNG=False,
# not exposed in gui
deleteMedia=False,

View file

@ -9,7 +9,7 @@ sip.setapi('QVariant', 2)
sip.setapi('QUrl', 2)
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage, QWebView
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
from PyQt4 import pyqtconfig
def debug():

View file

@ -37,7 +37,7 @@ class Reviewer(object):
if isMac:
self.bottom.web.setFixedHeight(46)
else:
self.bottom.web.setFixedHeight(52)
self.bottom.web.setFixedHeight(52+self.mw.fontHeightDelta*4)
self.bottom.web.setLinkHandler(self._linkHandler)
self._reps = None
self.nextCard()
@ -458,9 +458,8 @@ padding: 0px;
padding-left: 5px; padding-right: 5px;
}
button {
min-width: 60px;
min-width: 60px; white-space: nowrap;
}
td { font-weight: bold; font-size: 12px; }
.hitem { margin-top: 2px; }
.stat { padding-top: 5px; }
.stat2 { padding-top: 3px; font-weight: normal; }

View file

@ -5,8 +5,7 @@
from aqt.qt import *
import os
from aqt.webview import AnkiWebView
from aqt.utils import saveGeom, restoreGeom, maybeHideClose, openFolder, \
fontForPlatform
from aqt.utils import saveGeom, restoreGeom, maybeHideClose, openFolder
from anki.utils import namedtmp
from anki.hooks import addHook
import aqt
@ -80,6 +79,5 @@ class DeckStats(QDialog):
stats = self.mw.col.stats()
stats.wholeCollection = self.wholeCollection
self.report = stats.report(type=self.period)
css = '<style>body { font-family: "%s"; } </style>' % fontForPlatform()
self.form.web.setHtml(css + self.report)
self.form.web.setHtml(self.report)
self.mw.progress.finish()

View file

@ -96,7 +96,6 @@ class Toolbar(object):
_css = """
#header {
font-size: 12px;
margin:0;
margin-top: 4px;
font-weight: bold;
@ -133,7 +132,6 @@ border-top: 1px solid #aaa;
margin-bottom: 6px;
margin-top: 0;
}
td { font-size: 12px; }
"""
_centerBody = """

View file

@ -353,11 +353,6 @@ def maybeHideClose(bbox):
if b:
bbox.removeButton(b)
def fontForPlatform():
if isMac:
return "Lucida Grande"
return "Arial"
# Tooltips
######################################################################

View file

@ -4,7 +4,7 @@
import sys
from aqt.qt import *
from aqt.utils import fontForPlatform, openLink
from aqt.utils import openLink
from anki.utils import isMac, isWin
import anki.js
QtConfig = pyqtconfig.Configuration()
@ -108,10 +108,9 @@ class AnkiWebView(QWebView):
if isMac:
button = "font-weight: bold; height: 24px;"
else:
button = "font-weight: normal; font-size: 12px;"
button = "font-weight: normal;"
self.setHtml("""
<html><head><style>
body { font-family: "%s"; }
button {
%s
}
@ -121,7 +120,7 @@ button {
</head>
<body class="%s">%s</body></html>""" % (
fontForPlatform(), button, css, js or anki.js.jquery+anki.js.browserSel,
button, css, js or anki.js.jquery+anki.js.browserSel,
head, bodyClass, body), loadCB)
def setBridge(self, bridge):

View file

@ -248,8 +248,6 @@
<addaction name="separator"/>
<addaction name="actionFindDuplicates"/>
<addaction name="actionFindReplace"/>
<addaction name="separator"/>
<addaction name="actionOptions"/>
</widget>
<widget class="QMenu" name="menuJump">
<property name="title">
@ -410,11 +408,6 @@
<string>&amp;Cram...</string>
</property>
</action>
<action name="actionOptions">
<property name="text">
<string>Browser Options...</string>
</property>
</action>
<action name="actionTags">
<property name="icon">
<iconset resource="icons.qrc">