Skip to content

Conversation

@jposada202020
Copy link
Contributor

@jposada202020 jposada202020 commented Mar 12, 2021

Features

The change will add the feature to use label with styles. With this feature you could possible create the same style among differents widgets. The syles are taken from the PySimpleGui Project

Changes

There are changes in the following files:
init: A new function is added. This function converts the color str representation used in colorset used in the source library
label.py: a New class LabelT is added. This class is a child of label, This could use the theme as a parameter.
styles.py: New file including the colorsets. the idea to create a new file will be to share among different widgets. This could be easily done adding entries to the dictionary.
display_text_label_styles.py: new example

Tests

Expected result of the example is:
image

Others

See adafruit/Adafruit_CircuitPython_Colorsys#13 for project updates

TEST CODE

# SPDX-FileCopyrightText: 2021 Jose David Montoya
# SPDX-License-Identifier: MIT

import terminalio
import displayio
from os import uname
import time

if uname()[0] == 'samd51':
    import board
else:
    from blinka_displayio_pygamedisplay import PyGameDisplay
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font

if uname()[0] == 'samd51':
    display = board.DISPLAY
else:
    display = PyGameDisplay(width=320, height=240)
splash = displayio.Group(max_size=10)
MEDIUM_FONT = bitmap_font.load_font("fonts/Helvetica-Bold-16.bdf")

text = "CircuitPython"
text_area = label.Label(MEDIUM_FONT,
                        text=text,
                        label_direction="LTR",
                        background_tight=True,
                        x=155,
                        y=110,
                        padding_left=10,
                        padding_top=10,
                        padding_bottom=10,
                        padding_right=10,)

splash.append(text_area)
display.show(splash)
time.sleep(1)

text_area.label_direction = "UPR"
text_area.label_style = "DarkRed2"
display.show(splash)
time.sleep(1)
text_area.label_direction = "RTL"
text_area.label_style = "DarkGreen5"
display.show(splash)
time.sleep(1)
text_area.label_direction = "DWR"
text_area.label_style = "LightGreen8"
display.show(splash)
time.sleep(1)
text_area.label_direction = "TTB"
display.show(splash)
time.sleep(1)
text = "CircuitPython"

while True:
    pass

jposada202020 and others added 13 commits March 9, 2021 21:42
# Conflicts:
#	adafruit_display_text/__init__.py
This change addresses cases when Label class is initialized with
max_glyphs instead of text. In such cases, the split function is
attempted on None object instead of an empty string:

  File "/lib/adafruit_display_text/label.py", line 84, in __init__
  AttributeError: 'NoneType' object has no attribute 'split'

Fixes: #141
@jposada202020
Copy link
Contributor Author

See this issue for updates adafruit/Adafruit_CircuitPython_Colorsys#13 and possible changes.

@jposada202020 jposada202020 mentioned this pull request Mar 15, 2021
@jposada202020
Copy link
Contributor Author

Replace by PR #143 .

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants