fixed some little things
This commit is contained in:
parent
092ecff9ba
commit
541673f81b
Binary file not shown.
@ -4,7 +4,6 @@ import uuid
|
|||||||
from js import document, CanvasRenderingContext2D # type: ignore
|
from js import document, CanvasRenderingContext2D # type: ignore
|
||||||
from pyodide import create_proxy # type: ignore
|
from pyodide import create_proxy # type: ignore
|
||||||
from parse import *
|
from parse import *
|
||||||
import numpy as np
|
|
||||||
import base64
|
import base64
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
from io import BytesIO, StringIO
|
from io import BytesIO, StringIO
|
||||||
@ -1113,7 +1112,7 @@ class IFrame(Element):
|
|||||||
class Image(Element):
|
class Image(Element):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_numpy_array(cls, m:np.ndarray, format="PNG", **kwargs):
|
def from_numpy_array(cls, m:"np.ndarray", format="PNG", **kwargs):
|
||||||
if format.upper() == "JPG":
|
if format.upper() == "JPG":
|
||||||
format = "JPEG"
|
format = "JPEG"
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
from typing import Dict, List, Union, Callable
|
from typing import Dict, List, Union, Callable
|
||||||
|
|
||||||
import HTML
|
from . import HTML
|
||||||
|
|
||||||
from bootstrap_HTML_container import *
|
from .bootstrap_HTML_container import *
|
||||||
from js import bootstrap # type: ignore
|
from js import bootstrap # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import HTML
|
from . import HTML
|
||||||
|
|
||||||
# Base Container Class: -------------------------------------------------------
|
# Base Container Class: -------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import datetime as dt
|
import datetime as dt
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from bootstrap_HTML import *
|
from .bootstrap_HTML import *
|
||||||
from js import document, FileReader, btoa # type: ignore
|
from js import document, FileReader, btoa # type: ignore
|
||||||
from pyodide import create_proxy # type: ignore
|
from pyodide import create_proxy # type: ignore
|
||||||
import io
|
import io
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import HTML
|
from . import HTML
|
||||||
import bootstrap_HTML as bHTML
|
from . import bootstrap_HTML as bHTML
|
||||||
from js import document # type: ignore
|
from js import document # type: ignore
|
||||||
|
|
||||||
class PyScriptBootstrapApp(object):
|
class PyScriptBootstrapApp(object):
|
||||||
|
@ -2,18 +2,28 @@
|
|||||||
import pathlib
|
import pathlib
|
||||||
from typing import List
|
from typing import List
|
||||||
import argparse
|
import argparse
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def download_file(url: str, path: pathlib.Path):
|
||||||
|
response = requests.get(url)
|
||||||
|
path.write_bytes(response.content)
|
||||||
|
|
||||||
# create a new pyscript project
|
# create a new pyscript project
|
||||||
|
|
||||||
|
|
||||||
def create_project(root_folder: pathlib.Path,
|
def create_project(root_folder: pathlib.Path,
|
||||||
title: str,
|
title: str,
|
||||||
packages: List[str],
|
packages: List[str],
|
||||||
paths: List[str] = None,
|
paths: List[str] = None,
|
||||||
pyscript_css_url: str = "https://pyscript.net/alpha/pyscript.css",
|
pyscript_css_url: str = "https://pyscript.net/alpha/pyscript.css",
|
||||||
pyscript_js_url: str = "https://pyscript.net/alpha/pyscript.js"):
|
pyscript_js_url: str = "https://pyscript.net/alpha/pyscript.min.js",
|
||||||
|
pyscript_py_url: str = "https://pyscript.net/alpha/pyscript.py",
|
||||||
|
bootstrap_css_url: str = "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css",
|
||||||
|
bootstrap_js_url: str = "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js",
|
||||||
|
pyscript_bootstrap_templates_wheel_url: str = "https://the-cake-is-a-lie.net/gogs/jonas/pyscript-bootstrap-templates/raw/branch/main/dist/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl"):
|
||||||
|
|
||||||
pyenv = "- git+https://the-cake-is-a-lie.net/gogs/jonas/pyscript-bootstrap-templates.git"
|
pyenv = f"- ./resources/{pyscript_bootstrap_templates_wheel_url.split('/')[-1]}"
|
||||||
for package in packages:
|
for package in packages:
|
||||||
pyenv += f"\n - {package}"
|
pyenv += f"\n - {package}"
|
||||||
|
|
||||||
@ -33,36 +43,60 @@ def create_project(root_folder: pathlib.Path,
|
|||||||
|
|
||||||
|
|
||||||
<!-- Bootstrap CSS -->
|
<!-- Bootstrap CSS -->
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
<link href="./resources/bootstrap.css">
|
||||||
|
|
||||||
<link rel="stylesheet" href="{pyscript_css_url}" />
|
<link rel="stylesheet" href="./resources/pyscript.css" />
|
||||||
<script defer src="{pyscript_js_url}"></script>
|
<script defer src="./resources/pyscript.js"></script>
|
||||||
|
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
|
|
||||||
<py-env>
|
<py-env>
|
||||||
{pyenv}
|
{pyenv}
|
||||||
</py-env>
|
</py-env>
|
||||||
</head>
|
</head>
|
||||||
<body style="width: 100%; height: 100%">
|
<body style="width: 100%; height: 100%">
|
||||||
<div id="simple_app" style="height: 100%; min-height: 100%"></div>
|
<div id="pyscript_app" style="height: 100%; min-height: 100%"></div>
|
||||||
<py-script src="./main.py"></py-script>
|
<py-script src="./main.py"></py-script>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
<script src="./resources/bootstrap.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
py = f"""
|
py = f"""
|
||||||
|
from pyscript_bootstrap_templates import bootstrap_templates
|
||||||
|
from pyscript_bootstrap_templates import bootstrap_HTML as bHTML
|
||||||
|
from pyscript_bootstrap_templates import HTML as HTML
|
||||||
|
|
||||||
|
app = bootstrap_templates.PyScriptBootstrapDashboard(
|
||||||
|
parent_element="pyscript_app", brand_name="{title}")
|
||||||
|
div = bHTML.BootstrapContainer("This is a sidebar", parent=app.sidebar)
|
||||||
|
div.font_size = 4
|
||||||
|
|
||||||
|
btn = bHTML.ButtonPrimary("Click me", parent=app.sidebar)
|
||||||
|
btn.w = 100
|
||||||
|
btn.onclick = lambda _: bHTML.AlertSuccess(
|
||||||
|
"You clicked me!", parent=app.main_area)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not root_folder.exists():
|
if root_folder.exists():
|
||||||
root_folder.mkdir(parents=True)
|
raise("Value Error: root_folder already exists. Please choose a different name.")
|
||||||
|
|
||||||
|
root_folder.mkdir(parents=True)
|
||||||
|
(root_folder / "resources").mkdir(parents=True)
|
||||||
|
|
||||||
|
# Download files:
|
||||||
|
download_file(pyscript_css_url, root_folder / "resources" / "pyscript.css")
|
||||||
|
download_file(pyscript_js_url, root_folder / "resources" / "pyscript.js")
|
||||||
|
download_file(pyscript_py_url, root_folder / "resources" / "pyscript.py")
|
||||||
|
download_file(bootstrap_css_url, root_folder /
|
||||||
|
"resources" / "bootstrap.css")
|
||||||
|
download_file(bootstrap_js_url, root_folder / "resources" / "bootstrap.js")
|
||||||
|
download_file(pyscript_bootstrap_templates_wheel_url,
|
||||||
|
root_folder / "resources" / pyscript_bootstrap_templates_wheel_url.split("/")[-1])
|
||||||
|
|
||||||
(root_folder / "index.html").write_text(html, encoding="utf-8")
|
(root_folder / "index.html").write_text(html, encoding="utf-8")
|
||||||
(root_folder / "main.py").write_text("", encoding="utf-8")
|
(root_folder / "main.py").write_text(py, encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -80,16 +114,20 @@ def main():
|
|||||||
argument_parser.add_argument("--pyscript_css_url", type=str,
|
argument_parser.add_argument("--pyscript_css_url", type=str,
|
||||||
help="the url of the pyscript css file", default="https://pyscript.net/alpha/pyscript.css")
|
help="the url of the pyscript css file", default="https://pyscript.net/alpha/pyscript.css")
|
||||||
argument_parser.add_argument("--pyscript_js_url", type=str,
|
argument_parser.add_argument("--pyscript_js_url", type=str,
|
||||||
help="the url of the pyscript js file", default="https://pyscript.net/alpha/pyscript.js")
|
help="the url of the pyscript js file", default="https://pyscript.net/alpha/pyscript.min.js")
|
||||||
arguments = argument_parser.parse_args()
|
argument_parser.add_argument("--pyscript_py_url", type=str,
|
||||||
|
help="the url of the pyscript py file", default="https://pyscript.net/alpha/pyscript.py")
|
||||||
|
argument_parser.add_argument("--bootstrap_css_url", type=str,
|
||||||
|
help="the url of the bootstrap css file", default="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css")
|
||||||
|
argument_parser.add_argument("--bootstrap_js_url", type=str,
|
||||||
|
help="the url of the bootstrap js file", default="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js")
|
||||||
|
argument_parser.add_argument("--pyscript_bootstrap_templates_wheel_url", type=str,
|
||||||
|
help="the url of the pyscript bootstrap templates wheel file", default="https://the-cake-is-a-lie.net/gogs/jonas/pyscript-bootstrap-templates/raw/branch/main/dist/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl")
|
||||||
|
|
||||||
create_project(arguments.root_folder,
|
args = argument_parser.parse_args()
|
||||||
arguments.title,
|
|
||||||
arguments.packages,
|
create_project(args.root_folder, args.title, args.packages, args.paths, args.pyscript_css_url, args.pyscript_js_url, args.pyscript_py_url, args.bootstrap_css_url, args.bootstrap_js_url, args.pyscript_bootstrap_templates_wheel_url)
|
||||||
arguments.paths,
|
|
||||||
arguments.pyscript_css_url,
|
|
||||||
arguments.pyscript_js_url)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user