]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
Fix code duplication warnings
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Tue, 16 Mar 2021 18:42:34 +0000 (11:42 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Tue, 16 Mar 2021 18:42:34 +0000 (11:42 -0700)
displayio/bitmap.py
displayio/group.py
displayio/i2cdisplay.py
displayio/parallelbus.py
displayio/tilegrid.py

index 7ac075ce9cb74b9f2ac41c831c8e0d0bbf3ed135..41979cafa392381ef7e2b2368adbceb2d92b9796 100644 (file)
@@ -53,8 +53,8 @@ class Bitmap:
         share the underlying Bitmap. value_count is used to minimize the memory used to store
         the Bitmap.
         """
-        self._width = width
-        self._height = height
+        self._bmp_width = width
+        self._bmp_height = height
         self._read_only = False
 
         if value_count < 0:
@@ -87,8 +87,8 @@ class Bitmap:
         if isinstance(index, (tuple, list)):
             x, y = index
         elif isinstance(index, int):
-            x = index % self._width
-            y = index // self._width
+            x = index % self._bmp_width
+            y = index // self._bmp_width
         else:
             raise TypeError("Index is not an int, list, or tuple")
 
@@ -106,10 +106,10 @@ class Bitmap:
         if isinstance(index, (tuple, list)):
             x = index[0]
             y = index[1]
-            index = y * self._width + x
+            index = y * self._bmp_width + x
         elif isinstance(index, int):
-            x = index % self._width
-            y = index // self._width
+            x = index % self._bmp_width
+            y = index // self._bmp_width
         self._image.putpixel((x, y), value)
         if self._dirty_area.x1 == self._dirty_area.x2:
             self._dirty_area.x1 = x
@@ -132,15 +132,15 @@ class Bitmap:
 
     def fill(self, value):
         """Fills the bitmap with the supplied palette index value."""
-        self._image = Image.new("P", (self._width, self._height), value)
-        self._dirty_area = Rectangle(0, 0, self._width, self._height)
+        self._image = Image.new("P", (self._bmp_width, self._bmp_height), value)
+        self._dirty_area = Rectangle(0, 0, self._bmp_width, self._bmp_height)
 
     @property
     def width(self):
         """Width of the bitmap. (read only)"""
-        return self._width
+        return self._bmp_width
 
     @property
     def height(self):
         """Height of the bitmap. (read only)"""
-        return self._height
+        return self._bmp_height
index 902f17bc15c6ed12800b214927d4328d1a4d086b..3d8324f75293a11e471608b2f8141838f313bf21 100644 (file)
@@ -59,9 +59,9 @@ class Group:
         if not isinstance(scale, int) or scale < 1:
             raise ValueError("Scale must be >= 1")
         self._scale = scale
-        self._x = x
-        self._y = y
-        self._hidden = False
+        self._group_x = x
+        self._group_y = y
+        self._hidden_group = False
         self._layers = []
         self._supported_types = (TileGrid, Group)
         self._absolute_transform = None
@@ -74,8 +74,8 @@ class Group:
         """Update the parent transform and child transforms"""
         self.in_group = parent_transform is not None
         if self.in_group:
-            x = self._x
-            y = self._y
+            x = self._group_x
+            y = self._group_y
             if parent_transform.transpose_xy:
                 x, y = y, x
             self._absolute_transform.x = parent_transform.x + parent_transform.dx * x
@@ -154,7 +154,7 @@ class Group:
         del self._layers[index]
 
     def _fill_area(self, buffer):
-        if self._hidden:
+        if self._hidden_group:
             return
 
         for layer in self._layers:
@@ -166,13 +166,13 @@ class Group:
         """True when the Group and all of it’s layers are not visible. When False, the
         Group’s layers are visible if they haven’t been hidden.
         """
-        return self._hidden
+        return self._hidden_group
 
     @hidden.setter
     def hidden(self, value):
         if not isinstance(value, (bool, int)):
             raise ValueError("Expecting a boolean or integer value")
-        self._hidden = bool(value)
+        self._hidden_group = bool(value)
 
     @property
     def scale(self):
@@ -201,37 +201,37 @@ class Group:
     @property
     def x(self):
         """X position of the Group in the parent."""
-        return self._x
+        return self._group_x
 
     @x.setter
     def x(self, value):
         if not isinstance(value, int):
             raise ValueError("x must be an integer")
-        if self._x != value:
+        if self._group_x != value:
             if self._absolute_transform.transpose_xy:
                 dy_value = self._absolute_transform.dy / self._scale
-                self._absolute_transform.y += dy_value * (value - self._x)
+                self._absolute_transform.y += dy_value * (value - self._group_x)
             else:
                 dx_value = self._absolute_transform.dx / self._scale
-                self._absolute_transform.x += dx_value * (value - self._x)
-            self._x = value
+                self._absolute_transform.x += dx_value * (value - self._group_x)
+            self._group_x = value
             self._update_child_transforms()
 
     @property
     def y(self):
         """Y position of the Group in the parent."""
-        return self._y
+        return self._group_y
 
     @y.setter
     def y(self, value):
         if not isinstance(value, int):
             raise ValueError("y must be an integer")
-        if self._y != value:
+        if self._group_y != value:
             if self._absolute_transform.transpose_xy:
                 dx_value = self._absolute_transform.dx / self._scale
-                self._absolute_transform.x += dx_value * (value - self._y)
+                self._absolute_transform.x += dx_value * (value - self._group_y)
             else:
                 dy_value = self._absolute_transform.dy / self._scale
-                self._absolute_transform.y += dy_value * (value - self._y)
-            self._y = value
+                self._absolute_transform.y += dy_value * (value - self._group_y)
+            self._group_y = value
             self._update_child_transforms()
index 21fa3712dca758886e322ad1990fafd5d2d14714..408c2ac1282afdede394379c03dc7db5be6bf38a 100644 (file)
@@ -61,11 +61,11 @@ class I2CDisplay:
         """Performs a hardware reset via the reset pin. Raises an exception if called
         when no reset pin is available.
         """
-        pass
+        raise NotImplementedError("I2CDisplay reset has not been implemented yet")
 
     def send(self, command, data):
         """Sends the given command value followed by the full set of data. Display state,
         such as vertical scroll, set via send may or may not be reset once the code is
         done.
         """
-        pass
+        raise NotImplementedError("I2CDisplay send has not been implemented yet")
index f6e75d688a5327a108fa938c3b9e2b12ecd32b22..fa21d8f97719be0b169ae4cd07ea5ddb31dfc7b5 100644 (file)
@@ -65,11 +65,12 @@ class ParallelBus:
         """Performs a hardware reset via the reset pin. Raises an exception if called when
         no reset pin is available.
         """
-        pass
+        raise NotImplementedError("ParallelBus reset has not been implemented yet")
+
 
     def send(self, command, data):
         """Sends the given command value followed by the full set of data. Display state,
         such as vertical scroll, set via ``send`` may or may not be reset once the code is
         done.
         """
-        pass
+        raise NotImplementedError("ParallelBus send has not been implemented yet")
index 9f35bebebf4b74200064a11a58cf845ad9236e11..552277b73551ef148435a5d5fea1b34cd9b71367 100644 (file)
@@ -89,7 +89,7 @@ class TileGrid:
         self._pixel_shader = pixel_shader
         if isinstance(self._pixel_shader, ColorConverter):
             self._pixel_shader._rgba = True  # pylint: disable=protected-access
-        self._hidden = False
+        self._hidden_tilegrid = False
         self._x = x
         self._y = y
         self._width = width  # Number of Tiles Wide
@@ -218,7 +218,7 @@ class TileGrid:
     # pylint: disable=too-many-locals,too-many-branches,too-many-statements
     def _fill_area(self, buffer):
         """Draw onto the image"""
-        if self._hidden:
+        if self._hidden_tilegrid:
             return
 
         if self._bitmap.width <= 0 or self._bitmap.height <= 0:
@@ -318,13 +318,13 @@ class TileGrid:
     def hidden(self):
         """True when the TileGrid is hidden. This may be False even
         when a part of a hidden Group."""
-        return self._hidden
+        return self._hidden_tilegrid
 
     @hidden.setter
     def hidden(self, value):
         if not isinstance(value, (bool, int)):
             raise ValueError("Expecting a boolean or integer value")
-        self._hidden = bool(value)
+        self._hidden_tilegrid = bool(value)
 
     @property
     def x(self):
@@ -397,10 +397,7 @@ class TileGrid:
         """The pixel shader of the tilegrid."""
         return self._pixel_shader
 
-    def __getitem__(self, index):
-        """Returns the tile index at the given index. The index can either be
-        an x,y tuple or an int equal to ``y * width + x``'.
-        """
+    def _extract_and_check_index(self, index):
         if isinstance(index, (tuple, list)):
             x = index[0]
             y = index[1]
@@ -410,21 +407,20 @@ class TileGrid:
             y = index // self._width
         if x > self._width or y > self._height or index >= len(self._tiles):
             raise ValueError("Tile index out of bounds")
+        return index
+
+    def __getitem__(self, index):
+        """Returns the tile index at the given index. The index can either be
+        an x,y tuple or an int equal to ``y * width + x``'.
+        """
+        index = self._extract_and_check_index(index)
         return self._tiles[index]
 
     def __setitem__(self, index, value):
         """Sets the tile index at the given index. The index can either be
         an x,y tuple or an int equal to ``y * width + x``.
         """
-        if isinstance(index, (tuple, list)):
-            x = index[0]
-            y = index[1]
-            index = y * self._width + x
-        elif isinstance(index, int):
-            x = index % self._width
-            y = index // self._width
-        if x > self._width or y > self._height or index >= len(self._tiles):
-            raise ValueError("Tile index out of bounds")
+        index = self._extract_and_check_index(index)
         if not 0 <= value <= 255:
             raise ValueError("Tile value out of bounds")
         self._tiles[index] = value