mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
precommit fixes
This commit is contained in:
@@ -2,6 +2,7 @@ import sys
|
|||||||
|
|
||||||
import js as globalThis
|
import js as globalThis
|
||||||
from polyscript import js_modules
|
from polyscript import js_modules
|
||||||
|
|
||||||
from pyscript.util import NotSupported
|
from pyscript.util import NotSupported
|
||||||
|
|
||||||
RUNNING_IN_WORKER = not hasattr(globalThis, "document")
|
RUNNING_IN_WORKER = not hasattr(globalThis, "document")
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from pyodide.ffi import to_js
|
from pyodide.ffi import to_js
|
||||||
|
|
||||||
from pyscript import window
|
from pyscript import window
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from pyscript import document, when, window
|
|
||||||
from pyweb import JSProperty, js_property, pydom
|
from pyweb import JSProperty, js_property, pydom
|
||||||
|
|
||||||
|
from pyscript import document, when, window
|
||||||
|
|
||||||
|
|
||||||
class ElementBase(pydom.Element):
|
class ElementBase(pydom.Element):
|
||||||
tag = "div"
|
tag = "div"
|
||||||
@@ -188,7 +189,7 @@ class div(TextElementBase):
|
|||||||
class img(ElementBase):
|
class img(ElementBase):
|
||||||
tag = "img"
|
tag = "img"
|
||||||
src = js_property("src")
|
src = js_property("src")
|
||||||
# TODO: This should probably go on the ElementBase class since it's a global attribtute
|
# TODO: This should probably go on the ElementBase class since it's a global attribute
|
||||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/slot
|
# https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/slot
|
||||||
slot = js_property("slot")
|
slot = js_property("slot")
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
"""Markdown module to generate web/HTML components from Markdown code"""
|
"""Markdown module to generate web/HTML components from Markdown code"""
|
||||||
from pyscript import document, window
|
|
||||||
from pyweb.ui.elements import TextElementBase
|
from pyweb.ui.elements import TextElementBase
|
||||||
|
|
||||||
|
from pyscript import document, window
|
||||||
|
|
||||||
|
|
||||||
class markdown(TextElementBase):
|
class markdown(TextElementBase):
|
||||||
"""Markdown component to render HTML from Markdown code"""
|
"""Markdown component to render HTML from Markdown code"""
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import string
|
import string
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from pyscript import document, when, window
|
|
||||||
from pyweb import JSProperty, js_property, pydom
|
from pyweb import JSProperty, js_property, pydom
|
||||||
from pyweb.ui import elements as el
|
from pyweb.ui import elements as el
|
||||||
|
|
||||||
|
from pyscript import document, when, window
|
||||||
|
|
||||||
|
|
||||||
class ShoeBase(pydom.Element):
|
class ShoeBase(pydom.Element):
|
||||||
tag = "div"
|
tag = "div"
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
from pyodide.ffi import create_proxy
|
from pyodide.ffi import create_proxy
|
||||||
from pyscript import display, document, when, window
|
|
||||||
from pyweb import media, pydom
|
from pyweb import media, pydom
|
||||||
|
|
||||||
|
from pyscript import display, document, when, window
|
||||||
|
|
||||||
devicesSelect = pydom["#devices"][0]
|
devicesSelect = pydom["#devices"][0]
|
||||||
video = pydom["video"][0]
|
video = pydom["video"][0]
|
||||||
devices = {}
|
devices = {}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import random
|
|||||||
import time
|
import time
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
|
|
||||||
from pyscript import display, when
|
|
||||||
from pyweb import pydom
|
from pyweb import pydom
|
||||||
|
|
||||||
|
from pyscript import display, when
|
||||||
|
|
||||||
|
|
||||||
@when("click", "#just-a-button")
|
@when("click", "#just-a-button")
|
||||||
def on_click():
|
def on_click():
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
print("tests starting")
|
print("tests starting")
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pyscript import window
|
from pyscript import window
|
||||||
|
|
||||||
args = window.location.search.replace("?", "").split("&")
|
args = window.location.search.replace("?", "").split("&")
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pyscript import document, when
|
|
||||||
from pyweb import pydom
|
from pyweb import pydom
|
||||||
|
|
||||||
|
from pyscript import document, when
|
||||||
|
|
||||||
|
|
||||||
class TestDocument:
|
class TestDocument:
|
||||||
def test__element(self):
|
def test__element(self):
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import examples
|
import examples
|
||||||
from pyscript import when, window
|
|
||||||
from pyweb import pydom
|
from pyweb import pydom
|
||||||
from pyweb.ui import elements as el
|
from pyweb.ui import elements as el
|
||||||
from pyweb.ui import shoelace
|
from pyweb.ui import shoelace
|
||||||
from pyweb.ui.markdown import markdown
|
from pyweb.ui.markdown import markdown
|
||||||
|
|
||||||
|
from pyscript import when, window
|
||||||
|
|
||||||
# Style dictionary for code blocks
|
# Style dictionary for code blocks
|
||||||
STYLE_CODE_BLOCK = {"text-align": "left", "background-color": "#eee", "padding": "20px"}
|
STYLE_CODE_BLOCK = {"text-align": "left", "background-color": "#eee", "padding": "20px"}
|
||||||
|
|
||||||
@@ -27,29 +28,37 @@ def create_component_details(component):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
# Get the example from the examples catalog
|
# Get the example from the examples catalog
|
||||||
examples_gallery = examples.kits['shoelace']
|
examples_gallery = examples.kits["shoelace"]
|
||||||
example = examples_gallery[component]["instance"]
|
example = examples_gallery[component]["instance"]
|
||||||
details = example.__doc__ or f"Details missing for component {component}"
|
details = example.__doc__ or f"Details missing for component {component}"
|
||||||
|
|
||||||
div = el.div([
|
div = el.div(
|
||||||
# Title and description (description is picked from the class docstring)
|
[
|
||||||
el.h1(component),
|
# Title and description (description is picked from the class docstring)
|
||||||
markdown(details),
|
el.h1(component),
|
||||||
# Example section
|
markdown(details),
|
||||||
el.h2("Example:"),
|
# Example section
|
||||||
el.div([
|
el.h2("Example:"),
|
||||||
example,
|
el.div(
|
||||||
shoelace.Details(
|
[
|
||||||
el.div(examples_gallery[component]["code"], style=STYLE_CODE_BLOCK),
|
example,
|
||||||
summary="View Code", style={"background-color": "gainsboro"},
|
shoelace.Details(
|
||||||
),
|
el.div(
|
||||||
],
|
examples_gallery[component]["code"], style=STYLE_CODE_BLOCK
|
||||||
style={
|
),
|
||||||
"border-radius": "3px",
|
summary="View Code",
|
||||||
"background-color": "var(--sl-color-neutral-50)",
|
style={"background-color": "gainsboro"},
|
||||||
"margin-bottom": "1.5rem"
|
),
|
||||||
}
|
],
|
||||||
)], style={"margin": "20px"})
|
style={
|
||||||
|
"border-radius": "3px",
|
||||||
|
"background-color": "var(--sl-color-neutral-50)",
|
||||||
|
"margin-bottom": "1.5rem",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
style={"margin": "20px"},
|
||||||
|
)
|
||||||
return div
|
return div
|
||||||
|
|
||||||
|
|
||||||
@@ -68,12 +77,14 @@ def add_component_section(component, parent_div):
|
|||||||
el.a(component, href="#"),
|
el.a(component, href="#"),
|
||||||
style={"display": "block", "text-align": "center", "margin": "auto"},
|
style={"display": "block", "text-align": "center", "margin": "auto"},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a handler that opens the component details when the link is clicked
|
# Create a handler that opens the component details when the link is clicked
|
||||||
@when("click", div)
|
@when("click", div)
|
||||||
def _change():
|
def _change():
|
||||||
new_main = create_component_details(component)
|
new_main = create_component_details(component)
|
||||||
main_area.html = ""
|
main_area.html = ""
|
||||||
main_area.append(new_main)
|
main_area.append(new_main)
|
||||||
|
|
||||||
# Add the new link element to the parent div (left panel)
|
# Add the new link element to the parent div (left panel)
|
||||||
parent_div.append(div)
|
parent_div.append(div)
|
||||||
return div
|
return div
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from pyscript import when
|
|
||||||
from pyweb import pydom
|
from pyweb import pydom
|
||||||
from pyweb.ui import elements as el
|
from pyweb.ui import elements as el
|
||||||
from pyweb.ui.shoelace import (
|
from pyweb.ui.shoelace import (
|
||||||
@@ -12,6 +11,8 @@ from pyweb.ui.shoelace import (
|
|||||||
Rating,
|
Rating,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from pyscript import when
|
||||||
|
|
||||||
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
||||||
details_code = """
|
details_code = """
|
||||||
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import js
|
|||||||
js.document.body.append("document patch ")
|
js.document.body.append("document patch ")
|
||||||
|
|
||||||
import a
|
import a
|
||||||
|
|
||||||
from pyscript import RUNNING_IN_WORKER, display, sync
|
from pyscript import RUNNING_IN_WORKER, display, sync
|
||||||
|
|
||||||
display("Hello World", target="test", append=True)
|
display("Hello World", target="test", append=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user