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

View file

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

View file

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

View file

@ -54,13 +54,13 @@ class AnkiQt(QMainWindow):
self.hideSchemaMsg = False self.hideSchemaMsg = False
self.setupKeys() self.setupKeys()
self.setupThreads() self.setupThreads()
self.setupSystemSpecific()
self.setupMainWindow() self.setupMainWindow()
self.setupStyle() self.setupStyle()
self.setupProxy() self.setupProxy()
self.setupMenus() self.setupMenus()
self.setupProgress() self.setupProgress()
self.setupErrorHandler() self.setupErrorHandler()
self.setupSystemSpecific()
self.setupSignals() self.setupSignals()
self.setupAutoUpdate() self.setupAutoUpdate()
self.setupSchema() self.setupSchema()
@ -416,7 +416,7 @@ title="%s">%s</button>''' % (
tweb = aqt.webview.AnkiWebView() tweb = aqt.webview.AnkiWebView()
tweb.setObjectName("toolbarWeb") tweb.setObjectName("toolbarWeb")
tweb.setFocusPolicy(Qt.WheelFocus) tweb.setFocusPolicy(Qt.WheelFocus)
tweb.setFixedHeight(32) tweb.setFixedHeight(32+self.fontHeightDelta)
self.toolbar = aqt.toolbar.Toolbar(self, tweb) self.toolbar = aqt.toolbar.Toolbar(self, tweb)
self.toolbar.draw() self.toolbar.draw()
# main area # main area
@ -980,6 +980,15 @@ will be lost. Continue?"""))
########################################################################## ##########################################################################
def setupSystemSpecific(self): 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) addHook("macLoadEvent", self.onMacLoad)
if isMac: if isMac:
qt_mac_set_menubar_icons(False) qt_mac_set_menubar_icons(False)

View file

@ -125,7 +125,7 @@ class Overview(object):
counts[n] = "1000+" counts[n] = "1000+"
but = self.mw.button but = self.mw.button
if finished: 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()) self.mw.col.sched.finishedMsg())
else: else:
return ''' return '''
@ -157,10 +157,7 @@ class Overview(object):
_css = """ _css = """
.smallLink { font-size: 10px; } .smallLink { font-size: 10px; }
h3 { margin-bottom: 0; } h3 { margin-bottom: 0; }
.fin { font-size: 12px; font-weight: normal; }
td { font-size: 14px; }
.descfont { .descfont {
font-size: 12px;
padding: 1em; color: #333; padding: 1em; color: #333;
} }
.description { .description {
@ -202,7 +199,11 @@ text-align: center;
buf += """ buf += """
<button title="%s" onclick='py.link(\"%s\");'>%s</button>""" % tuple(b) <button title="%s" onclick='py.link(\"%s\");'>%s</button>""" % tuple(b)
self.bottom.draw(buf) 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) self.bottom.web.setLinkHandler(self._linkHandler)
# Today's limits # 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.db import DB
from anki.utils import isMac, isWin, intTime, checksum from anki.utils import isMac, isWin, intTime, checksum
from anki.lang import langs from anki.lang import langs
from aqt.utils import showWarning, fontForPlatform from aqt.utils import showWarning
import anki.sync import anki.sync
import aqt.forms import aqt.forms
@ -40,9 +40,6 @@ profileConf = dict(
searchHistory=[], searchHistory=[],
lastColour="#00f", lastColour="#00f",
stripHTML=True, stripHTML=True,
editFontFamily=fontForPlatform(),
editFontSize=12,
editLineSize=20,
pastePNG=False, pastePNG=False,
# not exposed in gui # not exposed in gui
deleteMedia=False, deleteMedia=False,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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