Skip to content

Commit

Permalink
Handle element mapping on PyOdide
Browse files Browse the repository at this point in the history
  • Loading branch information
laffra committed Dec 13, 2024
1 parent d36228f commit 437999c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions ltk/ltk.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@
return elementBottom > viewportTop && elementTop < viewportBottom;
};

window.ltk_widgets = {};
window.getWidget = function(id) {
return undefined;
};

$.fn.widget = function() {
return window.ltk_widgets[$(this).attr("ltk_id")];
return window.getWidget($(this))
};

// change the following to your own development root location
Expand Down
9 changes: 7 additions & 2 deletions ltk/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def get_caller(cls):
frame = frame.f_back


widgets = {}
window.getWidget = proxy(lambda element: widgets[element.attr("ltk_id")])


class Widget(object):
"""Base class for LTK widgets."""
classes = []
Expand Down Expand Up @@ -141,8 +145,9 @@ def __init__(self, *args):
.addClass(" ".join(self.classes))
.append(*self._flatten(args))
)
window.ltk_widgets[id(self)] = self
self.attr("ltk_id", id(self))
widgets[str(id(self))] = self
self.attr("ltk_id", str(id(self)))
window.console.log("add widget", self.element, self.attr("ltk_id"))
self._handle_css(args)
if Widget.INSPECT:
self.on("mousemove", proxy(lambda event: self._on_mousemove(event)))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyscript-ltk"
version = "0.2.16"
version = "0.2.17"
description = "A little toolkit for writing UIs in PyScript"
readme = "README.md"
authors = [{ name = "Chris Laffra", email = "chris@chrislaffra.com" }]
Expand Down

0 comments on commit 437999c

Please sign in to comment.