-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4524180
commit 539fcc0
Showing
4 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import sys | ||
import threading | ||
from time import sleep | ||
from pathlib import Path | ||
|
||
import click | ||
import os | ||
|
||
# make sure you use pyside when distributing your all without having to use a GPL license | ||
from qtpy.QtWidgets import QApplication | ||
from qtpy.QtWebEngineWidgets import QWebEngineView | ||
from qtpy import QtCore | ||
|
||
|
||
HERE = Path(__file__).parent | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--port", | ||
default=int(os.environ.get("PORT", 0)), | ||
help="Port to run the server on, 0 for a random free port", | ||
) | ||
def run(port: int): | ||
sys.path.append(str(HERE)) | ||
os.environ["SOLARA_APP"] = "test_app" | ||
import test_app | ||
|
||
import solara.server.starlette | ||
|
||
server = solara.server.starlette.ServerStarlette(host="localhost", port=port) | ||
print(f"Starting server on {server.base_url}") | ||
server.serve_threaded() | ||
server.wait_until_serving() | ||
|
||
def test_success(value): | ||
print("test output", value) | ||
app.quit() | ||
server.stop_serving() | ||
|
||
test_app.callback = test_success # type: ignore | ||
|
||
failed = False | ||
|
||
def fail_guard(): | ||
sleep(10) | ||
nonlocal failed | ||
print("failed") | ||
app.quit() | ||
failed = True | ||
|
||
app = QApplication([""]) | ||
web = QWebEngineView() | ||
web.setUrl(QtCore.QUrl(server.base_url)) | ||
web.show() | ||
|
||
threading.Thread(target=fail_guard, daemon=True).start() | ||
app.exec_() | ||
if failed: | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import solara | ||
|
||
|
||
def callback(event): | ||
print("Event received:", event) | ||
|
||
|
||
@solara.component_vue("test_pywebview.vue") | ||
def TestPywebview(event_callback): | ||
pass | ||
|
||
|
||
@solara.component | ||
def Page(): | ||
TestPywebview(event_callback=callback) | ||
# html = "<script>pywebview.api.test(\"Test passes!\")</script>Script tag inserted" | ||
# solara.HTML(unsafe_innerHTML=html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<div>This component should call back to Python</div> | ||
</template> | ||
<script> | ||
module.exports = { | ||
mounted() { | ||
console.log("mounted") | ||
this.callback() | ||
} | ||
} | ||
</script> |