示例#1
0
    def _set_js_api(self):
        def _register_window_object():
            frame.addToJavaScriptWindowObject('external', self.js_bridge)

        script = _parse_api_js(self.js_bridge.api)

        if _qt_version >= [5, 5]:
            qwebchannel_js = QtCore.QFile('://qtwebchannel/qwebchannel.js')
            if qwebchannel_js.open(QtCore.QFile.ReadOnly):
                source = bytes(qwebchannel_js.readAll()).decode('utf-8')
                self.view.page().runJavaScript(source)
                self.channel.registerObject('external', self.js_bridge)
                qwebchannel_js.close()
        elif _qt_version >= [5, 0]:
            frame = self.view.page().mainFrame()
            _register_window_object()
        else:
            frame = self.view.page().mainFrame()
            _register_window_object()

        try:  # PyQt4
            self.view.page().mainFrame().evaluateJavaScript(script)
        except AttributeError:  # PyQt5
            self.view.page().runJavaScript(script)

        self.load_event.set()
示例#2
0
        def on_document_completed(self, sender, args):
            BrowserView.instance.load_event.set()
            if self.first_load:
                self.web_browser.Visible = True
                self.first_load = False

            if self.js_bridge.api:
                document = self.web_browser.Document
                document.InvokeScript('eval',
                                      (_parse_api_js(self.js_bridge.api), ))
示例#3
0
文件: gtk.py 项目: lonicera/pWv
        def create_bridge():
            # Make the `call` method write the function name and param to the
            # `status` attribute of the JS window, delimited by a unique token.
            # The return value will be passed back to the `return_val` attribute
            # of the bridge by the on_status_change handler.
            code = """
            window.pywebview._bridge.call = function(funcName, param) {{
                window.status = "_{0}_" + funcName + "_{0}_" + param;
                return this.return_val;
            }};""".format(self.js_bridge.uid)

            # Create the `pywebview` JS api object
            self.webview.execute_script(_parse_api_js(self.js_bridge.api))
            self.webview.execute_script(code)
            self.load_event.set()
示例#4
0
文件: cocoa.py 项目: lonicera/pWv
    def _set_js_api(self):
        script = _parse_api_js(self.js_bridge.api)
        self.webkit.windowScriptObject().evaluateWebScript_(script)

        pwv_obj = self.webkit.windowScriptObject().valueForKey_('pywebview')
        pwv_obj.setValue_forKey_(self.js_bridge, '_bridge')