From dc19a7c3676a2c9851701482d9790d88b8d5a635 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 8 Oct 2020 15:50:59 -0600 Subject: [PATCH 1/3] Added terminalio font support and scaling --- adafruit_pyportal.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) mode change 100644 => 100755 adafruit_pyportal.py diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py old mode 100644 new mode 100755 index 9e35ff9..f584bdc --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -26,7 +26,7 @@ CircuitPython driver for Adafruit PyPortal. -* Author(s): Limor Fried, Kevin J. Walters +* Author(s): Limor Fried, Kevin J. Walters, Melissa LeBlanc-Williams Implementation Notes -------------------- @@ -58,6 +58,7 @@ import storage import displayio from adafruit_display_text.label import Label +import terminalio import audioio import audiocore import rtc @@ -147,6 +148,7 @@ class PyPortal: ``False``, no wrapping. :param text_maxlen: The max length of the text for text wrapping. Defaults to 0. :param text_transform: A function that will be called on the text before display + :param int text_scale: The factor to scale the default size of the text by :param json_transform: A function or a list of functions to call with the parsed JSON. Changes and additions are permitted for the ``dict`` object. :param image_json_path: The JSON traversal path for a background image to display. Defaults to @@ -184,12 +186,13 @@ def __init__( regexp_path=None, default_bg=0x000000, status_neopixel=None, - text_font=None, + text_font=terminalio.FONT, text_position=None, text_color=0x808080, text_wrap=False, text_maxlen=0, text_transform=None, + text_scale=1, json_transform=None, image_json_path=None, image_resize=None, @@ -373,13 +376,18 @@ def __init__( text_wrap = (text_wrap,) text_maxlen = (text_maxlen,) text_transform = (text_transform,) + text_scale = (text_scale,) self._text = [None] * num self._text_color = [None] * num self._text_position = [None] * num self._text_wrap = [None] * num self._text_maxlen = [None] * num self._text_transform = [None] * num - self._text_font = bitmap_font.load_font(text_font) + self._text_scale = [None] * num + if text_font is not terminalio.FONT: + self._text_font = bitmap_font.load_font(text_font) + else: + self._text_font = terminalio.FONT if self._debug: print("Loading font glyphs") # self._text_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' @@ -395,6 +403,9 @@ def __init__( self._text_wrap[i] = text_wrap[i] self._text_maxlen[i] = text_maxlen[i] self._text_transform[i] = text_transform[i] + if not isinstance(text_scale[i], (int, float)) or text_scale[i] < 1: + text_scale[i] = 1 + self._text_scale[i] = text_scale[i] else: self._text_font = None self._text = None @@ -547,7 +558,7 @@ def preload_font(self, glyphs=None): if not glyphs: glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. \"'?!" print("Preloading font glyphs:", glyphs) - if self._text_font: + if self._text_font and self._text_font is not terminalio.FONT: self._text_font.load_glyphs(glyphs) def set_caption(self, caption_text, caption_position, caption_color): @@ -607,7 +618,9 @@ def set_text(self, val, index=0): text_index = i break - self._text[index] = Label(self._text_font, text=string) + self._text[index] = Label( + self._text_font, text=string, scale=self._text_scale[index] + ) self._text[index].color = self._text_color[index] self._text[index].x = self._text_position[index][0] self._text[index].y = self._text_position[index][1] @@ -616,7 +629,9 @@ def set_text(self, val, index=0): if self._text_position[index]: # if we want it placed somewhere... print("Making text area with string:", string) - self._text[index] = Label(self._text_font, text=string) + self._text[index] = Label( + self._text_font, text=string, scale=self._text_scale[index] + ) self._text[index].color = self._text_color[index] self._text[index].x = self._text_position[index][0] self._text[index].y = self._text_position[index][1] From ddd5e2dd3e8d92f19108048a00d8e5cffcc24b1e Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 8 Oct 2020 16:03:38 -0600 Subject: [PATCH 2/3] Added terminalio to automock --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index c355d20..4a117be 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -41,6 +41,7 @@ "adafruit_io", "adafruit_cursorcontrol", "adafruit_requests", + "terminalio", ] From 51a786870068a189911ee2b372ad9709a8c120d1 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 20 Oct 2020 15:42:49 -0600 Subject: [PATCH 3/3] Fix issue when there are multiple labels --- adafruit_pyportal.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 87483bb..fb8099e 100755 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -383,6 +383,8 @@ def __init__( text_maxlen = [0] * num if not text_transform: text_transform = [None] * num + if not isinstance(text_scale, (list, tuple)): + text_scale = [text_scale] * num else: num = 1 text_position = (text_position,)