-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsimple.py
More file actions
45 lines (36 loc) · 1.06 KB
/
simple.py
File metadata and controls
45 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "justbe-webview",
# ]
#
# [tool.uv.sources]
# justbe-webview = { path = "../" }
# ///
import asyncio
from justbe_webview import (
WebView,
Options,
ContentHtml,
Notification,
)
async def main():
print("Creating webview")
config = Options(
title="Simple",
load=ContentHtml(html="<h1>Hello, World!</h1>"),
devtools=True,
initializationScript="console.log('This is printed from initializationScript!')",
)
async with WebView(config) as webview:
async def handle_start(event: Notification):
print("handle_start called")
await webview.set_title("Title set from Python")
current_title = await webview.get_title()
print(f"Current title: {current_title}")
await webview.open_devtools()
await webview.eval("console.log('This is printed from eval!')")
webview.on("started", handle_start)
print("Webview closed")
if __name__ == "__main__":
asyncio.run(main())