Python: Make it possible to construct a ListModel from an iterable

Makes for a more pythonic API :)

cc #4135
This commit is contained in:
Simon Hausmann 2024-03-07 08:55:37 +01:00
parent c83615cfb1
commit 176aa4bf72
2 changed files with 18 additions and 2 deletions

View file

@ -25,9 +25,12 @@ class Model(native.PyModelBase):
class ListModel(Model):
def __init__(self, lst=None):
def __init__(self, iterable=None):
super().__init__()
self.list = lst or []
if iterable is not None:
self.list = list(iterable)
else:
self.list = []
def row_count(self):
return len(self.list)