Simple test

Ensure your device works with this simple test.

examples/styles_simpletest.py
 1# SPDX-FileCopyrightText: 2020 Jose David Montoya
 2# SPDX-License-Identifier: Unlicense
 3
 4"""
 5This example shows the use of library with an adafruit_display_text.label object
 6"""
 7
 8import board
 9import terminalio
10from adafruit_display_text import label
11from styles import apply_style
12from styles.styles import DarkBlue
13
14text = "Hello world"
15text_area = label.Label(terminalio.FONT, text=text)
16text_area.x = 10
17text_area.y = 10
18apply_style(text_area, DarkBlue)
19board.DISPLAY.show(text_area)
20while True:
21    pass

Advanced test

Shows different graphical elements changing styles on the fly.

examples/styles_advanced_example.py
 1# SPDX-FileCopyrightText: 2020 Jose David M.
 2# SPDX-License-Identifier: Unlicense
 3
 4"""
 5This example shows the use of styles in different graphical elements
 6"""
 7
 8import time
 9import board
10import displayio
11from adafruit_display_text import label
12from adafruit_display_text.scrolling_label import ScrollingLabel
13from adafruit_progressbar.horizontalprogressbar import (
14    HorizontalProgressBar,
15    HorizontalFillDirection,
16)
17from adafruit_bitmap_font import bitmap_font
18from adafruit_button import Button
19from styles import apply_style
20from styles.styles import (
21    DarkBlue,
22    BlueMono,
23    GreenMono,
24    BrownBlue,
25    BrightColors,
26)
27
28
29display = board.DISPLAY
30
31# Creating a Label
32font = bitmap_font.load_font("../fonts/Helvetica-Bold-16.bdf")
33text_area = label.Label(font, text="Hello world", x=30, y=30)
34main_group = displayio.Group()
35main_group.append(text_area)
36
37# Creating a Progress Bar
38progress_bar = HorizontalProgressBar(
39    (display.width // 2 - display.width // 2, display.height // 3),
40    (display.width - 40, 30),
41    direction=HorizontalFillDirection.LEFT_TO_RIGHT,
42)
43progress_bar.value = 50
44main_group.append(progress_bar)
45
46# Creating a Button
47button = Button(
48    x=display.width // 2,
49    y=display.height // 2,
50    width=100,
51    height=50,
52    style=Button.ROUNDRECT,
53    fill_color=0x00FFFF,
54    outline_color=0xFF00FF,
55    label="Hello world",
56    label_font=font,
57    label_color=0x000000,
58)
59main_group.append(button)
60
61# Creating a Scrolling Label
62my_scrolling_label = ScrollingLabel(
63    font,
64    text="Hello world CircuitPython scrolling label",
65    max_characters=20,
66    animate_time=0.3,
67    x=30,
68    y=200,
69)
70main_group.append(my_scrolling_label)
71# Preparing the Colors to display
72colors_change = [DarkBlue, BlueMono, GreenMono, BrownBlue, BrightColors]
73display.show(main_group)
74counter = 0
75
76while True:
77    if counter == len(colors_change):
78        counter = 0
79    apply_style(text_area, colors_change[counter])
80    apply_style(progress_bar, colors_change[counter])
81    apply_style(button, colors_change[counter])
82    apply_style(my_scrolling_label, colors_change[counter])
83    current_time_counter = time.time()
84    while True:
85        my_scrolling_label.update()
86        if time.time() - current_time_counter > 4:
87            break
88    display.refresh()
89    time.sleep(4)
90    counter = counter + 1

List Select Example

An example using the community library ListSelect

examples/styles_list_select_example.py
 1# SPDX-FileCopyrightText: Copyright (c) 2021 Tim C, 2022 Jose D. Montoya
 2#
 3# SPDX-License-Identifier: MIT
 4"""
 5Create a list with a few options and move the selection around programmatically.
 6"""
 7import time
 8import displayio
 9import board
10from displayio_listselect import ListSelect
11from styles import apply_style
12from styles.styles import Topanga
13
14# Make the display context. Change size if you want
15display = board.DISPLAY
16
17# Make the display context
18main_group = displayio.Group()
19display.show(main_group)
20
21items = ["First", "Second", "Third", "Fourth"]
22
23list_select = ListSelect(scale=2, items=items)
24
25# Applying some style to the list
26apply_style(list_select, Topanga)
27
28main_group.append(list_select)
29
30list_select.anchor_point = (0.5, 0.5)
31list_select.anchored_position = (display.width // 2, display.height // 2)
32
33for i in range(3):
34    list_select.move_selection_down()
35    time.sleep(1)
36
37for i in range(3):
38    list_select.move_selection_up()
39    time.sleep(1)
40
41list_select.selected_index = 3
42while True:
43    pass