kopia lustrzana https://github.com/peterhinch/micropython-nano-gui
Grid widget __getitem__() returns iterator.
rodzic
dbcbd15535
commit
5eef93317e
|
@ -67,7 +67,7 @@ Constructor args:
|
||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
* `show` Draw the grid lines to the framebuffer.
|
* `show` Draw the grid lines to the framebuffer.
|
||||||
* `__getitem__` Return a list containing one or more `Label` instances.
|
* `__getitem__` Returns an iterator enabling `Label` instances to be accessed.
|
||||||
* `__setitem__` Assign a value to one or more labels. If multiple labels are
|
* `__setitem__` Assign a value to one or more labels. If multiple labels are
|
||||||
specified and a single text value is passed, all labels will receive that
|
specified and a single text value is passed, all labels will receive that
|
||||||
value. If an iterator is passed, consecutive labels will receive values from
|
value. If an iterator is passed, consecutive labels will receive values from
|
||||||
|
@ -96,6 +96,11 @@ grid[1:3, 1:3] = (str(n) for n in range(2)) # Produces
|
||||||
# 0 1
|
# 0 1
|
||||||
# 1 1
|
# 1 1
|
||||||
```
|
```
|
||||||
|
Read access:
|
||||||
|
```python
|
||||||
|
for label in grid[2, 0:]:
|
||||||
|
v = label.value() # Access each label in row 2
|
||||||
|
```
|
||||||
Sample usage (complete example):
|
Sample usage (complete example):
|
||||||
```python
|
```python
|
||||||
from color_setup import ssd
|
from color_setup import ssd
|
||||||
|
|
|
@ -34,12 +34,10 @@ class Grid(DObject):
|
||||||
r += self.cheight
|
r += self.cheight
|
||||||
c = col
|
c = col
|
||||||
|
|
||||||
def __getitem__(self, *args): # Return the Label instance
|
def __getitem__(self, *args):
|
||||||
indices = do_args(args, self.nrows, self.ncols)
|
indices = do_args(args, self.nrows, self.ncols)
|
||||||
res = []
|
|
||||||
for i in indices:
|
for i in indices:
|
||||||
res.append(self.cells[i])
|
yield self.cells[i]
|
||||||
return res
|
|
||||||
|
|
||||||
# allow grid[r, c] = "foo" or kwargs for Label:
|
# allow grid[r, c] = "foo" or kwargs for Label:
|
||||||
# grid[r, c] = {"text": str(n), "fgcolor" : RED}
|
# grid[r, c] = {"text": str(n), "fgcolor" : RED}
|
||||||
|
|
Ładowanie…
Reference in New Issue