field fonts

This commit is contained in:
Damien Elmes 2011-04-06 18:30:59 +09:00
parent b0d0faecf5
commit 5b7daf5060

View file

@ -16,7 +16,6 @@ import aqt
import anki.js import anki.js
# todo: # todo:
# - tags/groups
# if field.fieldModel.features: # if field.fieldModel.features:
# w.setLayoutDirection(Qt.RightToLeft) # w.setLayoutDirection(Qt.RightToLeft)
# else: # else:
@ -151,6 +150,13 @@ function setBackgrounds(cols) {
} }
} }
function setFonts(fonts) {
for (var i=0; i<fonts.length; i++) {
$("#f"+i).css("font-family", fonts[i][0]);
$("#f"+i).css("font-size", fonts[i][1]);
}
}
$(function () { $(function () {
// ignore drops outside the editable area // ignore drops outside the editable area
document.body.ondragover = function () { document.body.ondragover = function () {
@ -292,11 +298,13 @@ class Editor(object):
def onCardLayout(self): def onCardLayout(self):
from aqt.clayout import CardLayout from aqt.clayout import CardLayout
self.saveNow()
if self.card: if self.card:
type = 1; ord = self.card.ord type = 1; ord = self.card.ord
else: else:
type = 0; ord = 0 type = 0; ord = 0
CardLayout(self.mw, self.fact, type=type, ord=ord, parent=self.widget) CardLayout(self.mw, self.fact, type=type, ord=ord, parent=self.widget)
self.loadFact()
# JS->Python bridge # JS->Python bridge
###################################################################### ######################################################################
@ -363,9 +371,15 @@ class Editor(object):
return return
self.web.eval("setFields(%s, %d);" % ( self.web.eval("setFields(%s, %d);" % (
simplejson.dumps(self.fact.items()), field)) simplejson.dumps(self.fact.items()), field))
self.web.eval("setFonts(%s);" % (
simplejson.dumps(self.fonts())))
self.checkValid() self.checkValid()
self.widget.show() self.widget.show()
def fonts(self):
return [(f['font'], f['esize'])
for f in self.fact.model().fields]
def refresh(self): def refresh(self):
if self.fact: if self.fact:
self.fact.load() self.fact.load()
@ -711,8 +725,6 @@ class EditorWebView(AnkiWebView):
self.__tmpDir = None self.__tmpDir = None
self.errtxt = _("An error occured while opening %s") self.errtxt = _("An error occured while opening %s")
self.strip = self.editor.mw.config['stripHTML'] self.strip = self.editor.mw.config['stripHTML']
# if sys.platform.startswith("win32"):
# self._ownLayout = None
def keyPressEvent(self, evt): def keyPressEvent(self, evt):
self._curKey = True self._curKey = True