diff --git a/examples/custom.py b/examples/custom.py index afb8131..35acde4 100644 --- a/examples/custom.py +++ b/examples/custom.py @@ -11,7 +11,7 @@ def __init__(self, src, label): ltk.Image(src).width(196), ltk.Text(label).width("100%").css("text-align", "center") ) - self.element.css("border", "2px solid orange") + self.css("border", "2px solid orange") return ( diff --git a/examples/pubsub.py b/examples/pubsub.py index d0f81c8..cabdbb9 100644 --- a/examples/pubsub.py +++ b/examples/pubsub.py @@ -2,6 +2,11 @@ import ltk import random +from polyscript import XWorker + +print("launch worker") +worker = XWorker("/examples/worker.py", config="/examples/worker.toml", type="micropython") +print("worker", worker) fan = ltk.Preformatted("") @@ -18,6 +23,7 @@ def publish(event=None): ]) ltk.publish( "Influencer", # the sender + "Fan", # the intended receiver "message", # the subscription topic message # the message to send ) @@ -34,6 +40,7 @@ def create(): ltk.Important("What every fan sees:"), ltk.HBox( fan + .attr("id", "fan") .css("border", "1px solid gray") .css("overflow", "hidden") .width(200) diff --git a/examples/worker.py b/examples/worker.py new file mode 100644 index 0000000..07250c1 --- /dev/null +++ b/examples/worker.py @@ -0,0 +1,12 @@ +import ltk +from polyscript import xworker # type: ignore + +ltk.find("#fan").append("Worker is running...") + +subscribe = xworker.sync.subscribe +publish = xworker.sync.publish + +def handle_message(message): + ltk.find("#fan").append(message) + +subscribe("Worker-Fan", "message", handle_message) \ No newline at end of file diff --git a/examples/worker.toml b/examples/worker.toml new file mode 100644 index 0000000..e69de29 diff --git a/ltk/jquery.py b/ltk/jquery.py index 14a4572..1a77a7c 100644 --- a/ltk/jquery.py +++ b/ltk/jquery.py @@ -123,8 +123,13 @@ def push_state(url): window.history.pushState(None, "", url) -def inject_script(url): - create("