From 316d40c74e6a2cb499c3bcad93f78e89742e5b3e Mon Sep 17 00:00:00 2001 From: Robert Grizzell Date: Tue, 10 May 2022 23:20:59 -0500 Subject: [PATCH 1/6] Adding typing information to scrolling_label.py --- adafruit_display_text/scrolling_label.py | 61 +++++++++++++----------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 88ae61c..15563c2 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -26,36 +26,42 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git" +try: + from typing import Union, Optional, Tuple + from fontio import BuiltinFont + from adafruit_bitmap_font.bdf import BDF + from adafruit_bitmap_font.pcf import PCF +except ImportError: + pass + import time from adafruit_display_text import bitmap_label class ScrollingLabel(bitmap_label.Label): - - """ - ScrollingLabel - A fixed-width label that will scroll to the left + """ScrollingLabel - A fixed-width label that will scroll to the left in order to show the full text if it's larger than the fixed-width. :param font: The font to use for the label. - :param max_characters: The number of characters that sets the fixed-width. Default is 10. - :param text: The full text to show in the label. If this is longer than - `max_characters` then the label will scroll to show everything. - :param animate_time: The number of seconds in between scrolling animation + :type font: ~BuiltinFont, ~BDF, or ~PCF + :param int max_characters: The number of characters that sets the fixed-width. Default is 10. + :param str text: The full text to show in the label. If this is longer than + ``max_characters`` then the label will scroll to show everything. + :param float animate_time: The number of seconds in between scrolling animation frames. Default is 0.3 seconds. - :param current_index: The index of the first visible character in the label. - Default is 0, the first character. Will increase while scrolling. - """ + :param int current_index: The index of the first visible character in the label. + Default is 0, the first character. Will increase while scrolling.""" # pylint: disable=too-many-arguments def __init__( self, - font, - max_characters=10, - text="", - animate_time=0.3, - current_index=0, + font: Union[BuiltinFont, BDF, PCF], + max_characters: Optional[int] = 10, + text: Optional[str] = "", + animate_time: Optional[float] = 0.3, + current_index: Optional[int] = 0, **kwargs - ): + ) -> None: super().__init__(font, **kwargs) self.animate_time = animate_time @@ -69,13 +75,12 @@ def __init__( self.update() - def update(self, force=False): - """ - Attempt to update the display. If `animate_time` has elapsed since + def update(self, force: Optional[bool] = False) -> None: + """Attempt to update the display. If ``animate_time`` has elapsed since previews animation frame then move the characters over by 1 index. Must be called in the main loop of user code. - :param force: whether to ignore `animation_time` and force the update. Default is False. + :param bool force: whether to ignore ``animation_time`` and force the update. Default is False. :return: None """ _now = time.monotonic() @@ -110,25 +115,23 @@ def update(self, force=False): return @property - def current_index(self): - """ - Index of the first visible character. + def current_index(self) -> int: + """Index of the first visible character. - :return int: the current index + :return int: The current index """ return self._current_index @current_index.setter - def current_index(self, new_index): + def current_index(self, new_index: int): if new_index < len(self.full_text): self._current_index = new_index else: self._current_index = new_index % len(self.full_text) @property - def full_text(self): - """ - The full text to be shown. If it's longer than `max_characters` then + def full_text(self) -> str: + """The full text to be shown. If it's longer than ``max_characters`` then scrolling will occur as needed. :return string: The full text of this label. @@ -136,7 +139,7 @@ def full_text(self): return self._full_text @full_text.setter - def full_text(self, new_text): + def full_text(self, new_text: str): if new_text[-1] != " ": new_text = "{} ".format(new_text) self._full_text = new_text From b8f34dbd7532c5c6fbc983d63402195638c5738d Mon Sep 17 00:00:00 2001 From: Robert Grizzell Date: Tue, 10 May 2022 23:21:37 -0500 Subject: [PATCH 2/6] Adding scrolling_label.py and example to documentation --- docs/api.rst | 3 +++ docs/examples.rst | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index f2cfca6..8e456ce 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -13,3 +13,6 @@ .. automodule:: adafruit_display_text.bitmap_label :members: + +.. automodule:: adafruit_display_text.scrolling_label + :members: diff --git a/docs/examples.rst b/docs/examples.rst index ce38df3..bf00290 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -1,4 +1,4 @@ -Simple test +Simple Test ------------ Ensure your device works with this simple test. @@ -7,7 +7,7 @@ Ensure your device works with this simple test. :caption: examples/display_text_simpletest.py :linenos: -Bitmap_label Simple test +Bitmap_label Simple Test ------------------------ Simple test using bitmap_label to display text @@ -16,6 +16,15 @@ Simple test using bitmap_label to display text :caption: examples/display_text_bitmap_label_simpletest.py :linenos: +ScrollingLabel Simple Test +--------------------------- + +Simple test using scrolling_label to display text + +.. literalinclude:: ../examples/display_text_scrolling_label.py + :caption: examples/display_text_scrolling_label.py + :linenos: + Label vs Bitmap_label Comparison -------------------------------- @@ -25,7 +34,7 @@ Example to compare Label and Bitmap_Label characteristics :caption: examples/display_text_label_vs_bitmap_label_comparison.py :linenos: -Background color example +Background Color Example ------------------------ Show the text backgrounds features @@ -34,7 +43,7 @@ Show the text backgrounds features :caption: examples/display_text_background_color.py :linenos: -Text padding example +Text Padding Example -------------------- Show the text padding features in all directions @@ -61,7 +70,7 @@ Boundingbox demonstration :caption: examples/display_text_textarea_boundingbox.py :linenos: -Align Baseline example +Align Baseline Example ---------------------- Demonstrate how to align different labels to a common horizontal line @@ -70,7 +79,7 @@ Demonstrate how to align different labels to a common horizontal line :caption: examples/display_text_label_align_baseline_comparison.py :linenos: -Magtag example +Magtag Example -------------- Uses the MAGTAG to display some text @@ -79,7 +88,7 @@ Uses the MAGTAG to display some text :caption: examples/display_text_magtag.py :linenos: -MatrixPortal example +MatrixPortal Example -------------------- Uses the MatrixPortal to display some text @@ -88,7 +97,7 @@ Uses the MatrixPortal to display some text :caption: examples/display_text_matrixportal.py :linenos: -PyPortal example +PyPortal Example ---------------- Uses the Pyportal to display some text @@ -97,7 +106,7 @@ Uses the Pyportal to display some text :caption: examples/display_text_pyportal.py :linenos: -Wraptest example +Wraptest Example ---------------- Illustrates the wraptest feature From 681d4e32c6395a8a3deb5655e1a15887ab207d4a Mon Sep 17 00:00:00 2001 From: Robert Grizzell Date: Tue, 10 May 2022 23:30:43 -0500 Subject: [PATCH 3/6] Minor fixes to appease pylint --- adafruit_display_text/scrolling_label.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 15563c2..24e46a8 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -27,7 +27,7 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git" try: - from typing import Union, Optional, Tuple + from typing import Union, Optional from fontio import BuiltinFont from adafruit_bitmap_font.bdf import BDF from adafruit_bitmap_font.pcf import PCF @@ -80,7 +80,8 @@ def update(self, force: Optional[bool] = False) -> None: previews animation frame then move the characters over by 1 index. Must be called in the main loop of user code. - :param bool force: whether to ignore ``animation_time`` and force the update. Default is False. + :param bool force: whether to ignore ``animation_time`` and force the update. + Default is False. :return: None """ _now = time.monotonic() From d65fd655c72476d059913e8cce99ad312a06c8e7 Mon Sep 17 00:00:00 2001 From: Robert Grizzell Date: Mon, 16 May 2022 21:45:25 -0500 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- adafruit_display_text/scrolling_label.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 24e46a8..9e489f1 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -27,10 +27,8 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git" try: - from typing import Union, Optional - from fontio import BuiltinFont - from adafruit_bitmap_font.bdf import BDF - from adafruit_bitmap_font.pcf import PCF + from typing import Optional + from fontio import FontProtocol except ImportError: pass @@ -43,7 +41,7 @@ class ScrollingLabel(bitmap_label.Label): in order to show the full text if it's larger than the fixed-width. :param font: The font to use for the label. - :type font: ~BuiltinFont, ~BDF, or ~PCF + :type: ~FontProtocol :param int max_characters: The number of characters that sets the fixed-width. Default is 10. :param str text: The full text to show in the label. If this is longer than ``max_characters`` then the label will scroll to show everything. @@ -55,8 +53,8 @@ class ScrollingLabel(bitmap_label.Label): # pylint: disable=too-many-arguments def __init__( self, - font: Union[BuiltinFont, BDF, PCF], - max_characters: Optional[int] = 10, + font: FontProtocol, + max_characters: int = 10, text: Optional[str] = "", animate_time: Optional[float] = 0.3, current_index: Optional[int] = 0, @@ -135,7 +133,7 @@ def full_text(self) -> str: """The full text to be shown. If it's longer than ``max_characters`` then scrolling will occur as needed. - :return string: The full text of this label. + :return str: The full text of this label. """ return self._full_text From 9417ccc6e033d9a77951835b77bc9f050b210380 Mon Sep 17 00:00:00 2001 From: Robert Grizzell Date: Mon, 16 May 2022 21:48:16 -0500 Subject: [PATCH 5/6] Applying remaining suggestions from PR --- adafruit_display_text/scrolling_label.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_display_text/scrolling_label.py b/adafruit_display_text/scrolling_label.py index 9e489f1..a83ef2a 100644 --- a/adafruit_display_text/scrolling_label.py +++ b/adafruit_display_text/scrolling_label.py @@ -73,7 +73,7 @@ def __init__( self.update() - def update(self, force: Optional[bool] = False) -> None: + def update(self, force: bool = False) -> None: """Attempt to update the display. If ``animate_time`` has elapsed since previews animation frame then move the characters over by 1 index. Must be called in the main loop of user code. @@ -122,7 +122,7 @@ def current_index(self) -> int: return self._current_index @current_index.setter - def current_index(self, new_index: int): + def current_index(self, new_index: int) -> None: if new_index < len(self.full_text): self._current_index = new_index else: @@ -138,7 +138,7 @@ def full_text(self) -> str: return self._full_text @full_text.setter - def full_text(self, new_text: str): + def full_text(self, new_text: str) -> None: if new_text[-1] != " ": new_text = "{} ".format(new_text) self._full_text = new_text From 0cc84af3e52fba29e486fbf1deb9c90d186f0631 Mon Sep 17 00:00:00 2001 From: Robert Grizzell Date: Wed, 18 May 2022 22:23:48 -0500 Subject: [PATCH 6/6] Setting minimum version for adafruit-blinka-displayio --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 35051e6..e67f709 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,5 @@ # SPDX-License-Identifier: Unlicense Adafruit-Blinka -adafruit-blinka-displayio +adafruit-blinka-displayio>=0.10.2 adafruit-circuitpython-bitmap-font diff --git a/setup.py b/setup.py index 3efcd0e..b5d98d1 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ author_email="circuitpython@adafruit.com", install_requires=[ "Adafruit-Blinka", - "adafruit-blinka-displayio", + "adafruit-blinka-displayio>=0.10.2", "adafruit-circuitpython-bitmap-font", ], # Choose your license