Skip to content

Commit 437999c

Browse files
committed
Handle element mapping on PyOdide
1 parent d36228f commit 437999c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

ltk/ltk.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@
134134
return elementBottom > viewportTop && elementTop < viewportBottom;
135135
};
136136

137-
window.ltk_widgets = {};
137+
window.getWidget = function(id) {
138+
return undefined;
139+
};
138140

139141
$.fn.widget = function() {
140-
return window.ltk_widgets[$(this).attr("ltk_id")];
142+
return window.getWidget($(this))
141143
};
142144

143145
// change the following to your own development root location

ltk/widgets.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ def get_caller(cls):
113113
frame = frame.f_back
114114

115115

116+
widgets = {}
117+
window.getWidget = proxy(lambda element: widgets[element.attr("ltk_id")])
118+
119+
116120
class Widget(object):
117121
"""Base class for LTK widgets."""
118122
classes = []
@@ -141,8 +145,9 @@ def __init__(self, *args):
141145
.addClass(" ".join(self.classes))
142146
.append(*self._flatten(args))
143147
)
144-
window.ltk_widgets[id(self)] = self
145-
self.attr("ltk_id", id(self))
148+
widgets[str(id(self))] = self
149+
self.attr("ltk_id", str(id(self)))
150+
window.console.log("add widget", self.element, self.attr("ltk_id"))
146151
self._handle_css(args)
147152
if Widget.INSPECT:
148153
self.on("mousemove", proxy(lambda event: self._on_mousemove(event)))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "pyscript-ltk"
9-
version = "0.2.16"
9+
version = "0.2.17"
1010
description = "A little toolkit for writing UIs in PyScript"
1111
readme = "README.md"
1212
authors = [{ name = "Chris Laffra", email = "[email protected]" }]

0 commit comments

Comments
 (0)