Skip to content

Commit 970a7cc

Browse files
committed
Add sub-elements of Text
1 parent b4d05c1 commit 970a7cc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ltk/widgets.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self, *args):
4949
.append(*self._flatten(args))
5050
)
5151
self._handle_css(args)
52+
args = self._flatten(args)
5253

5354
def _handle_css(self, args):
5455
"""Apply CSS styles passed in the args to the widget.
@@ -364,7 +365,7 @@ def __getattr__(self, name):
364365
try:
365366
return getattr(self.element, name)
366367
except Exception as e:
367-
raise AttributeError(f"ltk.{self.__class__.__name__} does not have attribute {name}") from e
368+
raise AttributeError(f"Widget {self.__class__.__name__} does not have attribute {name}") from e
368369

369370
def toJSON(self, *args): # pylint: disable=invalid-name
370371
""" Return a JSON representation of the widget """
@@ -737,7 +738,8 @@ class Link(Text):
737738
tag = "a"
738739

739740
def __init__(self, href, *items):
740-
Text.__init__(self, *items)
741+
Text.__init__(self)
742+
self.append(*items)
741743
self.attr("href", href)
742744
self.attr("target", "_blank")
743745

@@ -941,13 +943,13 @@ class TableRow(Widget):
941943
tag = "tr"
942944

943945

944-
class TableHeader(Text):
946+
class TableHeader(Widget):
945947
""" Wraps an HTML element of type <th> """
946948
classes = [ "ltk-th" ]
947949
tag = "th"
948950

949951

950-
class TableData(Text):
952+
class TableData(Widget):
951953
""" Wraps an HTML element of type <td> """
952954
classes = [ "ltk-td" ]
953955
tag = "td"
@@ -1218,6 +1220,7 @@ class Select(Widget):
12181220

12191221
def __init__(self, options, selected, handler=None, style=None):
12201222
Widget.__init__(self, [Option(text) for text in options], style)
1223+
assert isinstance(options, list), f"Select: Expected options to be a list, not {type(options)}"
12211224
self.options = options
12221225
self.handler = handler
12231226
self.set_value(selected)
@@ -1393,7 +1396,7 @@ def __getattr__(self, name):
13931396
try:
13941397
return getattr(self.context, name)
13951398
except: # pylint: disable=bare-except
1396-
error = f"LTK widget {self} does not have attribute {name}"
1399+
error = f"Widget {self} does not have attribute {name}"
13971400
raise AttributeError(error) # pylint: disable=raise-missing-from
13981401

13991402
def __setattr__(self, name, value):

0 commit comments

Comments
 (0)