use libanki json

This commit is contained in:
Damien Elmes 2012-04-28 17:58:28 +09:00
parent d66931359c
commit faf4e396f8
8 changed files with 21 additions and 22 deletions

3
README
View file

@ -3,9 +3,8 @@ Anki
Prerequisites for Linux/FreeBSD/etc:
- Python 2.5+
- Python 2.6 or 2.7 (not 3.0+)
- Python-Qt/PyQt 4.6+
- SimpleJSON 1.7.3+
- BeautifulSoup 3.2+
- Httplib2 0.7+

View file

@ -3,7 +3,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import *
import aqt, simplejson
import aqt
from anki.utils import ids2str
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText, askUser, \
tooltip

View file

@ -3,7 +3,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import *
import aqt, simplejson
import aqt
from anki.utils import ids2str
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText
from operator import itemgetter

View file

@ -3,8 +3,8 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import *
import re, os, sys, urllib2, ctypes, simplejson, traceback, urllib2
from anki.utils import stripHTML, isWin, isMac, namedtmp
import re, os, sys, urllib2, ctypes, traceback, urllib2
from anki.utils import stripHTML, isWin, isMac, namedtmp, json
from anki.sound import play
from anki.hooks import runHook, runFilter
from aqt.sound import getAudio
@ -502,7 +502,7 @@ class Editor(object):
# state buttons changed?
elif str.startswith("state"):
(cmd, txt) = str.split(":", 1)
r = simplejson.loads(txt)
r = json.loads(txt)
self._buttons['text_bold'].setChecked(r['bold'])
self._buttons['text_italic'].setChecked(r['italic'])
self._buttons['text_under'].setChecked(r['under'])
@ -555,9 +555,9 @@ class Editor(object):
for fld, val in self.note.items():
data.append((fld, self.mw.col.media.escapeImages(val)))
self.web.eval("setFields(%s, %d);" % (
simplejson.dumps(data), field))
json.dumps(data), field))
self.web.eval("setFonts(%s);" % (
simplejson.dumps(self.fonts())))
json.dumps(self.fonts())))
self.checkValid()
self.widget.show()
if self.stealFocus:
@ -594,7 +594,7 @@ class Editor(object):
self.web.eval("showDupes();")
else:
self.web.eval("hideDupes();")
self.web.eval("setBackgrounds(%s);" % simplejson.dumps(cols))
self.web.eval("setBackgrounds(%s);" % json.dumps(cols))
def showDupes(self):
contents = self.note.fields[0]
@ -809,7 +809,7 @@ class Editor(object):
def addMedia(self, path, canDelete=False):
html = self._addMedia(path, canDelete)
self._eval("setFormat('inserthtml', %s);" % simplejson.dumps(html))
self._eval("setFormat('inserthtml', %s);" % json.dumps(html))
def _addMedia(self, path, canDelete=False):
"Add to media folder and return basename."

View file

@ -2,7 +2,6 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import simplejson
from aqt.qt import *
from anki.consts import NEW_CARDS_RANDOM, dynOrderLabels
from anki.hooks import addHook

View file

@ -2,11 +2,11 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import time, os, stat, shutil, difflib, simplejson, re, cgi
import time, os, stat, shutil, difflib, re, cgi
import unicodedata as ucd
import HTMLParser
from aqt.qt import *
from anki.utils import fmtTimeSpan, stripHTML, isMac
from anki.utils import fmtTimeSpan, stripHTML, isMac, json
from anki.hooks import addHook, runHook, runFilter
from anki.sound import playFromText, clearAudioQueue, hasSound, play
from aqt.utils import mungeQA, getBase, shortcut, openLink, tooltip
@ -172,7 +172,7 @@ function _typeAnsPress() {
playFromText(q)
# render & update bottom
q = self._mungeQA(q)
self.web.eval("_updateQA(%s, false);" % simplejson.dumps(q))
self.web.eval("_updateQA(%s, false);" % json.dumps(q))
self._toggleStar()
if self._bottomReady:
self._showAnswerButton()
@ -187,7 +187,7 @@ function _typeAnsPress() {
self.card.odid or self.card.did)['autoplay']
def _toggleStar(self):
self.web.eval("_toggleStar(%s);" % simplejson.dumps(
self.web.eval("_toggleStar(%s);" % json.dumps(
self.card.note().hasTag("marked")))
# Showing the answer
@ -205,7 +205,7 @@ function _typeAnsPress() {
playFromText(a)
# render and update bottom
a = self._mungeQA(a)
self.web.eval("_updateQA(%s, true);" % simplejson.dumps(a))
self.web.eval("_updateQA(%s, true);" % json.dumps(a))
self._showEaseButtons()
# user hook
runHook('showAnswer')
@ -528,12 +528,12 @@ function showAnswer(txt) {
else:
maxTime = 0
self.bottom.web.eval("showQuestion(%s,%d);" % (
simplejson.dumps(middle), maxTime))
json.dumps(middle), maxTime))
def _showEaseButtons(self):
self.bottom.web.setFocus()
middle = self._answerButtons()
self.bottom.web.eval("showAnswer(%s);" % simplejson.dumps(middle))
self.bottom.web.eval("showAnswer(%s);" % json.dumps(middle))
def _remaining(self):
if not self.mw.col.conf['dueCounts']:

View file

@ -3,7 +3,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import *
import aqt, simplejson
import aqt
from anki.utils import ids2str
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText
from operator import itemgetter

View file

@ -5,8 +5,9 @@ from aqt.qt import *
import urllib, urllib2, os, sys, time, httplib
import anki, anki.utils, anki.lang, anki.stats
import aqt
import simplejson, platform
import platform
from aqt.utils import openLink
from anki.utils import json
baseUrl = "http://ankiweb.net/update/"
#baseUrl = "http://localhost:8001/update/"
@ -38,7 +39,7 @@ class LatestVersionFinder(QThread):
resp = f.read()
if not resp:
return
resp = simplejson.loads(resp)
resp = json.loads(resp)
except:
# behind proxy, corrupt message, etc
return