From 79d0c472cee798cbe7254d8e7afedb479a454bb1 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 7 Oct 2020 14:11:49 -0600 Subject: [PATCH 1/4] Updated README and added text_scale --- README.rst | 3 ++- adafruit_matrixportal/matrixportal.py | 37 ++++++++++++++++++++++----- docs/index.rst | 9 ++++++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 69095e0..ef2ec2a 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,8 @@ Introduction :target: https://github.com/psf/black :alt: Code Style: Black -Helper library for the Adafruit RGB Matrix Shield + Metro M4 Airlift Lite. +CircuitPython helper for Adafruit MatrixPortal M4, Adafruit RGB Matrix Shield + Metro M4 Airlift Lite, +and Adafruit RGB Matrix FeatherWings Dependencies diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index 18ad58f..2c0a696 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -28,6 +28,7 @@ import gc from time import sleep import terminalio +from displayio import Group from adafruit_bitmap_font import bitmap_font from adafruit_display_text.label import Label from adafruit_matrixportal.network import Network @@ -124,6 +125,7 @@ def __init__( self._text_maxlen = [] self._text_transform = [] self._text_scrolling = [] + self._text_scale = [] self._scrolling_index = None self._text_font = terminalio.FONT @@ -138,6 +140,7 @@ def add_text( text_wrap=False, text_maxlen=0, text_transform=None, + text_scale=1, scrolling=False, ): """ @@ -153,6 +156,7 @@ def add_text( ``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 bool scrolling: If true, text is placed offscreen and the scroll() function is used to scroll text on a pixel-by-pixel basis. Multiple text labels with the scrolling set to True will be cycled through. @@ -169,6 +173,9 @@ def add_text( text_maxlen = 0 if not text_transform: text_transform = None + if not isinstance(text_scale, (int, float)) or text_scale < 1: + text_scale = 1 + text_scale = round(text_scale) if scrolling: text_position = (self.display.width, text_position[1]) @@ -182,6 +189,7 @@ def add_text( self._text_wrap.append(text_wrap) self._text_maxlen.append(text_maxlen) self._text_transform.append(text_transform) + self._text_scale.append(text_scale) self._text_scrolling.append(scrolling) if scrolling and self._scrolling_index is None: # Not initialized yet @@ -242,7 +250,10 @@ def set_text_color(self, color, index=0): if self._text[index]: color = self.html_color_convert(color) self._text_color[index] = color - self._text[index].color = color + if isinstance(self._text[index], Group): + self._text[index][0].color = color + else: + self._text[index].color = color def set_text(self, val, index=0): """Display text, with indexing into our list of text boxes. @@ -261,12 +272,18 @@ def set_text(self, val, index=0): index_in_splash = None if self._text[index] is not None: print("Replacing text area with :", string) - index_in_splash = self.splash.index(self._text[index]) if len(string) > 0: - self._text[index] = Label(self._text_font, text=string) - 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] + label = Label(self._text_font, text=string) + label.color = self._text_color[index] + if self._text_scale[index] > 1: + self._text[index] = Group(max_size=1, scale=self._text_scale[index]) + self._text[index].x = self._text_position[index][0] + self._text[index].y = self._text_position[index][1] + self._text[index].append(label) + else: + label.x = self._text_position[index][0] + label.y = self._text_position[index][1] + self._text[index] = label elif index_in_splash is not None: self._text[index] = None @@ -315,6 +332,14 @@ def get_io_data(self, feed_key): return self.network.get_io_data(feed_key) + def get_io_last_data(self, feed_key): + """Return last value from Adafruit IO Feed Data that matches the feed key + + :param str feed_key: Name of feed key to receive data from. + + """ + return self.network.get_io_last_data(feed_key) + def get_io_feed(self, feed_key, detailed=False): """Return the Adafruit IO Feed that matches the feed key diff --git a/docs/index.rst b/docs/index.rst index fd1cd47..8b689cc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,13 +23,20 @@ Table of Contents .. toctree:: :caption: Tutorials + * Adafruit MatrixPortal M4 + .. toctree:: :caption: Related Products - * Adafruit Matrix Portal + * Adafruit MatrixPortal M4 * Adafruit Metro M4 Express AirLift * Adafruit RGB Matrix Shield + * Adafruit RGB Matrix Featherwing for M0/M4 + * Adafruit RGB Matrix FeatherWing for nrf52840 * 64x32 RGB LED Matrix + * 16x32 RGB LED Matrix + * 64x64 2.5mm pitch RGB LED Matrix + * 64x64 3mm pitch RGB LED Matrix .. toctree:: :caption: Other Links From be8f3b2c97e9c934dceb4b13ae5debbc32d8c656 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 7 Oct 2020 15:34:31 -0600 Subject: [PATCH 2/4] Simplified to just use scale property of label --- adafruit_matrixportal/matrixportal.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index 2c0a696..97535d6 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -250,10 +250,7 @@ def set_text_color(self, color, index=0): if self._text[index]: color = self.html_color_convert(color) self._text_color[index] = color - if isinstance(self._text[index], Group): - self._text[index][0].color = color - else: - self._text[index].color = color + self._text[index].color = color def set_text(self, val, index=0): """Display text, with indexing into our list of text boxes. @@ -273,17 +270,12 @@ def set_text(self, val, index=0): if self._text[index] is not None: print("Replacing text area with :", string) if len(string) > 0: - label = Label(self._text_font, text=string) - label.color = self._text_color[index] - if self._text_scale[index] > 1: - self._text[index] = Group(max_size=1, scale=self._text_scale[index]) - self._text[index].x = self._text_position[index][0] - self._text[index].y = self._text_position[index][1] - self._text[index].append(label) - else: - label.x = self._text_position[index][0] - label.y = self._text_position[index][1] - self._text[index] = label + 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] elif index_in_splash is not None: self._text[index] = None From bf282f9f59395da12d20df5324dcec5fbde049cc Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 7 Oct 2020 15:50:39 -0600 Subject: [PATCH 3/4] Fixed accidentally deleted line --- adafruit_matrixportal/matrixportal.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index 97535d6..7585409 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -28,7 +28,6 @@ import gc from time import sleep import terminalio -from displayio import Group from adafruit_bitmap_font import bitmap_font from adafruit_display_text.label import Label from adafruit_matrixportal.network import Network @@ -267,8 +266,14 @@ def set_text(self, val, index=0): string = string[: self._text_maxlen[index]] print("text index", self._text[index]) index_in_splash = None + if self._text[index] is not None: - print("Replacing text area with :", string) + if self._debug: + print("Replacing text area with :", string) + index_in_splash = self.splash.index(self._text[index]) + elif self._debug: + print("Creating text area with :", string) + if len(string) > 0: self._text[index] = Label( self._text_font, text=string, scale=self._text_scale[index] From 74d29df9f3cfe78d5dca016e976e8e772afa5aea Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 7 Oct 2020 16:10:53 -0600 Subject: [PATCH 4/4] Remove function I didn't add --- adafruit_matrixportal/matrixportal.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index 7585409..9b954c3 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -329,14 +329,6 @@ def get_io_data(self, feed_key): return self.network.get_io_data(feed_key) - def get_io_last_data(self, feed_key): - """Return last value from Adafruit IO Feed Data that matches the feed key - - :param str feed_key: Name of feed key to receive data from. - - """ - return self.network.get_io_last_data(feed_key) - def get_io_feed(self, feed_key, detailed=False): """Return the Adafruit IO Feed that matches the feed key