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

View file

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