From: Melissa LeBlanc-Williams Date: Tue, 16 Mar 2021 18:42:34 +0000 (-0700) Subject: Fix code duplication warnings X-Git-Tag: 0.5.7~1^2~1 X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/commitdiff_plain/c2aa591d359e74f073f5e9cf7e1730ba41f24c01 Fix code duplication warnings --- diff --git a/displayio/bitmap.py b/displayio/bitmap.py index 7ac075c..41979ca 100644 --- a/displayio/bitmap.py +++ b/displayio/bitmap.py @@ -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 diff --git a/displayio/group.py b/displayio/group.py index 902f17b..3d8324f 100644 --- a/displayio/group.py +++ b/displayio/group.py @@ -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() diff --git a/displayio/i2cdisplay.py b/displayio/i2cdisplay.py index 21fa371..408c2ac 100644 --- a/displayio/i2cdisplay.py +++ b/displayio/i2cdisplay.py @@ -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") diff --git a/displayio/parallelbus.py b/displayio/parallelbus.py index f6e75d6..fa21d8f 100644 --- a/displayio/parallelbus.py +++ b/displayio/parallelbus.py @@ -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") diff --git a/displayio/tilegrid.py b/displayio/tilegrid.py index 9f35beb..552277b 100644 --- a/displayio/tilegrid.py +++ b/displayio/tilegrid.py @@ -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