Hi all,

I try to use mozembed.load_url("javascript:js_function()") to call
Javascript.
When call times is over 370 in my computer, it doesn't work.
Here is test program.
1. use a thread to call javascript.
2. each time it calls javascript and pass call counts.
3. print counts in console and webpage.

[result]
Webpage shows 370 counts but console continues showing follow
counts...
please help.

thanks,
Yojay Li

====test.py====

#!/usr/bin/python
import gtk
import gtkmozembed
import os
import gobject
import threading
import time

class CallThread ( threading.Thread ):
        def __init__ ( self, target):
                self.target = target
                threading.Thread.__init__ ( self )
        def run(self):
                while True:
                        time.sleep(0.01)
                        self.target.call()

class MozJs:
        def call(self):
                self.count = self.count+1
                gobject.idle_add(self.idle_call_js ,self.count)

        def idle_call_js(self,count):
                self.moz.load_url("javascript:callFromPython("+str(count)+")");
                print(count)

        def net_stop_cb(self, widget, data=None):
                self.thread = CallThread(self)
                self.thread.setDaemon(True)
                self.thread.start()

        def __init__(self):
                self.moz = gtkmozembed.MozEmbed()
                self.moz.connect("net-stop", self.net_stop_cb)

                self.window = gtk.Window()
                self.window.connect("destroy", gtk.main_quit)
                self.window.add(self.moz)
                self.window.set_default_size(200,200)
                self.window.show_all()

                self.url = "file://"+os.getcwd()+"/index.html"
                self.moz.load_url(self.url)
                self.count = 0

def main():
        gobject.threads_init()
        gtk.main()
        return 0

if __name__ == "__main__":
        MozJs()
        main()
====end of test.py====


====index.html====

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
  <meta http-equiv="Content-Script-Type" content="text/javascript">
  <script>
        function callFromPython(count){
                document.getElementById("txt").innerHTML = count;
        }
  </script>
</head>
<body>
        <Div id="txt">Count</Div>
</body>
</html>

====index.html====
_______________________________________________
dev-embedding mailing list
dev-embedding@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to