From a4670838db37b31da7c2337492a6106fb9d415ee Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 22 Feb 2023 09:56:23 -0500 Subject: [PATCH] adding_verbose_option --- adafruit_display_text/__init__.py | 6 +++++- adafruit_display_text/bitmap_label.py | 25 +++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index 6586857..017f6be 100755 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -221,7 +221,9 @@ class LabelBase(Group): (4, " ") will indicate a tab replacement of 4 spaces, defaults to 4 spaces by tab character :param str label_direction: string defining the label text orientation. See the - subclass documentation for the possible values.""" + subclass documentation for the possible values. + :param bool verbose: print debugging information in some internal functions. Default to False + """ def __init__( self, @@ -243,6 +245,7 @@ def __init__( base_alignment: bool = False, 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 @@ -266,6 +269,7 @@ def __init__( self._label_direction = label_direction self._tab_replacement = tab_replacement 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.") diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 0a40a17..d2a994a 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -80,7 +80,10 @@ class Label(LabelBase): tab character :param str label_direction: string defining the label text orientation. There are 5 configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left - ``UPD``-Upside Down ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``""" + ``UPD``-Upside Down ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR`` + :param bool verbose: print debugging information in some internal functions. Default to False + + """ # This maps label_direction to TileGrid's transpose_xy, flip_x, flip_y _DIR_MAP = { @@ -350,6 +353,7 @@ def _text_bounding_box( final_y_offset_loose, ) + # pylint: disable = too-many-branches def _place_text( self, bitmap: displayio.Bitmap, @@ -418,19 +422,20 @@ def _place_text( if y_blit_target < 0: y_clip = -y_blit_target # clip this amount from top of bitmap y_blit_target = 0 # draw the clipped bitmap at y=0 - - print( - 'Warning: Glyph clipped, exceeds Ascent property: "{}"'.format( - char + if self._verbose: + print( + 'Warning: Glyph clipped, exceeds Ascent property: "{}"'.format( + char + ) ) - ) if (y_blit_target + my_glyph.height) > bitmap.height: - print( - 'Warning: Glyph clipped, exceeds descent property: "{}"'.format( - char + if self._verbose: + print( + 'Warning: Glyph clipped, exceeds descent property: "{}"'.format( + char + ) ) - ) self._blit( bitmap,