]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blobdiff - displayio/_display.py
only convert command to bytes
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / _display.py
index 4e5da3f9b62cac322ad5c5f07223e26fbc02e23a..e0c4026689c4739c33b251e37692479f4f015b74 100644 (file)
@@ -20,16 +20,16 @@ displayio for Blinka
 import time
 import struct
 import threading
 import time
 import struct
 import threading
+from typing import Optional
 import digitalio
 from PIL import Image
 import numpy
 import microcontroller
 from recordclass import recordclass
 import digitalio
 from PIL import Image
 import numpy
 import microcontroller
 from recordclass import recordclass
-from ._colorconverter import ColorConverter
 import _typing
 import _typing
+from ._displaybus import _DisplayBus
+from ._colorconverter import ColorConverter
 from ._group import Group
 from ._group import Group
-from displayio import _DisplayBus
-from typing import Optional
 from ._constants import (
     CHIP_SELECT_TOGGLE_EVERY_BYTE,
     CHIP_SELECT_UNTOUCHED,
 from ._constants import (
     CHIP_SELECT_TOGGLE_EVERY_BYTE,
     CHIP_SELECT_UNTOUCHED,
@@ -87,7 +87,7 @@ class Display:
         SH1107_addressing: bool = False,
         set_vertical_scroll: int = 0,
     ):
         SH1107_addressing: bool = False,
         set_vertical_scroll: int = 0,
     ):
-        # pylint: disable=unused-argument,too-many-locals
+        # pylint: disable=unused-argument,too-many-locals,invalid-name
         """Create a Display object on the given display bus (`displayio.FourWire` or
         `paralleldisplay.ParallelBus`).
 
         """Create a Display object on the given display bus (`displayio.FourWire` or
         `paralleldisplay.ParallelBus`).
 
@@ -179,19 +179,21 @@ class Display:
             i += 2 + data_size
 
     def _send(self, command, data):
             i += 2 + data_size
 
     def _send(self, command, data):
-        self._bus._begin_transaction()  # pylint: disable=protected-access
+        # pylint: disable=protected-access
+        self._bus._begin_transaction()
         if self._data_as_commands:
             self._bus._send(
         if self._data_as_commands:
             self._bus._send(
-                DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, bytes([command] + data)
+                DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, bytes([command]) + data
             )
         else:
             self._bus._send(
                 DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, bytes([command])
             )
             self._bus._send(DISPLAY_DATA, CHIP_SELECT_UNTOUCHED, data)
             )
         else:
             self._bus._send(
                 DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, bytes([command])
             )
             self._bus._send(DISPLAY_DATA, CHIP_SELECT_UNTOUCHED, data)
-        self._bus._end_transaction()  # pylint: disable=protected-access
+        self._bus._end_transaction()
 
     def _send_pixels(self, data):
 
     def _send_pixels(self, data):
+        # pylint: disable=protected-access
         if not self._data_as_commands:
             self._bus._send(
                 DISPLAY_COMMAND,
         if not self._data_as_commands:
             self._bus._send(
                 DISPLAY_COMMAND,
@@ -296,14 +298,10 @@ class Display:
         else:
             width, height = self._width, self._height
 
         else:
             width, height = self._width, self._height
 
-        if rectangle.x1 < 0:
-            rectangle.x1 = 0
-        if rectangle.y1 < 0:
-            rectangle.y1 = 0
-        if rectangle.x2 > width:
-            rectangle.x2 = width
-        if rectangle.y2 > height:
-            rectangle.y2 = height
+        rectangle.x1 = max(rectangle.x1, 0)
+        rectangle.y1 = max(rectangle.y1, 0)
+        rectangle.x2 = min(rectangle.x2, width)
+        rectangle.y2 = min(rectangle.y2, height)
 
         return rectangle
 
 
         return rectangle
 
@@ -334,7 +332,7 @@ class Display:
 
     def _encode_pos(self, x, y):
         """Encode a postion into bytes."""
 
     def _encode_pos(self, x, y):
         """Encode a postion into bytes."""
-        return struct.pack(self._bounds_encoding, x, y)
+        return struct.pack(self._bounds_encoding, x, y)  # pylint: disable=no-member
 
     def fill_row(
         self, y: int, buffer: _typing.WriteableBuffer
 
     def fill_row(
         self, y: int, buffer: _typing.WriteableBuffer