+ # Go through groups and and add each to buffer
+ if self._current_group is not None:
+ buffer = Image.new("RGB", (self._width, self._height))
+ # Recursively have everything draw to the image
+ self._current_group._fill_area(buffer)
+ # save image to buffer (or probably refresh buffer so we can compare)
+ self._buffer.paste(buffer)
+ print("refreshing")
+ time.sleep(1)
+ # Eventually calculate dirty rectangles here
+ self._subrectangles.append(Rectangle(0, 0, self._width, self._height))
+
+ for area in self._subrectangles:
+ self._refresh_display_area(area)
+
+ def _refresh_loop(self):
+ while self._auto_refresh:
+ self.refresh()
+
+ def _refresh_display_area(self, rectangle):
+ """Loop through dirty rectangles and redraw that area."""
+ """Read or write a block of data."""
+ data = numpy.array(self._buffer.crop(rectangle).convert("RGB")).astype("uint16")
+ color = (
+ ((data[:, :, 0] & 0xF8) << 8)
+ | ((data[:, :, 1] & 0xFC) << 3)
+ | (data[:, :, 2] >> 3)
+ )
+
+ pixels = list(
+ numpy.dstack(((color >> 8) & 0xFF, color & 0xFF)).flatten().tolist()
+ )
+
+ self._write(
+ self._set_column_command,
+ self._encode_pos(
+ rectangle.x1 + self._colstart, rectangle.x2 + self._colstart
+ ),
+ )
+ self._write(
+ self._set_row_command,
+ self._encode_pos(
+ rectangle.y1 + self._rowstart, rectangle.y2 + self._rowstart
+ ),
+ )
+ self._write(self._write_ram_command, pixels)
+
+ def _encode_pos(self, x, y):
+ """Encode a postion into bytes."""
+ return struct.pack(self._bounds_encoding, x, y)