Skip to content

Commit

Permalink
Set autoclass on reactive widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
laffra committed Nov 24, 2024
1 parent c101ab7 commit 67f2437
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ltk/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def debug(self, *args):
if self.DEBUG:
print(self.__class__.__name__, *args)

def _bind(self, attribute):
def bind(self, attribute):
""" Establish a binding between this Widget and a model """
def set_model_value(_=None):
attribute.set_value(self.get_value())
Expand All @@ -104,13 +104,14 @@ def set_widget_value(_=None):
self.set_value(attribute.get_value())

set_widget_value()
self.addClass(f"ltk-model-{attribute.model.__class__.__name__.lower()}-{attribute.name}")
attribute.listeners.append(set_widget_value)
self.on("change", proxy(lambda event: schedule(set_model_value, f"set model {self}")))

def set_value(self, value):
""" Set the value of the widget. """
if isinstance(value, ModelAttribute):
self._bind(value)
self.bind(value)
else:
self._set_value(value)

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.4"
version = "0.2.5"
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 67f2437

Please sign in to comment.