Skip to content

Commit

Permalink
When setting label/text, preserve   character.
Browse files Browse the repository at this point in the history
  • Loading branch information
laffra committed Nov 30, 2024
1 parent 26dc062 commit 8edbeb3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def open_popup(event):

widgets = [
ltk.HBox(
ltk.Div("Load a file:").css("margin-right", 8),
ltk.Label("Load a file:").css("margin-right", 8),
ltk.File(loaded_file),
),
ltk.VBox(
Expand Down
17 changes: 9 additions & 8 deletions ltk/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ def set_value(self, value):

def _set_value(self, value):
""" To be overridden by subclasses. """
self.element.text(value)
self.element.html(value)

def get_value(self):
""" Get the value of the widget. """
return self._get_value()

def _get_value(self):
""" To be overridden by subclasses. """
return self.element.text()
return self.element.html()

def css(self, prop, value=None):
"""
Expand Down Expand Up @@ -417,10 +417,10 @@ def __init__(self, value="", style=None):
self.set_value(value)

def _get_value(self):
return self.element.text()
return self.element.html()

def _set_value(self, value):
return self.element.text(value)
return self.element.html(value)


class Model():
Expand Down Expand Up @@ -730,14 +730,14 @@ def __init__(self, label, input_widget=None, style=None):
self.set_value(label)

def _get_value(self):
return self.element.text()
return self.element.html()

def _set_value(self, value):
if self.input_widget:
element = self.input_widget.element if isinstance(self.input_widget, Widget) else self.input_widget
self.element.empty().append(element, value)
else:
self.element.text(value)
self.element.html(value)


class Button(Widget):
Expand All @@ -755,7 +755,7 @@ def __init__(self, label:str, click, style=None):
style:dict [optional] CSS values to set on the element
"""
Widget.__init__(self, style or DEFAULT_CSS)
self.element.text(label)
self.element.html(label)
self.on("click", proxy(click))


Expand Down Expand Up @@ -1179,7 +1179,7 @@ class MenuLabel(Widget):

def __init__(self, label, style=None):
Widget.__init__(self, style or DEFAULT_CSS)
self.element.text(label)
self.element.html(label)


class Menu(Widget):
Expand Down Expand Up @@ -1299,6 +1299,7 @@ def _set_value(self, value):
self.set_selected_index(self.options.index(value))
except ValueError as e:
raise ValueError(f"Invalid value {value} for options {self.options}") from e

def _get_value(self):
return self.get_selected_index()

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.10"
version = "0.2.11"
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 8edbeb3

Please sign in to comment.