Skip to content

Commit

Permalink
Updated to work with Circuitpython 9.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jake1164 committed Nov 30, 2024
1 parent 6193503 commit eded794
Show file tree
Hide file tree
Showing 42 changed files with 969 additions and 199 deletions.
2 changes: 1 addition & 1 deletion src/code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# UPDATE the settings.toml file before starting!

# Following are imported from circuitpython 8.x
# Following are imported from circuitpython 9.x
import os
import gc
import board
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bitmap_font/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from fontio import Glyph
from .glyph_cache import GlyphCache

__version__ = "2.1.0"
__version__ = "2.1.3"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"


Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bitmap_font/bitmap_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
except ImportError:
pass

__version__ = "2.1.0"
__version__ = "2.1.3"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"


Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bitmap_font/glyph_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import gc

__version__ = "2.1.0"
__version__ = "2.1.3"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"


Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bus_device/i2c_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pass


__version__ = "5.2.7"
__version__ = "5.2.10"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git"


Expand Down
4 changes: 2 additions & 2 deletions src/lib/adafruit_bus_device/spi_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
pass


__version__ = "5.2.7"
__version__ = "5.2.10"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git"


Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(
self.chip_select = chip_select
self.cs_active_value = cs_active_value
if self.chip_select:
self.chip_select.switch_to_output(value=True)
self.chip_select.switch_to_output(value=not self.cs_active_value)

def __enter__(self) -> SPI:
while not self.spi.try_lock():
Expand Down
Binary file added src/lib/adafruit_connection_manager.mpy
Binary file not shown.
10 changes: 3 additions & 7 deletions src/lib/adafruit_display_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
=======================
"""

__version__ = "3.0.5"
__version__ = "3.2.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

from displayio import Group, Palette
Expand Down Expand Up @@ -246,7 +246,6 @@ def __init__(
tab_replacement: Tuple[int, str] = (4, " "),
label_direction: str = "LTR",
verbose: bool = False,
**kwargs, # pylint: disable=unused-argument
) -> None:
# pylint: disable=too-many-arguments, too-many-locals

Expand All @@ -271,9 +270,6 @@ def __init__(
self._tab_text = self._tab_replacement[1] * self._tab_replacement[0]
self._verbose = verbose

if "max_glyphs" in kwargs:
print("Please update your code: 'max_glyphs' is not needed anymore.")

self._ascent, self._descent = self._get_ascent_descent()
self._bounding_box = None

Expand Down Expand Up @@ -428,12 +424,12 @@ def bounding_box(self) -> Tuple[int, int]:
@property
def height(self) -> int:
"""The height of the label determined from the bounding box."""
return self._bounding_box[3] - self._bounding_box[1]
return self._bounding_box[3]

@property
def width(self) -> int:
"""The width of the label determined from the bounding box."""
return self._bounding_box[2] - self._bounding_box[0]
return self._bounding_box[2]

@property
def line_spacing(self) -> float:
Expand Down
19 changes: 13 additions & 6 deletions src/lib/adafruit_display_text/bitmap_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

__version__ = "3.0.5"
__version__ = "3.2.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

import displayio
Expand Down Expand Up @@ -183,6 +183,10 @@ def _reset_text(
if self._background_tight:
box_y = tight_box_y
y_offset = tight_y_offset
self._padding_left = 0
self._padding_right = 0
self._padding_top = 0
self._padding_bottom = 0

else: # calculate the box size for a loose background
box_y = loose_box_y
Expand Down Expand Up @@ -288,15 +292,18 @@ def _line_spacing_ypixels(font: FontProtocol, line_spacing: float) -> int:
def _text_bounding_box(
self, text: str, font: FontProtocol
) -> Tuple[int, int, int, int, int, int]:
# pylint: disable=too-many-locals
# pylint: disable=too-many-locals,too-many-branches

ascender_max, descender_max = self._ascent, self._descent
bbox = font.get_bounding_box()
if len(bbox) == 4:
ascender_max, descender_max = bbox[1], -bbox[3]
else:
ascender_max, descender_max = self._ascent, self._descent

lines = 1

xposition = (
x_start
) = yposition = y_start = 0 # starting x and y position (left margin)
# starting x and y position (left margin)
xposition = x_start = yposition = y_start = 0

left = None
right = x_start
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

__version__ = "3.0.5"
__version__ = "3.2.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"


Expand Down
188 changes: 188 additions & 0 deletions src/lib/adafruit_display_text/outlined_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# SPDX-FileCopyrightText: 2023 Tim C
#
# SPDX-License-Identifier: MIT

"""
`adafruit_display_text.outlined_label`
====================================================
Subclass of BitmapLabel that adds outline color and stroke size
functionalities.
* Author(s): Tim Cocks
Implementation Notes
--------------------
**Hardware:**
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads
"""
__version__ = "3.2.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

import bitmaptools
from displayio import Palette, Bitmap
from adafruit_display_text import bitmap_label

try:
from typing import Optional, Tuple, Union
from fontio import FontProtocol
except ImportError:
pass


class OutlinedLabel(bitmap_label.Label):
"""
OutlinedLabel - A BitmapLabel subclass that includes arguments and properties for specifying
outline_size and outline_color to get drawn as a stroke around the text.
:param Union[Tuple, int] outline_color: The color of the outline stroke as RGB tuple, or hex.
:param int outline_size: The size in pixels of the outline stroke.
"""

# pylint: disable=too-many-arguments
def __init__(
self,
font,
outline_color: Union[int, Tuple] = 0x999999,
outline_size: int = 1,
padding_top: Optional[int] = None,
padding_bottom: Optional[int] = None,
padding_left: Optional[int] = None,
padding_right: Optional[int] = None,
**kwargs
):
if padding_top is None:
padding_top = outline_size + 0
if padding_bottom is None:
padding_bottom = outline_size + 2
if padding_left is None:
padding_left = outline_size + 0
if padding_right is None:
padding_right = outline_size + 0

super().__init__(
font,
padding_top=padding_top,
padding_bottom=padding_bottom,
padding_left=padding_left,
padding_right=padding_right,
**kwargs
)

_background_color = self._palette[0]
_foreground_color = self._palette[1]
_background_is_transparent = self._palette.is_transparent(0)
self._palette = Palette(3)
self._palette[0] = _background_color
self._palette[1] = _foreground_color
self._palette[2] = outline_color
if _background_is_transparent:
self._palette.make_transparent(0)

self._outline_size = outline_size
self._stamp_source = Bitmap((outline_size * 2) + 1, (outline_size * 2) + 1, 3)
self._stamp_source.fill(2)

self._bitmap = None

self._reset_text(
font=font,
text=self._text,
line_spacing=self._line_spacing,
scale=self.scale,
)

def _add_outline(self):
"""
Blit the outline into the labels Bitmap. We will stamp self._stamp_source for each
pixel of the foreground color but skip the foreground color when we blit.
:return: None
"""
if hasattr(self, "_stamp_source"):
for y in range(self.bitmap.height):
for x in range(self.bitmap.width):
if self.bitmap[x, y] == 1:
try:
bitmaptools.blit(
self.bitmap,
self._stamp_source,
x - self._outline_size,
y - self._outline_size,
skip_dest_index=1,
)
except ValueError as value_error:
raise ValueError(
"Padding must be big enough to fit outline_size "
"all the way around the text. "
"Try using either larger padding sizes, or smaller outline_size."
) from value_error

def _place_text(
self,
bitmap: Bitmap,
text: str,
font: FontProtocol,
xposition: int,
yposition: int,
skip_index: int = 0, # set to None to write all pixels, other wise skip this palette index
# when copying glyph bitmaps (this is important for slanted text
# where rectangular glyph boxes overlap)
) -> Tuple[int, int, int, int]:
"""
Copy the glpyphs that represent the value of the string into the labels Bitmap.
:param bitmap: The bitmap to place text into
:param text: The text to render
:param font: The font to render the text in
:param xposition: x location of the starting point within the bitmap
:param yposition: y location of the starting point within the bitmap
:param skip_index: Color index to skip during rendering instead of covering up
:return Tuple bounding_box: tuple with x, y, width, height values of the bitmap
"""
parent_result = super()._place_text(
bitmap, text, font, xposition, yposition, skip_index=skip_index
)

self._add_outline()

return parent_result

@property
def outline_color(self):
"""Color of the outline to draw around the text."""
return self._palette[2]

@outline_color.setter
def outline_color(self, new_outline_color):
self._palette[2] = new_outline_color

@property
def outline_size(self):
"""Stroke size of the outline to draw around the text."""
return self._outline_size

@outline_size.setter
def outline_size(self, new_outline_size):
self._outline_size = new_outline_size

self._padding_top = new_outline_size + 0
self._padding_bottom = new_outline_size + 2
self._padding_left = new_outline_size + 0
self._padding_right = new_outline_size + 0

self._stamp_source = Bitmap(
(new_outline_size * 2) + 1, (new_outline_size * 2) + 1, 3
)
self._stamp_source.fill(2)
self._reset_text(
font=self._font,
text=self._text,
line_spacing=self._line_spacing,
scale=self.scale,
)
Loading

0 comments on commit eded794

Please sign in to comment.