-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwindow_size.py
More file actions
52 lines (43 loc) · 1.4 KB
/
window_size.py
File metadata and controls
52 lines (43 loc) · 1.4 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
46
47
48
49
50
51
52
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "justbe-webview",
# ]
#
# [tool.uv.sources]
# justbe-webview = { path = "../" }
# ///
import asyncio
from justbe_webview import WebView, Options, ContentHtml, IpcNotification, Size
async def main():
print("Creating webview")
config = Options(
title="Window Size",
load=ContentHtml(
html="""
<h1>Window Sizes</h1>
<div style="display: flex; gap: 10px;">
<button onclick="window.ipc.postMessage('maximize')">Maximize</button>
<button onclick="window.ipc.postMessage('minimize')">Minimize</button>
<button onclick="window.ipc.postMessage('fullscreen')">Fullscreen</button>
</div>
"""
),
size=Size(width=800, height=200),
ipc=True,
)
async with WebView(config) as webview:
async def handle_ipc(event: IpcNotification):
message = event.message
if message == "maximize":
await webview.maximize()
elif message == "minimize":
await webview.minimize()
elif message == "fullscreen":
await webview.fullscreen()
else:
print(f"Unknown message: {message}")
webview.on("ipc", handle_ipc)
print("Webview closed")
if __name__ == "__main__":
asyncio.run(main())