Skip to content

Commit bde028b

Browse files
committed
Add support for MVC and fix pylint errors
1 parent 4e8a4ee commit bde028b

File tree

14 files changed

+596
-418
lines changed

14 files changed

+596
-418
lines changed

examples/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from examples import app
44
from examples import canvas
55
from examples import custom
6-
from examples import editor
76
from examples import dom
7+
from examples import editor
88
from examples import inputs
9+
from examples import mvc
910
from examples import pitch
1011
from examples import pizza
1112
from examples import splits
@@ -14,9 +15,9 @@
1415
from examples import svg
1516
from examples import table
1617
from examples import tictactoe
17-
from examples import tutorial
1818

1919
items = [
20+
("examples/mvc.py", mvc.create()),
2021
("examples/styling.py", styling.create()),
2122
("examples/dom.py", dom.create()),
2223
("examples/inputs.py", inputs.create()),
@@ -31,5 +32,4 @@
3132
("examples/canvas.py", canvas.create()),
3233
("examples/pizza.py", pizza.create()),
3334
("examples/splits.py", splits.create()),
34-
("examples/tutorial.py", tutorial.create()),
3535
]

examples/dom.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,34 @@ def get_color():
1111
return color
1212

1313
def new_text():
14-
return ltk.Text(f"Text created at {ltk.get_time()}s", {
15-
"color": "white",
16-
"background-color": get_color(),
17-
})
14+
return ltk.Text(f"Text created at {ltk.get_time()}s") \
15+
.css("color", "white") \
16+
.css("background-color", get_color())
1817

1918
def append(event):
2019
# the base class for LTK Widgets sends all methods it does not
2120
# understand to its jQuery element. This also happens to the "append"
2221
# call below. As jQuery does not know anything about LTK, it expects
2322
# a list of other jQuery elements to be passed to it. Therefore, we
2423
# append the widget's element, not the widget itself.
25-
ltk.find("#dom-texts").append(new_text().element)
24+
ltk.find("#dom-texts").append(new_text())
2625

2726
def append_to(event):
2827
new_text().appendTo(ltk.find("#dom-texts"))
2928

3029
def prepend(event):
31-
ltk.find("#dom-texts").prepend(new_text().element)
30+
ltk.find("#dom-texts").prepend(new_text())
3231

3332
def after(event):
34-
ltk.find("#dom-texts .ltk-text").eq(0).after(new_text().element)
33+
ltk.find("#dom-texts .ltk-text").eq(0).after(new_text())
3534

3635
def before(event):
37-
ltk.find("#dom-texts .ltk-text").eq(1).before(new_text().element)
36+
ltk.find("#dom-texts .ltk-text").eq(1).before(new_text())
3837

3938
def append_two(event):
4039
ltk.find("#dom-texts").append(
41-
new_text().element,
42-
new_text().element,
40+
new_text(),
41+
new_text(),
4342
)
4443

4544
def append_html(event):

examples/inputs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ def loveit(event):
3535

3636
@ltk.callback
3737
def change(event):
38-
element = ltk.jQuery(event.target)
38+
element = ltk.find(event.target)
3939
kind = element.prop("type")
4040
feedback(f"Changed {kind}: {element.val()}")
4141

4242
@ltk.callback
4343
def switched(event):
44-
element = ltk.jQuery(event.target)
44+
element = ltk.find(event.target)
4545
feedback(f"Changed switch: {element.prop('checked')}")
4646

4747
@ltk.callback
4848
def set_runtime(event):
49-
chosen = ltk.jQuery(event.target).attr("value")
49+
chosen = ltk.find(event.target).attr("value")
5050
if chosen != runtime:
5151
window.setSearchParameter("runtime", chosen)
5252

examples/mvc.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# LTK - Copyright 2023 - All Rights Reserved - chrislaffra.com - See LICENSE
2+
3+
import ltk
4+
5+
class Product(ltk.Model):
6+
""" This is a model with two fields """
7+
name: str = ""
8+
price: float = 0.0
9+
10+
product = Product()
11+
12+
def clear(event):
13+
product.name = ""
14+
15+
def create():
16+
return (
17+
ltk.VBox(
18+
ltk.Heading2("LTK Model-View Demo"),
19+
20+
ltk.Label("Product Name (as ltk.Input):"),
21+
ltk.Input(product.name)
22+
.attr("placeholder", "Please enter a name")
23+
.css("border", "2px solid red"),
24+
25+
ltk.Break(),
26+
27+
ltk.Label("Product Name (as ltk.Text):"),
28+
ltk.Text(product.name)
29+
.css("border", "2px solid green")
30+
.css("height", 34),
31+
32+
ltk.Break(),
33+
ltk.Button("Clear product.name", ltk.proxy(clear)),
34+
)
35+
.css("font-size", 24)
36+
.attr("name", "MVC")
37+
)

examples/tictactoe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def choose(event):
1414
@ltk.callback
1515
def enter(event):
1616
ltk.find(".tictactoe-inside").removeClass("tictactoe-inside")
17-
if not ltk.jQuery(event.target).text():
18-
ltk.jQuery(event.target).addClass("tictactoe-inside")
17+
if not ltk.find(event.target).text():
18+
ltk.find(event.target).addClass("tictactoe-inside")
1919

2020
return (
2121
ltk.VBox(

examples/tutorial.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

kitchensink.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ function startTime() {
3030
}
3131

3232
setupRuntime()
33-
setupToggle()
34-
35-
pyodide.setDebug(true)
33+
setupToggle()

kitchensink.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ files = [
2323
"examples/pubsub.py",
2424
"examples/table.py",
2525
"examples/svg.py",
26-
"examples/tutorial.py",
26+
"examples/mvc.py",
2727
]

ltk/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# LTK - Copyright 2023 - All Rights Reserved - chrislaffra.com - See LICENSE
1+
"""
2+
Copyright 2023 - All Rights Reserved - chrislaffra.com - See LICENSE
3+
4+
LTK (Little Toolkit) is a library for building client-side web applications using Python and CSS.
5+
"""
26

37
from ltk.jquery import *
48
from ltk.widgets import *
59
from ltk.pubsub import *
610
from ltk.logger import *
711

812
(
9-
ltk.Link("https://github.com/laffra/ltk", "built with LTK")
13+
ltk.Link("https://github.com/pyscript/ltk", "built with LTK")
1014
.addClass("ltk-built-with")
1115
.attr("target", "_blank")
12-
.appendTo(jQuery(window.document.body))
13-
)
16+
.appendTo(window.jQuery(window.document.body))
17+
)

0 commit comments

Comments
 (0)