|
| 1 | +<img src='/logo-no-text.png' alt='pywebview' style='max-width: 150px; margin: 50px auto 20px auto; display: block'/> |
| 2 | + |
| 3 | + |
| 4 | +# 6.0 is here |
| 5 | + |
| 6 | +I am excited to announce the release of _pywebview 6_. The new version introduces powerful state management, network event handling, and significant improvements to Android support. For a complete changelog, see [here](/changelog). |
| 7 | + |
| 8 | +If you are not familiar with _pywebview_, it's a lightweight Python framework for building modern desktop applications with web technologies. Unlike heavyweight alternatives, _pywebview_ leverages your system's native webview, resulting in smaller binaries and better performance. Write your UI once in HTML, CSS, and JavaScript, then deploy across Windows, macOS, Linux, and Android with the full power of Python at your fingertips. _pywebview_ can be installed with |
| 9 | + |
| 10 | +``` bash |
| 11 | +pip install pywebview |
| 12 | +``` |
| 13 | + |
| 14 | +## Shared State Management |
| 15 | + |
| 16 | +One of the most exciting features in version 6 is the new shared state management via the `window.state` object. This revolutionary feature automatically synchronizes state between Javascript and Python, eliminating the need for manual data synchronization. |
| 17 | + |
| 18 | +``` python |
| 19 | +# In Python |
| 20 | +window.state.user_name = "Test" |
| 21 | +``` |
| 22 | + |
| 23 | +``` javascript |
| 24 | +// In Javascript - automatically updated! |
| 25 | +console.log(window.pywebview.state.user_name); // "Test" |
| 26 | +``` |
| 27 | + |
| 28 | +This bidirectional synchronization makes building complex applications much simpler, as you no longer need to manually pass data between Python and Javascript. Currenlty state syncronization is limited to top-level properties. If you want to synchronize nested objects, you need to reassign the entire object. For example: |
| 29 | + |
| 30 | +``` python |
| 31 | +# In Python |
| 32 | +window.state.user_settings = {"theme": "dark", "notifications": True} |
| 33 | +``` |
| 34 | + |
| 35 | +``` javascript |
| 36 | +// In Javascript - automatically updated! |
| 37 | +console.log(window.pywebview.state.user_settings); // {"theme": "dark", "notifications": True} |
| 38 | +window.pywebview.state.user_settings = {"theme": "light", "notifications": False} // Updates Python side too |
| 39 | +``` |
| 40 | + |
| 41 | +## Network Event Handling |
| 42 | + |
| 43 | +_pywebview 6_ introduces powerful network monitoring capabilities with the new `request_sent` and `response_received` events. These events are fired whenever HTTP requests are made, giving you full visibility into your application's network activity. Request headers can be modified before sending, and you can inspect responses as they arrive. Response header modification is not supported. |
| 44 | + |
| 45 | +``` python |
| 46 | +def on_request_sent(request): |
| 47 | + print(f"Sending request to: {request['url']}") |
| 48 | + # Modify request headers before sending |
| 49 | + request['headers']['Authorization'] = f"Bearer {get_auth_token()}" |
| 50 | + |
| 51 | +def on_response_received(response): |
| 52 | + print(f"Received response: {response['status_code']}") |
| 53 | + |
| 54 | +window.events.request_sent += on_request_sent |
| 55 | +window.events.response_received += on_response_received |
| 56 | +``` |
| 57 | + |
| 58 | + |
| 59 | +## Enhanced Android Support |
| 60 | + |
| 61 | +Android support receives a major upgrade with a new Kivyless implementation that significantly improves startup time and reduces package size. Additionally, Android apps now support fullscreen mode, bringing mobile experience closer to native apps. |
| 62 | + |
| 63 | +Furthermore Android now has a new dedicated test suite found in `tests/android`. |
| 64 | + |
| 65 | +## Window-Specific Menus |
| 66 | + |
| 67 | +You can now create custom menus for individual windows, giving you more control over the user interface (not supported on GTK with Unity) |
| 68 | + |
| 69 | +``` python |
| 70 | +menu = webview.menu.Menu([ |
| 71 | + webview.menu.MenuAction('File', [ |
| 72 | + webview.menu.MenuAction('New', new_file), |
| 73 | + webview.menu.MenuSeparator(), |
| 74 | + webview.menu.MenuAction('Exit', exit_app) |
| 75 | + ]) |
| 76 | +]) |
| 77 | + |
| 78 | +window = webview.create_window('My App', 'index.html', menu=menu) |
| 79 | +``` |
| 80 | + |
| 81 | +## Modern API Improvements |
| 82 | + |
| 83 | +Version 6 includes several breaking changes that modernize the API and removes deprecated features: |
| 84 | + |
| 85 | +- File dialog constants are now part of the `webview.FileDialog` enum (`SAVE`, `LOAD`, `FOLDER`) |
| 86 | +- `webview.DRAG_REGION_SELECTOR` moved to `webview.settings['webview.DRAG_REGION_SELECTOR']` |
| 87 | +- Deprecated DOM functions are removed in favor of the modern `window.dom` API |
| 88 | + |
| 89 | + |
| 90 | +## Platform-Specific Enhancements |
| 91 | + |
| 92 | +- **Windows**: Dark mode support with automatic theme detection |
| 93 | +- **macOS**: Option to hide default menus and better Javascript prompt handling |
| 94 | +- **All platforms**: Improved screen coordinate handling and better SSL support |
| 95 | + |
| 96 | +## Learn more |
| 97 | + |
| 98 | +Ready to explore _pywebview 6_? Check out the [usage guide](/guide/usage.html), [API reference](/guide/api.html) and [examples](/examples) to get started with the new features. |
| 99 | + |
| 100 | +## Support the project |
| 101 | + |
| 102 | +_pywebview_ continues to be primarily a one-person project, updated when time allows. Your contributions make a real difference! The best way to help is by submitting pull requests - bug fixes are always welcome, and for new features, please create an issue to discuss first. Check out the [contributing guide](/contributing) to get started. |
| 103 | + |
| 104 | +If _pywebview_ has been useful for your projects and you'd like to see continued development, consider sponsoring the project. Companies can become sponsors to gain exposure and connect with the Python developer community. |
| 105 | + |
| 106 | +<div class="center spc-l spc-vertical"> |
| 107 | + <a href="https://github.com/sponsors/r0x0r"> |
| 108 | + <img src='/github_sponsor_button.png' alt='Sponsor on Github' style="max-width: 250px"/> |
| 109 | + </a> |
| 110 | +</div> |
| 111 | + |
| 112 | +<div class="center spc-l spc-vertical"> |
| 113 | + <a href="https://opencollective.com/pywebview/donate" target="_blank"> |
| 114 | + <img src="https://opencollective.com/pywebview/donate/[email protected]?color=blue" width=300 /> |
| 115 | + </a> |
| 116 | +</div> |
| 117 | + |
| 118 | +<div class="center spc-l spc-vertical"> |
| 119 | + <a href="https://www.patreon.com/bePatron?u=13226105" data-patreon-widget-type="become-patron-button"> |
| 120 | + <img src='https://c5.patreon.com/external/logo/become_a_patron_button.png' alt='Become a Patron!'/> |
| 121 | + </a> |
| 122 | +</div> |
| 123 | + |
| 124 | +<div class="center spc-l spc-vertical"> |
| 125 | + <a href="http://bit.ly/2eg2Z5P" target="_blank"> |
| 126 | + <img src="/paypal.png"/> |
| 127 | + </a> |
| 128 | +</div> |
0 commit comments