WebBrowser/Tools/Scripts.py

changeset 6140
c20e2d414d0d
parent 6135
12e48d27f1d7
child 6142
304a469455c8
equal deleted inserted replaced
6139:d24997c47244 6140:c20e2d414d0d
17 from PyQt5.QtCore import QUrlQuery, QUrl 17 from PyQt5.QtCore import QUrlQuery, QUrl
18 18
19 from .WebBrowserTools import readAllFileContents 19 from .WebBrowserTools import readAllFileContents
20 20
21 21
22 def setupWebChannel(): 22 def setupWebChannel(worldId):
23 """ 23 """
24 Function generating a script to setup the web channel. 24 Function generating a script to setup the web channel.
25 25
26 @param worlId world ID for which to setup the channel
27 @type int
26 @return script to setup the web channel 28 @return script to setup the web channel
27 @rtype str 29 @rtype str
28 """ 30 """
29 source = """ 31 source = """
30 (function() {{ 32 // ==UserScript==
31 {0} 33 {0}
34 // ==/UserScript==
35
36 (function() {{
37 {1}
32 38
33 function registerExternal(e) {{ 39 function registerExternal(e) {{
34 window.external = e; 40 window.external = e;
35 if (window.external) {{ 41 if (window.external) {{
36 var event = document.createEvent('Event'); 42 var event = document.createEvent('Event');
69 }} 75 }}
70 registerWebChannel(); 76 registerWebChannel();
71 77
72 }})()""" 78 }})()"""
73 79
74 return source.format(readAllFileContents(":/javascript/qwebchannel.js")) 80 from WebBrowser.WebBrowserPage import WebBrowserPage
81 if worldId == WebBrowserPage.SafeJsWorld:
82 match = "// @exclude eric:*"
83 else:
84 match = "// @include eric:*"
85 return source.format(
86 match, readAllFileContents(":/javascript/qwebchannel.js"))
75 87
76 88
77 def setStyleSheet(css): 89 def setStyleSheet(css):
78 """ 90 """
79 Function generating a script to set a user style sheet. 91 Function generating a script to set a user style sheet.

eric ide

mercurial