Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 33c8c98

Browse files
committed
docs update
1 parent 8d592b0 commit 33c8c98

File tree

7 files changed

+114
-46
lines changed

7 files changed

+114
-46
lines changed

docs/index.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ This package supports the following platforms:
2222
| Android ||
2323
| Web ||
2424

25+
## Usage
26+
27+
### Installation
28+
29+
To install the `flet-webview` package and add it to your project dependencies:
30+
31+
=== "uv"
32+
33+
```bash
34+
uv add flet-webview
35+
```
36+
37+
=== "pip"
38+
39+
```bash
40+
pip install flet-webview
41+
```
42+
43+
You will have to manually add this package to your `requirements.txt` or `pyproject.toml`.
44+
45+
=== "poetry"
46+
47+
```bash
48+
poetry add flet-webview
49+
```
50+
2551
## Example
2652

2753
```python title="main.py"
Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
2-
name = "webview_example"
2+
name = "flet-webview-example"
33
version = "1.0.0"
4-
description = "Flet Webview Example"
4+
description = "flet-webview-example"
55
readme = "README.md"
66
license = "Apache-2.0"
77
requires-python = ">=3.10"
@@ -13,26 +13,9 @@ dependencies = [
1313
# Docs: https://flet.dev/docs/publish
1414
[tool.flet]
1515
org = "com.mycompany"
16-
product = "Flet Webview Example"
16+
product = "flet-webview-example"
1717
company = "Flet"
1818
copyright = "Copyright (C) 2025 by Flet"
1919

2020
[tool.flet.app]
2121
path = "src"
22-
23-
[tool.flet.dev_packages]
24-
flet-webview = "../.."
25-
flet = "../../../flet/sdk/python/packages/flet"
26-
27-
[tool.uv]
28-
dev-dependencies = [
29-
"flet",
30-
"flet-cli",
31-
"flet-desktop",
32-
]
33-
34-
[tool.uv.sources]
35-
flet-webview = { path = "../../", editable = true }
36-
flet = { git = "https://github.com/flet-dev/flet", subdirectory = "sdk/python/packages/flet", rev = "v1" }
37-
flet-cli = { git = "https://github.com/flet-dev/flet", subdirectory = "sdk/python/packages/flet-cli", rev = "v1" }
38-
flet-desktop = { git = "https://github.com/flet-dev/flet", subdirectory = "sdk/python/packages/flet-desktop", rev = "v1" }

examples/webview_example/src/main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55

66
def main(page: ft.Page):
7-
wv = fwv.WebView(
8-
url="https://flet.dev",
9-
on_page_started=lambda _: print("Page started"),
10-
on_page_ended=lambda _: print("Page ended"),
11-
on_web_resource_error=lambda e: print("Page error:", e.data),
12-
expand=True,
7+
page.add(
8+
fwv.WebView(
9+
url="https://flet.dev",
10+
on_page_started=lambda _: print("Page started"),
11+
on_page_ended=lambda _: print("Page ended"),
12+
on_web_resource_error=lambda e: print("WebView error:", e.data),
13+
expand=True,
14+
)
1315
)
14-
page.add(wv)
1516

1617

17-
ft.app(main)
18+
ft.run(main)

mkdocs.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ theme:
4747
- content.code.annotate
4848
- content.code.copy
4949
- content.code.select
50+
- content.tabs.link
5051
# - navigation.tabs
5152
- navigation.instant
5253
- navigation.tracking
@@ -105,6 +106,7 @@ plugins:
105106
- mike:
106107
alias_type: symlink
107108
- glightbox
109+
- section-index
108110
- mkdocstrings:
109111
default_handler: python_xref
110112
handlers:
@@ -137,23 +139,42 @@ plugins:
137139

138140
# Markdown Extensions
139141
markdown_extensions:
142+
- abbr
140143
- admonition
144+
- attr_list
145+
- def_list
146+
- footnotes
147+
- md_in_html
141148
- toc:
142149
permalink: "#"
150+
151+
# Python Markdown Extensions
152+
- pymdownx.arithmatex:
153+
generic: true
154+
- pymdownx.betterem:
155+
smart_enable: all
156+
- pymdownx.caret
157+
- pymdownx.details
158+
- pymdownx.emoji:
159+
emoji_index: !!python/name:material.extensions.emoji.twemoji
160+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
143161
- pymdownx.highlight:
144162
anchor_linenums: true
145163
line_spans: __span
146164
pygments_lang_class: true
147165
- pymdownx.inlinehilite
148-
- pymdownx.snippets
166+
- pymdownx.keys
167+
- pymdownx.mark
168+
- pymdownx.smartsymbols
149169
- pymdownx.superfences
150-
- pymdownx.details
170+
- pymdownx.snippets
151171
- pymdownx.magiclink:
152172
repo_url_shorthand: true
153173
- pymdownx.tabbed:
154174
alternate_style: true
155-
- attr_list
156-
- md_in_html
157-
- def_list
175+
slugify: !!python/object/apply:pymdownx.slugs.slugify
176+
kwds:
177+
case: lower
158178
- pymdownx.tasklist:
159179
custom_checkbox: true
180+
- pymdownx.tilde

pyproject.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ docs = [
3232
"markdown>=3.6",
3333
"pymdown-extensions",
3434
"mkdocs-glightbox",
35+
"mkdocs-section-index",
3536
"pygments>=2.16",
3637
]
3738

@@ -41,3 +42,35 @@ flet = { git = "https://github.com/flet-dev/flet", subdirectory = "sdk/python/pa
4142
[build-system]
4243
requires = ["setuptools"]
4344
build-backend = "setuptools.build_meta"
45+
46+
[tool.ruff]
47+
line-length = 88
48+
target-version = "py39"
49+
fix = true
50+
show-fixes = true
51+
52+
[tool.ruff.lint]
53+
select = [
54+
# pycodestyle
55+
"E",
56+
# Pyflakes
57+
"F",
58+
# pyupgrade
59+
"UP",
60+
# flake8-bugbear
61+
"B",
62+
# flake8-simplify
63+
"SIM",
64+
# isort
65+
"I"
66+
]
67+
ignore = [
68+
# Pyflakes
69+
"F401", # unused import
70+
]
71+
preview = true
72+
73+
[tool.ruff.format]
74+
quote-style = "double"
75+
indent-style = "space"
76+
line-ending = "auto"

src/flet_webview/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LogLevelSeverity(Enum):
4545

4646

4747
@dataclass
48-
class WebViewScrollEvent(ft.ControlEvent):
48+
class WebViewScrollEvent(ft.Event[ft.EventControlType]):
4949
x: float
5050
"""The value of the horizontal offset with the origin being at the leftmost of the `WebView`."""
5151

@@ -54,7 +54,7 @@ class WebViewScrollEvent(ft.ControlEvent):
5454

5555

5656
@dataclass
57-
class WebViewConsoleMessageEvent(ft.ControlEvent):
57+
class WebViewConsoleMessageEvent(ft.Event[ft.EventControlType]):
5858
message: str
5959
"""The message written to the console."""
6060

@@ -63,7 +63,7 @@ class WebViewConsoleMessageEvent(ft.ControlEvent):
6363

6464

6565
@dataclass
66-
class WebViewJavaScriptEvent(ft.ControlEvent):
66+
class WebViewJavaScriptEvent(ft.Event[ft.EventControlType]):
6767
message: str
6868
"""The message to be displayed in the window."""
6969

src/flet_webview/webview.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class WebView(ft.ConstrainedControl):
3838
bgcolor: Optional[ft.ColorValue] = None
3939
"""Defines the background color of the WebView."""
4040

41-
on_page_started: ft.OptionalControlEventCallable = None
41+
on_page_started: ft.OptionalControlEventHandler["WebView"] = None
4242
"""
4343
Fires soon as the first loading process of the webview page is started.
4444
@@ -48,7 +48,7 @@ class WebView(ft.ConstrainedControl):
4848
Works only on the following platforms: iOS, Android and macOS.
4949
"""
5050

51-
on_page_ended: ft.OptionalControlEventCallable = None
51+
on_page_ended: ft.OptionalControlEventHandler["WebView"] = None
5252
"""
5353
Fires when all the webview page loading processes are ended.
5454
@@ -58,7 +58,7 @@ class WebView(ft.ConstrainedControl):
5858
Works only on the following platforms: iOS, Android and macOS.
5959
"""
6060

61-
on_web_resource_error: ft.OptionalControlEventCallable = None
61+
on_web_resource_error: ft.OptionalControlEventHandler["WebView"] = None
6262
"""
6363
Fires when there is error with loading a webview page resource.
6464
@@ -68,7 +68,7 @@ class WebView(ft.ConstrainedControl):
6868
Works only on the following platforms: iOS, Android and macOS.
6969
"""
7070

71-
on_progress: ft.OptionalControlEventCallable = None
71+
on_progress: ft.OptionalControlEventHandler["WebView"] = None
7272
"""
7373
Fires when the progress of the webview page loading is changed.
7474
@@ -78,7 +78,7 @@ class WebView(ft.ConstrainedControl):
7878
Works only on the following platforms: iOS, Android and macOS.
7979
"""
8080

81-
on_url_change: ft.OptionalControlEventCallable = None
81+
on_url_change: ft.OptionalControlEventHandler["WebView"] = None
8282
"""
8383
Fires when the URL of the webview page is changed.
8484
@@ -88,7 +88,7 @@ class WebView(ft.ConstrainedControl):
8888
Works only on the following platforms: iOS, Android and macOS.
8989
"""
9090

91-
on_scroll: ft.OptionalEventCallable[WebViewScrollEvent] = None
91+
on_scroll: ft.OptionalEventHandler[WebViewScrollEvent["WebView"]] = None
9292
"""
9393
Fires when the web page's scroll position changes.
9494
@@ -98,7 +98,9 @@ class WebView(ft.ConstrainedControl):
9898
Works only on the following platforms: iOS, Android and macOS.
9999
"""
100100

101-
on_console_message: ft.OptionalEventCallable[WebViewConsoleMessageEvent] = None
101+
on_console_message: ft.OptionalEventHandler[
102+
WebViewConsoleMessageEvent["WebView"]
103+
] = None
102104
"""
103105
Fires when a log message is written to the JavaScript console.
104106
@@ -108,7 +110,9 @@ class WebView(ft.ConstrainedControl):
108110
Works only on the following platforms: iOS, Android and macOS.
109111
"""
110112

111-
on_javascript_alert_dialog: ft.OptionalEventCallable[WebViewJavaScriptEvent] = None
113+
on_javascript_alert_dialog: ft.OptionalEventHandler[
114+
WebViewJavaScriptEvent["WebView"]
115+
] = None
112116
"""
113117
Fires when the web page attempts to display a JavaScript alert() dialog.
114118
@@ -362,7 +366,7 @@ def load_request(self, url: str, method: RequestMethod = RequestMethod.GET):
362366
363367
Args:
364368
url (str): The URL to load.
365-
method (RequestMethod): The HTTP method to use. Defaults to `RequestMethod.GET`.
369+
method (RequestMethod): The HTTP method to use.
366370
"""
367371
self._check_mobile_or_mac_platform()
368372
asyncio.create_task(self.load_request_async(url, method))
@@ -375,7 +379,7 @@ async def load_request_async(
375379
376380
Args:
377381
url (str): The URL to load.
378-
method (RequestMethod): The HTTP method to use. Defaults to `RequestMethod.GET`.
382+
method (RequestMethod): The HTTP method to use.
379383
380384
Note:
381385
Works only on the following platforms: iOS, Android and macOS.

0 commit comments

Comments
 (0)