Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Autocompletion and handling unimplemented methods #299

Merged
merged 12 commits into from
Apr 7, 2020
Binary file not shown.
102 changes: 98 additions & 4 deletions src/base_circuitpython/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,114 @@ def show(self, group=None):
self.active_group = group

if group == None:
self.terminal.draw()
self.terminal._Terminal__draw()
return

# if the group has no attribute called
# "draw", then it is liable for updating itself
# when it calls show
if hasattr(group, "draw"):
group.draw()
if hasattr(group, "_Group__draw"):
group._Group__draw()


DISPLAY = Display()

# deafult pin,
# default pin for neopixel,
# shows that this could
# refer to the CPX
# or CLUE neopixel pin
NEOPIXEL = "D00"

# ETC PINS WITHIN THE CLUE THAT MAY BE REFERENCED
# found by runing print(dir(board)) on clue
A0 = 0
A1 = 0
A2 = 0
A3 = 0
A4 = 0
A5 = 0
A6 = 0
A7 = 0

ACCELEROMETER_GYRO_INTERRUPT = 0

BUTTON_A = 0
BUTTON_B = 0

D0 = 0
D1 = 0
D2 = 0
D3 = 0
D4 = 0
D5 = 0
D6 = 0
D7 = 0
D8 = 0
D9 = 0
D10 = 0
D11 = 0
D12 = 0
D13 = 0
D14 = 0
D15 = 0
D16 = 0
D17 = 0
D18 = 0
D19 = 0
D20 = 0

I2C = 0

L = 0

MICROPHONE_CLOCK = 0
MICROPHONE_DATA = 0

MISO = 0
MOSI = 0

P0 = 0
P1 = 0
P2 = 0
P3 = 0
P4 = 0
P5 = 0
P6 = 0
P7 = 0
P8 = 0
P9 = 0
P10 = 0
P11 = 0
P12 = 0
P13 = 0
P14 = 0
P15 = 0
P16 = 0
P17 = 0
P18 = 0
P19 = 0
P20 = 0

PROXIMITY_LIGHT_INTERRUPT = 0

RX = 0
SCK = 0
SCL = 0
SDA = 0

SPEAKER = 0

SPI = 0

TFT_BACKLIGHT = 0
TFT_CS = 0
TFT_DC = 0
TFT_MOSI = 0
TFT_RESET = 0
TFT_SCK = 0

TX = 0

UART = 0

WHITE_LEDS = 0
1 change: 0 additions & 1 deletion src/base_circuitpython/displayio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# https://circuitpython.readthedocs.io/en/5.0.x/shared-bindings/displayio/__init__.html

from .bitmap import Bitmap
from .color_type import ColorType
from .group import Group
from .palette import Palette

Expand Down
57 changes: 54 additions & 3 deletions src/base_circuitpython/displayio/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,63 @@


class Bitmap:
"""
.. currentmodule:: displayio

`Bitmap` -- Stores values in a 2D array
==========================================================================

Stores values of a certain size in a 2D array

.. class:: Bitmap(width, height, value_count)

Create a Bitmap object with the given fixed size. Each pixel stores a value that is used to
index into a corresponding palette. This enables differently colored sprites to share the
underlying Bitmap. value_count is used to minimize the memory used to store the Bitmap.

:param int width: The number of values wide
:param int height: The number of values high
:param int value_count: The number of possible pixel values.

"""

def __init__(self, width, height, value_count=255):
self.__width = width
self.__height = height
self.values = bytearray(width * height)

@property
def width(self):
"""
.. attribute:: width

Width of the bitmap. (read only)

"""
return self.__width

@property
def height(self):
"""
.. attribute:: height

Height of the bitmap. (read only)

"""
return self.__height

def __setitem__(self, index, value):
"""
.. method:: __setitem__(index, value)

Sets the value at the given index. The index can either be an x,y tuple or an int equal
to ``y * width + x``.

This allows you to::

bitmap[0,1] = 3

"""
if isinstance(index, tuple):
if index[0] >= self.width or index[1] >= self.height:
raise IndexError(CONSTANTS.PIXEL_OUT_OF_BOUNDS)
Expand All @@ -38,6 +81,17 @@ def __setitem__(self, index, value):
raise IndexError(CONSTANTS.PIXEL_OUT_OF_BOUNDS)

def __getitem__(self, index):
"""
.. method:: __getitem__(index)

Returns the value at the given index. The index can either be an x,y tuple or an int equal
to ``y * width + x``.

This allows you to::

print(bitmap[0,1])

"""

if isinstance(index, tuple):
if index[0] >= self.width or index[1] >= self.height:
Expand All @@ -49,6 +103,3 @@ def __getitem__(self, index):
return self.values[index]
except IndexError:
raise IndexError(CONSTANTS.PIXEL_OUT_OF_BOUNDS)

def __len__(self):
return self.width * self.height
4 changes: 2 additions & 2 deletions src/base_circuitpython/displayio/color_type.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Datatype for the items within a palette
class ColorType:
class _ColorType:
def __init__(self, rgb888):
self.rgb888 = rgb888
self.transparent = False

def __eq__(self, other):
return (
isinstance(other, ColorType)
isinstance(other, _ColorType)
and self.rgb888 == other.rgb888
and self.transparent == other.transparent
)
Loading