mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
lint
This commit is contained in:
@@ -60,6 +60,7 @@ def js_property(name: str, allow_nones: bool = False):
|
||||
Returns:
|
||||
the property created
|
||||
"""
|
||||
|
||||
class CustomProperty(JSProperty):
|
||||
def __get__(self, obj, objtype=None):
|
||||
return getattr(obj._js, name)
|
||||
@@ -163,7 +164,6 @@ class Element(BaseElement):
|
||||
def html(self, value):
|
||||
self._js.innerHTML = value
|
||||
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return self._js.textContent
|
||||
|
||||
@@ -24,7 +24,7 @@ GLOBAL_ATTRIBUTES = [
|
||||
"title",
|
||||
"translate",
|
||||
"virtualkeyboardpolicy",
|
||||
"className"
|
||||
"className",
|
||||
]
|
||||
|
||||
# class and style are different ones that are handled by pydom.element directly
|
||||
@@ -82,7 +82,7 @@ def _add_js_properties(cls, *attrs):
|
||||
# First we set all the global properties as JSProperties
|
||||
for attr in GLOBAL_ATTRIBUTES:
|
||||
setattr(cls, attr, js_property(attr))
|
||||
|
||||
|
||||
# Now the specific class properties
|
||||
for attr in attrs:
|
||||
setattr(cls, attr, js_property(attr))
|
||||
@@ -262,8 +262,10 @@ class br(ElementBase):
|
||||
class div(TextElementBase):
|
||||
tag = "div"
|
||||
|
||||
|
||||
_add_js_properties(div)
|
||||
|
||||
|
||||
class img(ElementBase):
|
||||
tag = "img"
|
||||
src = js_property("src")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from textwrap import dedent
|
||||
|
||||
import examples
|
||||
import styles
|
||||
from pyweb import pydom
|
||||
from pyweb.ui import elements as el
|
||||
from pyweb.ui import shoelace
|
||||
@@ -7,9 +9,6 @@ from pyweb.ui.markdown import markdown
|
||||
|
||||
from pyscript import when, window
|
||||
|
||||
import styles
|
||||
import examples
|
||||
|
||||
MAIN_PAGE_MARKDOWN = dedent(
|
||||
"""
|
||||
## What is pyweb.ui?
|
||||
@@ -58,7 +57,8 @@ def create_component_details(component):
|
||||
example,
|
||||
shoelace.Details(
|
||||
el.div(
|
||||
examples_gallery[component]["code"], style=styles.STYLE_CODE_BLOCK
|
||||
examples_gallery[component]["code"],
|
||||
style=styles.STYLE_CODE_BLOCK,
|
||||
),
|
||||
summary="View Code",
|
||||
style={"background-color": "gainsboro"},
|
||||
@@ -137,7 +137,7 @@ def create_main_area():
|
||||
"""
|
||||
div = el.div(
|
||||
[
|
||||
el.h1("Welcome to PyDom UI!", style={"text-align": "center"}),
|
||||
el.h1("Welcome to PyWeb UI!", style={"text-align": "center"}),
|
||||
markdown(MAIN_PAGE_MARKDOWN),
|
||||
]
|
||||
)
|
||||
@@ -199,8 +199,10 @@ def create_basic_components_page():
|
||||
btn = el.button("Click me!")
|
||||
when("click", btn)(lambda: window.alert("Clicked!"))
|
||||
|
||||
btn_code = dedent("""btn = button("Click me!")
|
||||
when('click', btn)(lambda: window.alert("Clicked!"))""")
|
||||
btn_code = dedent(
|
||||
"""btn = button("Click me!")
|
||||
when('click', btn)(lambda: window.alert("Clicked!"))"""
|
||||
)
|
||||
|
||||
div.append(create_component_example(btn, btn_code))
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
from textwrap import dedent
|
||||
import inspect
|
||||
from textwrap import dedent
|
||||
|
||||
import styles
|
||||
import tictactoe
|
||||
from pyweb import pydom
|
||||
from pyweb.ui import elements as el
|
||||
from pyweb.ui import shoelace
|
||||
from pyweb.ui.markdown import markdown
|
||||
|
||||
from pyscript import when, window
|
||||
import tictactoe
|
||||
import styles
|
||||
|
||||
MAIN_PAGE_MARKDOWN = dedent(
|
||||
"""
|
||||
@@ -48,7 +49,7 @@ def add_demo(demo_name, demo_creator_cb, parent_div, source=None):
|
||||
demo_div.append(el.div(widget_code, style=styles.STYLE_CODE_BLOCK))
|
||||
else:
|
||||
demo_div = demo_creator_cb()
|
||||
demo_div.style['margin'] = '20px'
|
||||
demo_div.style["margin"] = "20px"
|
||||
write_to_main(demo_div)
|
||||
window.hljs.highlightAll()
|
||||
|
||||
@@ -56,6 +57,7 @@ def add_demo(demo_name, demo_creator_cb, parent_div, source=None):
|
||||
parent_div.append(div)
|
||||
return div
|
||||
|
||||
|
||||
def create_main_area():
|
||||
"""Create the main area of the right side of page, with the description of the
|
||||
demo itself and how to use it.
|
||||
@@ -64,10 +66,12 @@ def create_main_area():
|
||||
the main area
|
||||
|
||||
"""
|
||||
return el.div([
|
||||
el.h1("PyWeb UI Galler", style={"text-align": "center"}),
|
||||
return el.div(
|
||||
[
|
||||
el.h1("PyWeb UI Gallery", style={"text-align": "center"}),
|
||||
markdown(MAIN_PAGE_MARKDOWN),
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def create_markdown_app():
|
||||
@@ -80,16 +84,20 @@ def create_markdown_app():
|
||||
translate_button = shoelace.Button("Convert", variant="primary")
|
||||
markdown_txt_area = shoelace.TextArea(label="Use this to write your Markdown")
|
||||
result_div = el.div(style=styles.STYLE_MARKDOWN_RESULT)
|
||||
|
||||
@when("click", translate_button)
|
||||
def translate_markdown():
|
||||
result_div.html = markdown(markdown_txt_area.value).html
|
||||
|
||||
return el.div([
|
||||
return el.div(
|
||||
[
|
||||
el.h2("Markdown"),
|
||||
markdown_txt_area,
|
||||
translate_button,
|
||||
result_div,
|
||||
], style={"margin": "20px"})
|
||||
],
|
||||
style={"margin": "20px"},
|
||||
)
|
||||
|
||||
|
||||
# ********** MAIN PANEL **********
|
||||
@@ -147,8 +155,13 @@ el.div([
|
||||
result_div,
|
||||
])
|
||||
"""
|
||||
add_demo("Markdown", create_markdown_app, left_div, source = markdown_source)
|
||||
add_demo("Tic Tac Toe", tictactoe.create_tic_tac_toe, left_div, source=inspect.getsource(tictactoe))
|
||||
add_demo("Markdown", create_markdown_app, left_div, source=markdown_source)
|
||||
add_demo(
|
||||
"Tic Tac Toe",
|
||||
tictactoe.create_tic_tac_toe,
|
||||
left_div,
|
||||
source=inspect.getsource(tictactoe),
|
||||
)
|
||||
|
||||
# ********** CREATE ALL THE LAYOUT **********
|
||||
grid = el.Grid("minmax(100px, 200px) 20px auto", style={"min-height": "100%"})
|
||||
@@ -156,4 +169,4 @@ grid.append(left_div)
|
||||
grid.append(shoelace.Divider(vertical=True))
|
||||
grid.append(main_area)
|
||||
|
||||
pydom.body.append(grid)
|
||||
pydom.body.append(grid)
|
||||
|
||||
Reference in New Issue
Block a user