From fe56af22926e6db2892d806828fea55f2a98e727 Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 6 Sep 2023 15:30:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=A1=A5=E6=8E=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/lib/python3/dist-packages/webengine/gtk3/__init__.py | 3 ++- .../python3/dist-packages/webengine/gtk3/_custom_bridge.py | 7 +++++++ usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 usr/lib/python3/dist-packages/webengine/gtk3/_custom_bridge.py diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py b/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py index e3d2720..3f49140 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py @@ -7,4 +7,5 @@ from ._version import * from ._webengine import WebEngine from ._settings import create_setting -from ._hotreload import create_hmr_server \ No newline at end of file +from ._hotreload import create_hmr_server +from ._custom_bridge import create_bridge \ No newline at end of file diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_custom_bridge.py b/usr/lib/python3/dist-packages/webengine/gtk3/_custom_bridge.py new file mode 100644 index 0000000..cc06077 --- /dev/null +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_custom_bridge.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +def create_bridge(): + def wrapper(app, extra = None): + app.custom_bridge = extra + + return wrapper \ No newline at end of file diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py index 10ddd66..2d3b488 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py @@ -73,6 +73,7 @@ class WebEngine(WebKit2.WebView): root = None window = None + custom_bridge = None def __init__(self, window): @@ -200,6 +201,12 @@ class WebEngine(WebKit2.WebView): case 'md5': output = hashlib.md5(str(params.get('value'))).hexdigest() + case _: + if self.custom_bridge is None: + pass + else: + _error, output = self.custom_bridge(event, params) + # 有回调则返回结果 if callback: self.call_js(callback, output, _error)