add the bridge after the page has loaded

This commit is contained in:
Damien Elmes 2011-04-10 16:49:21 +09:00
parent b8f03c298b
commit 6816163c08
2 changed files with 2 additions and 3 deletions

View file

@ -303,6 +303,7 @@ class Editor(object):
######################################################################
def bridge(self, str):
print "bridge", str
if not self.fact or not runHook:
# shutdown
return
@ -310,7 +311,6 @@ class Editor(object):
if str.startswith("blur") or str.startswith("key"):
(type, txt) = str.split(":", 1)
self.fact._fields[self.currentField] = self.mungeHTML(txt)
print "save fact", txt
if type == "blur":
if not self._keepButtons:
self.disableButtons()
@ -463,7 +463,6 @@ class Editor(object):
def saveTagsAndGroup(self):
self.fact.gid = self.mw.deck.groupId(unicode(self.group.text()))
self.fact.tags = parseTags(unicode(self.tags.text()))
print "update tags to ", self.fact.tags
self.fact.flush()
# Format buttons

View file

@ -86,7 +86,6 @@ class AnkiWebView(QWebView):
if loadCB:
self._loadFinishedCB = loadCB
QWebView.setHtml(self, html)
self.page().mainFrame().addToJavaScriptWindowObject("py", self._bridge)
def stdHtml(self, body, css="", bodyClass="", loadCB=None):
self.setHtml("""
<html><head><style>%s</style>
@ -107,6 +106,7 @@ class AnkiWebView(QWebView):
def _linkHandler(self, url):
self.linkHandler(unicode(url.toString()))
def _loadFinished(self):
self.page().mainFrame().addToJavaScriptWindowObject("py", self._bridge)
if self._loadFinishedCB:
self._loadFinishedCB(self)
self._loadFinishedCB = None