Skip to content

Commit 62ced2d

Browse files
committed
Apply code formatting
1 parent a7d77d7 commit 62ced2d

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

examples/simple_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def on_button_click(event):
1414

1515
# You can even use the Pyodide/JS bridge
1616
from js import alert
17+
1718
alert("It works! Python is running in your browser.")
1819

1920

@@ -24,18 +25,17 @@ def home():
2425

2526
# 4. Build the UI
2627
# We create a button and attach the Python function directly.
27-
btn = (
28-
Element("button", text="Click Me!")
29-
.on("click", on_button_click) # <--- The Magic Link
30-
)
28+
btn = Element("button", text="Click Me!").on(
29+
"click", on_button_click
30+
) # <--- The Magic Link
3131

3232
doc.body.extend(
3333
Element("h1", text="Violetear Full-Stack Demo"),
3434
Element("p", text="Open your browser console (F12) and click the button."),
35-
btn
35+
btn,
3636
)
3737

3838
return doc
3939

4040

41-
app.run()
41+
app.run()

violetear/app.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def _generate_bundle(self) -> str:
9393
It combines the runtime logic + user functions.
9494
"""
9595
# 1. Mock the 'app' object so decorators don't fail in the browser
96-
header = "class MockApp:\n def client(self, f): return f\n\napp = MockApp()\n\n"
96+
header = (
97+
"class MockApp:\n def client(self, f): return f\n\napp = MockApp()\n\n"
98+
)
9799

98100
# 2. Read the Client Runtime (Hydration logic)
99101
runtime_path = Path(__file__).parent / "client.py"
@@ -118,15 +120,17 @@ def _inject_client_side(self, doc: Document):
118120
doc.script(src="https://cdn.jsdelivr.net/pyodide/v0.29.0/full/pyodide.js")
119121

120122
# 2. Bootstrap Script
121-
bootstrap = dedent("""
123+
bootstrap = dedent(
124+
"""
122125
async function main() {
123126
let pyodide = await loadPyodide();
124127
let response = await fetch("/_violetear/bundle.py");
125128
let code = await response.text();
126129
await pyodide.runPythonAsync(code);
127130
}
128131
main();
129-
""")
132+
"""
133+
)
130134

131135
doc.script(content=bootstrap)
132136

violetear/client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ def hydrate(namespace: dict):
2727
# We explicitly scan for common events.
2828
# In the future, we could inspect the DOM more aggressively or use a MutationObserver.
2929
supported_events = [
30-
"click", "change", "input", "submit",
31-
"keydown", "keyup", "mouseenter", "mouseleave"
30+
"click",
31+
"change",
32+
"input",
33+
"submit",
34+
"keydown",
35+
"keyup",
36+
"mouseenter",
37+
"mouseleave",
3238
]
3339

3440
bound_count = 0
@@ -61,6 +67,8 @@ def hydrate(namespace: dict):
6167

6268
bound_count += 1
6369
else:
64-
print(f"[Violetear] Warning: Function '{handler_name}' not found for event '{event_name}'")
70+
print(
71+
f"[Violetear] Warning: Function '{handler_name}' not found for event '{event_name}'"
72+
)
6573

6674
print(f"[Violetear] Hydrated {bound_count} interactive elements.")

0 commit comments

Comments
 (0)