sideview 0.4.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,359 @@
1
+ Metadata-Version: 2.4
2
+ Name: sideview
3
+ Version: 0.4.0
4
+ Summary: A lightweight native webview widget for PySide6.
5
+ Keywords: pyside6,qt,webview,webview2,webkit,webkitgtk
6
+ Author: AlexsanderMe
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Environment :: X11 Applications :: Qt
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: MacOS
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Project-URL: Homepage, https://github.com/AlexsanderMe/SideView
23
+ Project-URL: Documentation, https://github.com/AlexsanderMe/SideView#readme
24
+ Project-URL: Repository, https://github.com/AlexsanderMe/SideView
25
+ Project-URL: Issues, https://github.com/AlexsanderMe/SideView/issues
26
+ Project-URL: Changelog, https://github.com/AlexsanderMe/SideView/blob/master/CHANGELOG.md
27
+ Requires-Python: >=3.10
28
+ Requires-Dist: PySide6>=6.5
29
+ Provides-Extra: dev
30
+ Requires-Dist: build<2,>=1.3; extra == "dev"
31
+ Requires-Dist: pytest<10,>=8; extra == "dev"
32
+ Requires-Dist: ruff<1,>=0.12; extra == "dev"
33
+ Requires-Dist: twine<7,>=6; extra == "dev"
34
+ Description-Content-Type: text/markdown
35
+
36
+ # SideView
37
+
38
+ A lightweight native webview widget for PySide6 applications that need the operating
39
+ system browser stack without bundling Qt WebEngine.
40
+
41
+ The library exposes a normal `QWidget` subclass in Python and delegates rendering to:
42
+
43
+ - Windows: Microsoft Edge WebView2, hosted inside the widget's native `HWND`.
44
+ - macOS: `WKWebView`, hosted inside the widget's native `NSView`.
45
+ - Linux: WebKitGTK 4.1, embedded into the Qt widget through an X11 foreign window.
46
+
47
+ This is intentionally not a full browser. It is a small embedded view for in-app navigation, OAuth/help pages, web dashboards, and video playback using codecs available through the operating system browser stack.
48
+
49
+ It also gives the host application control over browser-adjacent behavior that should not be left to the embedded engine by default:
50
+
51
+ - Downloads are intercepted and blocked unless your Python whitelist callback allows them.
52
+ - Links that request a new window are intercepted and surfaced as a signal, so the app can open an internal tab instead of letting the engine spawn a separate native window.
53
+ - JavaScript can be injected at document creation, and page scripts can send messages back to Python.
54
+ - Native context menus and devtools can be disabled so the host app can provide its own controlled menu.
55
+ - The visible webview can be captured as PNG/JPEG bytes, either as a full frame, viewport-relative region, or a continuous native frame stream where supported.
56
+ - Browser zoom can be read, changed, and observed through a platform-neutral API.
57
+
58
+ ## Why not fork pywebview?
59
+
60
+ `pywebview` is a window abstraction. Its backends are designed to own top-level windows and integrate with their own GUI loops. This library uses the opposite contract: PySide6 owns the application, and the native webview is a child of a Qt widget. That keeps focus, resizing, lifecycle, and application shutdown under Qt's control.
61
+
62
+ ## Current status
63
+
64
+ SideView is currently an alpha API. The repository provides:
65
+
66
+ - Focused Python `NativeWebView` API.
67
+ - Native library loader with clear platform errors.
68
+ - Windows C++ backend using WebView2.
69
+ - macOS Objective-C++ backend using WKWebView.
70
+ - Linux C++ backend using WebKitGTK and GTK 3.
71
+ - CMake build files for native libraries.
72
+ - A tabbed PySide6 browser example with back, forward, reload, new tab, close tab, URL/search bar, download policy hooks, and new-window routing.
73
+ - Script bridge hooks for custom overlays, page-to-Python messages, and controlled context menus.
74
+ - Asynchronous native capture hooks for tab-live previews, region projection, and high-FPS frame streaming on WebView2.
75
+
76
+ ## Installation
77
+
78
+ Windows x64 and macOS universal2 wheels contain the native backend:
79
+
80
+ ```bash
81
+ python -m pip install sideview
82
+ ```
83
+
84
+ Linux is distributed as source because WebKitGTK is a system library. Install the
85
+ WebKitGTK 4.1 and GTK 3 development packages for your distribution before running
86
+ the same `pip install` command. For Ubuntu 22.04 and newer:
87
+
88
+ ```bash
89
+ sudo apt-get install libgtk-3-dev libwebkit2gtk-4.1-dev pkg-config
90
+ python -m pip install sideview
91
+ ```
92
+
93
+ Linux embedding requires Qt's XCB platform. Native X11 works directly; Wayland
94
+ sessions can run through XWayland by setting `QT_QPA_PLATFORM=xcb` before the
95
+ `QApplication` is created.
96
+
97
+ ## Python usage
98
+
99
+ ```python
100
+ from PySide6.QtWidgets import QApplication, QMainWindow
101
+ from sideview import NativeWebView
102
+
103
+ app = QApplication([])
104
+
105
+ window = QMainWindow()
106
+ view = NativeWebView()
107
+ window.setCentralWidget(view)
108
+ window.resize(1200, 800)
109
+ window.show()
110
+
111
+ view.navigate("https://www.youtube.com")
112
+
113
+ app.exec()
114
+ ```
115
+
116
+ ## Downloads and new windows
117
+
118
+ Downloads are denied by default. Register a callback with `set_download_policy()` to allow only the URLs your app trusts. The callback should return `True` to let the native webview continue the download, or `False` to cancel it so your app can handle the URL itself.
119
+
120
+ ```python
121
+ from urllib.parse import urlparse
122
+
123
+ ALLOWED_DOWNLOAD_HOSTS = {"example.com", "cdn.example.com"}
124
+
125
+
126
+ def allow_download(url: str) -> bool:
127
+ return (urlparse(url).hostname or "").lower() in ALLOWED_DOWNLOAD_HOSTS
128
+
129
+
130
+ view.set_download_policy(allow_download)
131
+ view.downloadRequested.connect(lambda url: print("Download requested:", url))
132
+ ```
133
+
134
+ Links that try to open a new tab or popup are not opened as separate native windows. Instead, the widget emits `newWindowRequested(url)`.
135
+
136
+ ```python
137
+ view.newWindowRequested.connect(lambda url: open_internal_tab(url))
138
+ ```
139
+
140
+ ## JavaScript bridge and context menus
141
+
142
+ Use `add_document_script()` for persistent JavaScript that should run at document creation on every future navigation. Use `eval_js()` for one-shot JavaScript on the currently loaded page.
143
+
144
+ ```python
145
+ view.add_document_script("""
146
+ window.addEventListener("DOMContentLoaded", () => {
147
+ document.documentElement.dataset.hostApp = "solin";
148
+ });
149
+ """)
150
+ ```
151
+
152
+ `install_script_bridge()` exposes `window.nativeWebView.postMessage(message)` to page scripts. Messages arrive in Python through `scriptMessageReceived`.
153
+
154
+ ```python
155
+ view.install_script_bridge()
156
+ view.scriptMessageReceived.connect(lambda message: print("JS:", message))
157
+
158
+ view.eval_js("""
159
+ window.nativeWebView.postMessage({
160
+ type: "overlay-ready",
161
+ href: location.href
162
+ });
163
+ """)
164
+ ```
165
+
166
+ For a controlled right-click menu, call `install_context_menu_bridge()`. It disables the native browser context menu, prevents default page context menus, and emits `contextMenuRequested(dict)` with coordinates and basic target metadata.
167
+
168
+ ```python
169
+ def show_context_menu(payload: dict) -> None:
170
+ print(payload["x"], payload["y"], payload.get("href"), payload.get("src"))
171
+
172
+
173
+ view.set_devtools_enabled(False)
174
+ view.install_context_menu_bridge()
175
+ view.contextMenuRequested.connect(show_context_menu)
176
+ ```
177
+
178
+ ## Native capture
179
+
180
+ `capture_frame()` and `capture_region()` return immediately with a request id. The PNG bytes arrive later through `captureCompleted(request_id, data)`. `capture_frame_jpeg()` follows the same request/response model, but returns JPEG bytes for lighter live-preview snapshots. Failures arrive through `captureFailed(request_id, error)`.
181
+
182
+ ```python
183
+ def save_capture(request_id: int, data: bytes) -> None:
184
+ Path(f"capture-{request_id}.png").write_bytes(data)
185
+
186
+
187
+ view.captureCompleted.connect(save_capture)
188
+ view.captureFailed.connect(lambda request_id, error: print("Capture failed:", error))
189
+
190
+ full_request_id = view.capture_frame()
191
+ region_request_id = view.capture_region(120, 80, 640, 360)
192
+ jpeg_request_id = view.capture_frame_jpeg()
193
+ ```
194
+
195
+ The capture API is intentionally native and asynchronous:
196
+
197
+ - Windows uses WebView2 `CapturePreview` and crops regions with Windows Imaging Component.
198
+ - macOS uses WKWebView snapshots with `WKSnapshotConfiguration`.
199
+ - Linux uses WebKitGTK visible-region snapshots and GdkPixbuf encoding.
200
+ - Coordinates use widget pixels with a top-left origin.
201
+
202
+ For live projection on Windows, prefer `start_frame_stream()`. It uses WebView2 DevTools screencast frames and emits JPEG bytes through `frameStreamFrame(data)`. Unsupported platforms return `False`, so production apps should fall back to `capture_frame_jpeg()`.
203
+
204
+ ```python
205
+ def show_live_frame(data: bytes) -> None:
206
+ pixmap = QPixmap()
207
+ if pixmap.loadFromData(data):
208
+ update_projection(pixmap)
209
+
210
+
211
+ view.frameStreamFrame.connect(show_live_frame)
212
+ view.frameStreamFailed.connect(lambda error: print("Frame stream failed:", error))
213
+
214
+ if not view.start_frame_stream(quality=75, max_width=1280, max_height=720):
215
+ start_timer_based_jpeg_capture()
216
+
217
+ # Later, when projection stops:
218
+ view.stop_frame_stream()
219
+ ```
220
+
221
+ ## Sessions and cookies
222
+
223
+ Use `session_id` to isolate browser state per application profile. Views created with the same `session_id` share cookies/cache; views created with different IDs get separate sessions.
224
+
225
+ ```python
226
+ profile_id = "default" # for example, your active app profile id
227
+
228
+ view = NativeWebView(
229
+ session_id=f"solin_session_{profile_id}",
230
+ session_data_root="path/to/user/data/webview",
231
+ )
232
+ ```
233
+
234
+ On Windows, the session maps to a WebView2 `userDataFolder`. On macOS, the session maps to a persistent `WKWebsiteDataStore` identifier when the platform supports it. On Linux, it maps to a WebKitGTK website-data directory with persistent cookie storage. You can still pass `user_data_folder` directly when you need full control over the storage path.
235
+
236
+ Cookies can be set before or after the native view is ready. If the view is not ready yet, the cookie operation is queued and applied before the first pending navigation.
237
+
238
+ ```python
239
+ view.set_cookie(
240
+ name="session",
241
+ value="abc123",
242
+ domain=".example.com",
243
+ path="/",
244
+ secure=True,
245
+ http_only=True,
246
+ same_site="lax",
247
+ )
248
+ ```
249
+
250
+ To clear the current session cookies:
251
+
252
+ ```python
253
+ view.clear_cookies()
254
+ view.reload()
255
+ ```
256
+
257
+ ## Zoom
258
+
259
+ `set_zoom_factor()` applies native page zoom. User changes, including
260
+ `Ctrl + scroll` in WebView2, emit `zoomFactorChanged`, allowing a host with
261
+ multiple views to keep one shared zoom preference.
262
+
263
+ ```python
264
+ view.set_zoom_factor(1.25)
265
+ view.zoomFactorChanged.connect(lambda factor: print("Zoom:", factor))
266
+ print(view.zoom_factor())
267
+ ```
268
+
269
+ ## Building from source
270
+
271
+ ### GitHub Actions
272
+
273
+ Every pull request runs tests and builds the release distributions through
274
+ `.github/workflows/build-distributions.yml`. Release builds produce:
275
+
276
+ - a Windows x64 `py3-none-win_amd64` wheel;
277
+ - a macOS `py3-none-macosx_*_universal2` wheel;
278
+ - one source distribution used to build the Linux backend on the target machine.
279
+
280
+ The workflow can also be dispatched manually for a branch, tag, or commit.
281
+
282
+ ### Windows
283
+
284
+ Install the WebView2 Runtime and the WebView2 SDK headers/libraries. The CMake project expects `WEBVIEW2_SDK_DIR` to point at the SDK root that contains `build/native/include/WebView2.h` and the matching loader library.
285
+
286
+ ```powershell
287
+ .\scripts\build_windows.ps1 -WebView2SdkDir C:\path\to\Microsoft.Web.WebView2
288
+ ```
289
+
290
+ The script uses `vswhere` to locate Visual Studio Build Tools, configures MSVC
291
+ through `vcvars64.bat`, builds the DLL, and copies it next to the Python package.
292
+ If you build manually, copy `sideview_native.dll` next to `src/sideview/` or set:
293
+
294
+ ```powershell
295
+ $env:SIDEVIEW_NATIVE_LIB="C:\path\to\sideview_native.dll"
296
+ ```
297
+
298
+ ### macOS
299
+
300
+ ```bash
301
+ cmake -S native -B build/native -DCMAKE_BUILD_TYPE=Release
302
+ cmake --build build/native
303
+ ```
304
+
305
+ Copy `libsideview_native.dylib` next to `src/sideview/` or set:
306
+
307
+ ```bash
308
+ export SIDEVIEW_NATIVE_LIB=/path/to/libsideview_native.dylib
309
+ ```
310
+
311
+ ### Linux
312
+
313
+ The Linux backend uses the GTK 3 build of WebKitGTK 4.1. On Ubuntu 22.04 or
314
+ newer Debian-based distributions, install the build dependencies and build the
315
+ library with:
316
+
317
+ ```bash
318
+ sudo apt-get install libgtk-3-dev libwebkit2gtk-4.1-dev pkg-config
319
+ bash scripts/build_linux.sh
320
+ ```
321
+
322
+ The build script copies `libsideview_native.so` next to the Python package. A
323
+ custom location can be selected with:
324
+
325
+ ```bash
326
+ export SIDEVIEW_NATIVE_LIB=/path/to/libsideview_native.so
327
+ ```
328
+
329
+ Embedding GTK inside Qt requires the X11/XCB window model. It works on native X11 desktops and through XWayland. On a Wayland session, launch the application with the Qt XCB backend before creating `QApplication`:
330
+
331
+ ```bash
332
+ QT_QPA_PLATFORM=xcb python examples/simple_browser.py
333
+ ```
334
+
335
+ WebKitGTK and GTK remain dynamically linked system dependencies.
336
+
337
+ ## Design constraints
338
+
339
+ - The native webview is a real native child view. It draws outside Qt's paint engine, so it should not be overlapped by translucent Qt widgets.
340
+ - Because rendering happens in a native child view, Qt `QWidget.grab()` is not a reliable production-grade way to capture tab-live thumbnails or crop projected page regions. Use the native capture API instead.
341
+ - Keep one webview per visible widget unless the product truly needs more; native browser views are heavier than normal widgets.
342
+ - Navigation policy, custom context menus, downloads, permission prompts, and devtools should be added deliberately as product requirements, not by default.
343
+ - Linux embedding requires Qt to use the XCB platform because GTK 3 foreign-window embedding is X11-specific. Native Wayland cross-toolkit embedding is not available.
344
+
345
+ ## Example
346
+
347
+ Run:
348
+
349
+ ```bash
350
+ python examples/simple_browser.py
351
+ ```
352
+
353
+ The example opens Google in a new tab by default. The address bar goes directly to valid URLs and searches Google when the input looks like plain text. Its download whitelist is intentionally empty:
354
+
355
+ ```python
356
+ DOWNLOAD_HOST_WHITELIST: set[str] = set()
357
+ ```
358
+
359
+ Replace `is_download_allowed(url)` in `examples/simple_browser.py` with your application policy when you decide how downloads should be handled.
@@ -0,0 +1,9 @@
1
+ sideview/__init__.py,sha256=hupweVvFEpIhJf30riul_JFbjywbmZmEW4n3koG8DM0,285
2
+ sideview/_backend.py,sha256=KbJjZqJXXAxWIdTVbaA4H7Febu6MrIx6ev4i-M76f0o,19799
3
+ sideview/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
4
+ sideview/sideview_native.dll,sha256=aNqE93om7gU4CA-4zSjR85OBzABhUiaOFMesTx51uWM,99840
5
+ sideview/widget.py,sha256=Xd9ca06W6kNtKySuSsCRHdCvIKSZRUrSYeAds3Ijuqk,27989
6
+ sideview-0.4.0.dist-info/METADATA,sha256=iRibIOvtYMfjYGmNKqtlaYBAYwt6YOaKtbfKhOjI7Dg,14066
7
+ sideview-0.4.0.dist-info/WHEEL,sha256=k8ugwGhXAI0--PEoWE0F6sXc-nX2zbZqyTgxRg_imsk,102
8
+ sideview-0.4.0.dist-info/licenses/LICENSE,sha256=Nm-YMbpNBELaOAg9e7j7UiCrRyhNQkyivd87VpSasHM,1095
9
+ sideview-0.4.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: scikit-build-core 1.0.3
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Alexsander Meiniche
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.