diff --git a/drivers/epaper/pico_epaper_42.py b/drivers/epaper/pico_epaper_42.py index 26aaff4..65466fa 100644 --- a/drivers/epaper/pico_epaper_42.py +++ b/drivers/epaper/pico_epaper_42.py @@ -7,6 +7,7 @@ # UC8176 manual https://www.waveshare.com/w/upload/8/88/UC8176.pdf # Waveshare's copy of this driver. # https://github.com/waveshare/Pico_ePaper_Code/blob/main/pythonNanoGui/drivers/ePaper4in2.py +# https://github.com/waveshare/Pico_ePaper_Code/blob/main/python/Pico-ePaper-4.2.py # ***************************************************************************** # * | File : Pico_ePaper-3.7.py diff --git a/extras/README.md b/extras/README.md index 68349c0..a3a331d 100644 --- a/extras/README.md +++ b/extras/README.md @@ -40,8 +40,7 @@ specified in pixels with the column width being the specified width +4 to allow for borders. The dimensions of the widget including borders are thus: height = no. of rows * (font height + 4) width = sum(column width + 4) -Cells may be addressed as a 1-dimensional list or by a `[row, col]` 2-list or -2-tuple. +Cells may be addressed as a 1 or 2-dimensional array. Constructor args: 1. `writer` The `Writer` instance (font and screen) to use. @@ -94,22 +93,22 @@ grid.show() # Draw grid lines # Populate grid col = 0 for y, txt in enumerate("ABCDE"): - grid[[y + 1, col]] = txt + grid[y + 1, col] = txt row = 0 for col in range(1, cols): - grid[[row, col]] = str(col) + grid[row, col] = str(col) grid[20] = "" # Clear cell 20 by setting its value to "" -grid[[2, 5]] = str(42) # Note syntax +grid[2, 5] = str(42) # 2d array syntax # Dynamic formatting def txt(text): return {"text": text} redfg = {"fgcolor": RED} -grid[[3, 7]] = redfg | txt(str(99)) # Specify color as well as text +grid[3, 7] = redfg | txt(str(99)) # Specify color as well as text invla = {"invert": True, "align": ALIGN_LEFT} -grid[[2, 1]] = invla | txt("x") # Invert using invert flag +grid[2, 1] = invla | txt("x") # Invert using invert flag bkongn = {"fgcolor": BLACK, "bgcolor": GREEN, "align": ALIGN_LEFT} # Invert by swapping bg and fg -grid[[3, 1]] = bkongn | txt("a") -grid[[4,2]] = {"fgcolor": BLUE} | txt("go") +grid[3, 1] = bkongn | txt("a") +grid[4,2] = {"fgcolor": BLUE} | txt("go") refresh(ssd) ``` ## Calendar diff --git a/extras/widgets/calendar.py b/extras/widgets/calendar.py index 6e498f4..d44cbce 100644 --- a/extras/widgets/calendar.py +++ b/extras/widgets/calendar.py @@ -30,7 +30,7 @@ class Calendar: self.grid = Grid(wri, row, col, colwidth, rows, cols, **kwargs) self.grid.show() # Draw grid lines for n, day in enumerate(DateCal.days): # Populate day names - self.grid[[0, n]] = day[:3] + self.grid[0, n] = day[:3] self.show() def show(self): diff --git a/extras/widgets/grid.py b/extras/widgets/grid.py index 7f30269..89228a9 100644 --- a/extras/widgets/grid.py +++ b/extras/widgets/grid.py @@ -34,7 +34,7 @@ class Grid(DObject): c = col def _idx(self, n): - if isinstance(n, tuple) or isinstance(n, list): + if isinstance(n, tuple) or isinstance(n, list): # list allows old syntax l[[r, c]] if n[0] >= self.nrows: raise ValueError("Grid row index too large") if n[1] >= self.ncols: @@ -46,13 +46,14 @@ class Grid(DObject): raise ValueError("Grid cell index too large") return idx - def __getitem__(self, n): # Return the Label instance - return self.cells[self._idx(n)] + def __getitem__(self, *args): # Return the Label instance + return self.cells[self._idx(args[0])] - # allow grid[[r, c]] = "foo" or kwargs for Label: - # grid[[r, c]] = {"text": str(n), "fgcolor" : RED} - def __setitem__(self, n, x): - v = self.cells[self._idx(n)].value + # allow grid[r, c] = "foo" or kwargs for Label: + # grid[r, c] = {"text": str(n), "fgcolor" : RED} + def __setitem__(self, *args): + v = self.cells[self._idx(args[0])].value + x = args[1] _ = v(**x) if isinstance(x, dict) else v(x) def show(self):