]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
Merge pull request #91 from FoamyGuy/bitmap_setter
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Mon, 16 May 2022 22:15:53 +0000 (16:15 -0600)
committerGitHub <noreply@github.com>
Mon, 16 May 2022 22:15:53 +0000 (16:15 -0600)
bitmap getter and setter. and pixel_shader setter

1  2 
displayio/_tilegrid.py

diff --combined displayio/_tilegrid.py
index 999ddb225316fe993ae1ed6b527b3efeb5d877a3,ca3a31f0d7340512075b2f693675d42b74c172dc..7fc9189a4dcdca4b98dc0ddc0862e2554b1c809d
@@@ -381,6 -381,42 +381,42 @@@ class TileGrid
          """The pixel shader of the tilegrid."""
          return self._pixel_shader
  
+     @pixel_shader.setter
+     def pixel_shader(self, new_pixel_shader: Union[ColorConverter, Palette]) -> None:
+         if not isinstance(new_pixel_shader, ColorConverter) and not isinstance(
+             new_pixel_shader, Palette
+         ):
+             raise TypeError(
+                 "Unsupported Type: new_pixel_shader must be ColorConverter or Palette"
+             )
+         self._pixel_shader = new_pixel_shader
+     @property
+     def bitmap(self) -> Union[Bitmap, OnDiskBitmap, Shape]:
+         """The Bitmap, OnDiskBitmap, or Shape that is assigned to this TileGrid"""
+         return self._bitmap
+     @bitmap.setter
+     def bitmap(self, new_bitmap: Union[Bitmap, OnDiskBitmap, Shape]) -> None:
+         if (
+             not isinstance(new_bitmap, Bitmap)
+             and not isinstance(new_bitmap, OnDiskBitmap)
+             and not isinstance(new_bitmap, Shape)
+         ):
+             raise TypeError(
+                 "Unsupported Type: new_bitmap must be Bitmap, OnDiskBitmap, or Shape"
+             )
+         if (
+             new_bitmap.width != self.bitmap.width
+             or new_bitmap.height != self.bitmap.height
+         ):
+             raise ValueError("New bitmap must be same size as old bitmap")
+         self._bitmap = new_bitmap
      def _extract_and_check_index(self, index):
          if isinstance(index, (tuple, list)):
              x = index[0]
          if not 0 <= value <= 255:
              raise ValueError("Tile value out of bounds")
          self._tiles[index] = value
 +
 +    @property
 +    def width(self) -> int:
 +        """Width in tiles"""
 +        return self._width
 +
 +    @property
 +    def height(self) -> int:
 +        """Height in tiles"""
 +        return self._height
 +
 +    @property
 +    def tile_width(self) -> int:
 +        """Width of each tile in pixels"""
 +        return self._tile_width
 +
 +    @property
 +    def tile_height(self) -> int:
 +        """Height of each tile in pixels"""
 +        return self._tile_height