From 54f3729114160c5692e13f26ef7c304654778d34 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Thu, 18 Mar 2021 22:58:20 -0400 Subject: [PATCH 01/13] initial Commit for draft --- adafruit_display_text/bitmap_label.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index fa06596..6e3d884 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -76,7 +76,10 @@ class Label(LabelBase): This is helpful when two or more labels need to be aligned to the same baseline :param (int,str) tab_replacement: tuple with tab character replace information. When (4, " ") will indicate a tab replacement of 4 spaces, defaults to 4 spaces by - tab character""" + 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 + ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments # pylint: disable=too-many-branches, no-self-use, too-many-statements From c3b0269cd9e938cb38ff85a841cd0bee2bc37c88 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Fri, 19 Mar 2021 22:27:49 -0400 Subject: [PATCH 02/13] Working. Anchor position still not working. possible related with current issue. --- adafruit_display_text/bitmap_label.py | 53 ++++++++++++++++++--------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 6e3d884..271802b 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -79,7 +79,7 @@ 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 - ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``""" + ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments # pylint: disable=too-many-branches, no-self-use, too-many-statements @@ -106,6 +106,10 @@ def __init__(self, font, **kwargs) -> None: self.color = kwargs.get("color", 0xFFFFFF) self.background_color = kwargs.get("background_color", None) + self._label_direction = kwargs.get("label_direction", "LTR") + + if self._label_direction == "RTL": + self._text = "".join(reversed(self._text)) self.base_alignment = kwargs.get("base_alignment", False) @@ -127,26 +131,28 @@ def __init__(self, font, **kwargs) -> None: scale=kwargs.get("scale", 1), base_alignment=kwargs.get("base_alignment", False), tab_replacement=kwargs.get("tab_replacement", (4, " ")), + label_direction=kwargs.get("label_direction", "LTR"), ) def _reset_text( - self, - font=None, - x: int = None, - y: int = None, - text: str = None, - line_spacing: float = None, - background_tight: bool = None, - padding_top: int = None, - padding_bottom: int = None, - padding_left: int = None, - padding_right: int = None, - anchor_point: Tuple[float, float] = None, - anchored_position: Tuple[int, int] = None, - save_text: bool = None, - scale: int = None, - base_alignment: bool = None, - tab_replacement: Tuple[int, str] = None, + self, + font=None, + x: int = None, + y: int = None, + text: str = None, + line_spacing: float = None, + background_tight: bool = None, + padding_top: int = None, + padding_bottom: int = None, + padding_left: int = None, + padding_right: int = None, + anchor_point: Tuple[float, float] = None, + anchored_position: Tuple[int, int] = None, + save_text: bool = None, + scale: int = None, + base_alignment: bool = None, + tab_replacement: Tuple[int, str] = None, + label_direction: str = "LTR", ) -> None: # Store all the instance variables @@ -178,6 +184,8 @@ def _reset_text( self.base_alignment = base_alignment if tab_replacement is not None: self._tab_replacement = tab_replacement + if label_direction is not None: + self._label_direction = label_direction # if text is not provided as a parameter (text is None), use the previous value. if (text is None) and self._save_text: @@ -185,6 +193,8 @@ def _reset_text( if self._save_text: # text string will be saved self._text = self._tab_text.join(text.split("\t")) + if self._label_direction == "RTL": + self._text = "".join(reversed(self._text)) else: self._text = None # save a None value since text string is not saved @@ -266,6 +276,13 @@ def _reset_text( y=label_position_yoffset - y_offset - self._padding_top, ) + if self._label_direction == "UPR": + self.tilegrid.transpose_xy = True + self.tilegrid.flip_x = True + if self._label_direction == "DWR": + self.tilegrid.transpose_xy = True + self.tilegrid.flip_y = True + # Clear out any items in the local_group Group, in case this is an update to # the bitmap_label for _ in self.local_group: From 3f5a042246d7c5f3e3e504f15de6fcd0108494aa Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Fri, 19 Mar 2021 22:32:40 -0400 Subject: [PATCH 03/13] Black format --- adafruit_display_text/bitmap_label.py | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 271802b..af3d7a9 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -135,24 +135,24 @@ def __init__(self, font, **kwargs) -> None: ) def _reset_text( - self, - font=None, - x: int = None, - y: int = None, - text: str = None, - line_spacing: float = None, - background_tight: bool = None, - padding_top: int = None, - padding_bottom: int = None, - padding_left: int = None, - padding_right: int = None, - anchor_point: Tuple[float, float] = None, - anchored_position: Tuple[int, int] = None, - save_text: bool = None, - scale: int = None, - base_alignment: bool = None, - tab_replacement: Tuple[int, str] = None, - label_direction: str = "LTR", + self, + font=None, + x: int = None, + y: int = None, + text: str = None, + line_spacing: float = None, + background_tight: bool = None, + padding_top: int = None, + padding_bottom: int = None, + padding_left: int = None, + padding_right: int = None, + anchor_point: Tuple[float, float] = None, + anchored_position: Tuple[int, int] = None, + save_text: bool = None, + scale: int = None, + base_alignment: bool = None, + tab_replacement: Tuple[int, str] = None, + label_direction: str = "LTR", ) -> None: # Store all the instance variables From 4d72041d6ef5b747ad05fc349e6c9fd6352580fc Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Mar 2021 20:58:45 -0400 Subject: [PATCH 04/13] UPDATE - UPD direction inclusion - Docs Update --- adafruit_display_text/__init__.py | 38 ++++++++++++++++++++++++--- adafruit_display_text/bitmap_label.py | 5 +++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index a3ddb52..c6176fb 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -161,36 +161,67 @@ class LabelBase(Group): Subclasses should implement ``_set_text``, ``_set_font``, and ``_set_line_spacing`` to have the correct behavior for that type of label. + Anchor points are represented in the corners of the following graph + + (0.0,0.0)┌──────────────────────────────────────────────────────────────┐ (1.0,0.0) + │ @@ | │ + │ @@ Ascent │ + │ @@ | │ + │------------------------------------------@@+-----|-----------│ + │ %@ @% @@@@@@@@% %@@@@@@@@ | │ + │ %@ @% @@% %@ @% %@@ | │ + │ %@% @@ @% %@ @@ | │ Bounding BOX + │ %@% @@ @$ $@ @@ | │ + │ %@ @% @@$ @ @% $@@ | │ + │ %@ @% @@@@@@@% %@@@@@@@ | │ + │-------------------@@+----------------------------------------│ Baseline + │ @@ | │ + │ @@ Descent │ + │ @@___| │ + (0.0,1.0)╰──────────────────────────────────────────────────────────────┘(1.0,1.0) + + :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. Must include a capital M for measuring character size. :param str text: Text to display :param int max_glyphs: Unnecessary parameter (provided only for direct compability with :py:func:`~adafruit_display_text.label.Label`) + :param int color: Color of all text in RGB hex :param int background_color: Color of the background, use `None` for transparent + :param float line_spacing: Line spacing of text to display + :param bool background_tight: Set `True` only if you want background box to tightly surround text. When set to 'True' Padding parameters will be ignored. + :param int padding_top: Additional pixels added to background bounding box at top :param int padding_bottom: Additional pixels added to background bounding box at bottom :param int padding_left: Additional pixels added to background bounding box at left :param int padding_right: Additional pixels added to background bounding box at right + :param (float,float) anchor_point: Point that anchored_position moves relative to. Tuple with decimal percentage of width and height. (E.g. (0,0) is top left, (1.0, 0.5): is middle right.) :param (int,int) anchored_position: Position relative to the anchor_point. Tuple containing x,y pixel coordinates. + :param int scale: Integer value of the pixel scaling + :param bool save_text: Set True to save the text string as a constant in the label structure. Set False to reduce memory use. + :param bool base_alignment: when True allows to align text label to the baseline. This is helpful when two or more labels need to be aligned to the same baseline + :param (int,str) tab_replacement: tuple with tab character replace information. When (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. There are 5 configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left - ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``""" + ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards and ``UPD``-Upside-Down + (bitmap_label only). It defaults to ``LTR``""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments def __init__( @@ -235,7 +266,7 @@ def __init__( self._text = text - if label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB"]: + if label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB", "UPD"]: raise RuntimeError("Please provide a valid text direction") self._label_direction = label_direction @@ -384,6 +415,7 @@ def bounding_box(self) -> Tuple[int, int]: first two numbers are offset from the x, y origin of this group""" return tuple(self._bounding_box) + # pylint: disable=no-member @property def line_spacing(self) -> float: """The amount of space between lines of text, in multiples of the font's @@ -410,6 +442,6 @@ def _set_label_direction(self, new_label_direction: str) -> None: @label_direction.setter def label_direction(self, new_label_direction: str) -> None: """Set the text direction of the label""" - if new_label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB"]: + if new_label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB", "UPD"]: raise RuntimeError("Please provide a valid text direction") self._set_label_direction(new_label_direction) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index af3d7a9..1613793 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -79,7 +79,7 @@ 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 - ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``""" + ``UPR``-Upwards ``DWR``-Downwards and ``UPD``-Upside-Down. It defaults to ``LTR``""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments # pylint: disable=too-many-branches, no-self-use, too-many-statements @@ -282,6 +282,9 @@ def _reset_text( if self._label_direction == "DWR": self.tilegrid.transpose_xy = True self.tilegrid.flip_y = True + if self._label_direction == "UPD": + self.tilegrid.flip_x = True + self.tilegrid.flip_y = True # Clear out any items in the local_group Group, in case this is an update to # the bitmap_label From 4eb377c4a58049bafd96e0519020eac8117a5dbe Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Mar 2021 21:08:00 -0400 Subject: [PATCH 05/13] UPDATE - Spaces --- adafruit_display_text/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index c6176fb..98a08d0 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -32,7 +32,6 @@ def wrap_text_to_pixels( :return: A list of the lines resulting from wrapping the input text at ``max_width`` pixels size :rtype: List[str] - """ # pylint: disable=too-many-locals, too-many-branches if font is None: @@ -180,7 +179,6 @@ class LabelBase(Group): │ @@___| │ (0.0,1.0)╰──────────────────────────────────────────────────────────────┘(1.0,1.0) - :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. Must include a capital M for measuring character size. :param str text: Text to display @@ -221,7 +219,8 @@ class LabelBase(Group): :param str label_direction: string defining the label text orientation. There are 5 configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards and ``UPD``-Upside-Down - (bitmap_label only). It defaults to ``LTR``""" + (bitmap_label only). It defaults to ``LTR`` + """ # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments def __init__( From 246f78e23c4ec4ae12ec4cd4fd62469649087110 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Mar 2021 21:14:46 -0400 Subject: [PATCH 06/13] Docs Corrections --- adafruit_display_text/__init__.py | 34 ++----------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index 98a08d0..6dd9714 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -32,6 +32,7 @@ def wrap_text_to_pixels( :return: A list of the lines resulting from wrapping the input text at ``max_width`` pixels size :rtype: List[str] + """ # pylint: disable=too-many-locals, too-many-branches if font is None: @@ -159,68 +160,37 @@ class LabelBase(Group): Subclasses should implement ``_set_text``, ``_set_font``, and ``_set_line_spacing`` to have the correct behavior for that type of label. - - Anchor points are represented in the corners of the following graph - - (0.0,0.0)┌──────────────────────────────────────────────────────────────┐ (1.0,0.0) - │ @@ | │ - │ @@ Ascent │ - │ @@ | │ - │------------------------------------------@@+-----|-----------│ - │ %@ @% @@@@@@@@% %@@@@@@@@ | │ - │ %@ @% @@% %@ @% %@@ | │ - │ %@% @@ @% %@ @@ | │ Bounding BOX - │ %@% @@ @$ $@ @@ | │ - │ %@ @% @@$ @ @% $@@ | │ - │ %@ @% @@@@@@@% %@@@@@@@ | │ - │-------------------@@+----------------------------------------│ Baseline - │ @@ | │ - │ @@ Descent │ - │ @@___| │ - (0.0,1.0)╰──────────────────────────────────────────────────────────────┘(1.0,1.0) - :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. Must include a capital M for measuring character size. :param str text: Text to display :param int max_glyphs: Unnecessary parameter (provided only for direct compability with :py:func:`~adafruit_display_text.label.Label`) - :param int color: Color of all text in RGB hex :param int background_color: Color of the background, use `None` for transparent - :param float line_spacing: Line spacing of text to display - :param bool background_tight: Set `True` only if you want background box to tightly surround text. When set to 'True' Padding parameters will be ignored. - :param int padding_top: Additional pixels added to background bounding box at top :param int padding_bottom: Additional pixels added to background bounding box at bottom :param int padding_left: Additional pixels added to background bounding box at left :param int padding_right: Additional pixels added to background bounding box at right - :param (float,float) anchor_point: Point that anchored_position moves relative to. Tuple with decimal percentage of width and height. (E.g. (0,0) is top left, (1.0, 0.5): is middle right.) :param (int,int) anchored_position: Position relative to the anchor_point. Tuple containing x,y pixel coordinates. - :param int scale: Integer value of the pixel scaling - :param bool save_text: Set True to save the text string as a constant in the label structure. Set False to reduce memory use. - :param bool base_alignment: when True allows to align text label to the baseline. This is helpful when two or more labels need to be aligned to the same baseline - :param (int,str) tab_replacement: tuple with tab character replace information. When (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. There are 5 configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards and ``UPD``-Upside-Down - (bitmap_label only). It defaults to ``LTR`` - """ + (bitmap_label only). It defaults to ``LTR``""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments def __init__( From aeea65e15a23f6231517beac607ea7b5e3e0f6ec Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Mar 2021 21:27:40 -0400 Subject: [PATCH 07/13] Docs Corrections --- adafruit_display_text/__init__.py | 5 ++--- adafruit_display_text/bitmap_label.py | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index 6dd9714..f91a0c6 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -189,8 +189,8 @@ class LabelBase(Group): 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 - ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards and ``UPD``-Upside-Down - (bitmap_label only). It defaults to ``LTR``""" + ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards``DWR``-Downwards and + ``UPD``-Upside-Down only avalaible for bitmap_label. It defaults to ``LTR``""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments def __init__( @@ -384,7 +384,6 @@ def bounding_box(self) -> Tuple[int, int]: first two numbers are offset from the x, y origin of this group""" return tuple(self._bounding_box) - # pylint: disable=no-member @property def line_spacing(self) -> float: """The amount of space between lines of text, in multiples of the font's diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 1613793..92312df 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -40,16 +40,13 @@ class Label(LabelBase): This method is memory-conserving relative to ``label.py``. The ``max_glyphs`` parameter is ignored and is present only for direct compatibility with label.py. - For further reduction in memory usage, set ``save_text=False`` (text string will not be stored and ``line_spacing`` and ``font`` are immutable with ``save_text`` set to ``False``). - The origin point set by ``x`` and ``y`` properties will be the left edge of the bounding box, and in the center of a M glyph (if its one line), or the (number of lines * linespacing + M)/2. That is, it will try to have it be center-left as close as possible. - :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. Must include a capital M for measuring character size. :param str text: Text to display From 97c591553fee3a1f214a15c9b3100e1c11e18f55 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Mar 2021 21:34:56 -0400 Subject: [PATCH 08/13] Using same __init__ as the repo --- adafruit_display_text/__init__.py | 8 ++++---- docs/examples.rst | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index f91a0c6..a3ddb52 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -160,6 +160,7 @@ class LabelBase(Group): Subclasses should implement ``_set_text``, ``_set_font``, and ``_set_line_spacing`` to have the correct behavior for that type of label. + :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. Must include a capital M for measuring character size. :param str text: Text to display @@ -189,8 +190,7 @@ class LabelBase(Group): 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 - ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards``DWR``-Downwards and - ``UPD``-Upside-Down only avalaible for bitmap_label. It defaults to ``LTR``""" + ``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments def __init__( @@ -235,7 +235,7 @@ def __init__( self._text = text - if label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB", "UPD"]: + if label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB"]: raise RuntimeError("Please provide a valid text direction") self._label_direction = label_direction @@ -410,6 +410,6 @@ def _set_label_direction(self, new_label_direction: str) -> None: @label_direction.setter def label_direction(self, new_label_direction: str) -> None: """Set the text direction of the label""" - if new_label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB", "UPD"]: + if new_label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB"]: raise RuntimeError("Please provide a valid text direction") self._set_label_direction(new_label_direction) diff --git a/docs/examples.rst b/docs/examples.rst index e61fe4c..6b8a109 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,30 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/display_text_simpletest.py :caption: examples/display_text_simpletest.py :linenos: + +Bitmap_label Simple test +------------------------ + +Simple test using bitmap_label to display text + +.. literalinclude:: ../examples/display_text_bitmap_label_simpletest.py + :caption: examples/display_text_bitmap_label_simpletest.py + :linenos: + +Label vs Bitmap_label Comparison +-------------------------------- + +Example to compare Label and Bitmap_Label characteristics + +.. literalinclude:: ../examples/display_text_label_vs_bitmap_label_comparison.py + :caption: examples/display_text_label_vs_bitmap_label_comparison.py + :linenos: + +Label vs Bitmap_label Comparison +-------------------------------- + +Example to compare Label and Bitmap_Label characteristics + +.. literalinclude:: ../examples/display_text_label_vs_bitmap_label_comparison.py + :caption: examples/display_text_label_vs_bitmap_label_comparison.py + :linenos: \ No newline at end of file From f943d0dec1617786128459d20b7773d7c0acf3da Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Mar 2021 21:35:45 -0400 Subject: [PATCH 09/13] Using same __init__ as the repo --- docs/examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples.rst b/docs/examples.rst index 6b8a109..4d97689 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -32,4 +32,4 @@ Example to compare Label and Bitmap_Label characteristics .. literalinclude:: ../examples/display_text_label_vs_bitmap_label_comparison.py :caption: examples/display_text_label_vs_bitmap_label_comparison.py - :linenos: \ No newline at end of file + :linenos: From c8b9475a1a9bd3c48f1c3f01bff6310111e3dfe9 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Mar 2021 21:47:49 -0400 Subject: [PATCH 10/13] Line 14 --- adafruit_display_text/bitmap_label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 92312df..06d68ba 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -48,7 +48,7 @@ class Label(LabelBase): glyph (if its one line), or the (number of lines * linespacing + M)/2. That is, it will try to have it be center-left as close as possible. :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. - Must include a capital M for measuring character size. + Must include a capital M for measuring character size. :param str text: Text to display :param int max_glyphs: Unnecessary parameter (provided only for direct compability with label.py) From 69909e75f3451fa1aa2730c635f95aaafaa5db79 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Mar 2021 21:57:32 -0400 Subject: [PATCH 11/13] Original Docs --- adafruit_display_text/bitmap_label.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 06d68ba..0c62b9e 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -40,15 +40,18 @@ class Label(LabelBase): This method is memory-conserving relative to ``label.py``. The ``max_glyphs`` parameter is ignored and is present only for direct compatibility with label.py. + For further reduction in memory usage, set ``save_text=False`` (text string will not be stored and ``line_spacing`` and ``font`` are immutable with ``save_text`` set to ``False``). + The origin point set by ``x`` and ``y`` properties will be the left edge of the bounding box, and in the center of a M glyph (if its one line), or the (number of lines * linespacing + M)/2. That is, it will try to have it be center-left as close as possible. + :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. - Must include a capital M for measuring character size. + Must include a capital M for measuring character size. :param str text: Text to display :param int max_glyphs: Unnecessary parameter (provided only for direct compability with label.py) @@ -76,7 +79,7 @@ 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 - ``UPR``-Upwards ``DWR``-Downwards and ``UPD``-Upside-Down. It defaults to ``LTR``""" + ``UPD``-Upside Down ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments # pylint: disable=too-many-branches, no-self-use, too-many-statements From d0baee4638f7b4fd877b2cb72a33d8e773da70f0 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sat, 27 Mar 2021 20:46:03 -0400 Subject: [PATCH 12/13] # TODO Label Exceptions corrections --- adafruit_display_text/__init__.py | 2 -- adafruit_display_text/bitmap_label.py | 3 +++ adafruit_display_text/label.py | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index a3ddb52..7cb2186 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -235,8 +235,6 @@ def __init__( self._text = text - if label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB"]: - raise RuntimeError("Please provide a valid text direction") self._label_direction = label_direction self.baseline = -1.0 diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 0c62b9e..a9daedd 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -108,6 +108,9 @@ def __init__(self, font, **kwargs) -> None: self.background_color = kwargs.get("background_color", None) self._label_direction = kwargs.get("label_direction", "LTR") + if self._label_direction not in ["LTR", "RTL", "UPD", "UPR", "DWR"]: + raise RuntimeError("Please provide a valid text direction") + if self._label_direction == "RTL": self._text = "".join(reversed(self._text)) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 4e7373a..3fbd0fb 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -127,6 +127,9 @@ def __init__(self, font, **kwargs) -> None: self.base_alignment = kwargs.get("base_alignment", False) self._label_direction = kwargs.get("label_direction", "LTR") + if self._label_direction not in ["LTR", "RTL", "UPR", "DWR", "TTB"]: + raise RuntimeError("Please provide a valid text direction") + if text is not None: self._update_text(str(text)) if (kwargs.get("anchored_position", None) is not None) and ( From cc7f47869a74267cdac18ef534b6f43e557dfc8a Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Sun, 28 Mar 2021 12:27:56 -0400 Subject: [PATCH 13/13] Update examples.rst Deleting duplicate in exampl.rst file --- docs/examples.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index 4d97689..971a172 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -24,12 +24,3 @@ Example to compare Label and Bitmap_Label characteristics .. literalinclude:: ../examples/display_text_label_vs_bitmap_label_comparison.py :caption: examples/display_text_label_vs_bitmap_label_comparison.py :linenos: - -Label vs Bitmap_label Comparison --------------------------------- - -Example to compare Label and Bitmap_Label characteristics - -.. literalinclude:: ../examples/display_text_label_vs_bitmap_label_comparison.py - :caption: examples/display_text_label_vs_bitmap_label_comparison.py - :linenos: