|
3 | 3 |
|
4 | 4 | # Example demonstrating the CircuitPython ScrollBox widget for vertical scrolling of text.
|
5 | 5 |
|
6 |
| -import displayio_scrollbox |
7 |
| - |
8 |
| -import gc |
9 | 6 | import board
|
| 7 | +import math |
10 | 8 | import time
|
11 |
| -import displayio |
12 |
| -import fontio |
13 | 9 | import terminalio
|
14 | 10 |
|
15 |
| -from adafruit_bitmap_font import bitmap_font |
16 |
| - |
17 |
| -import math |
| 11 | +import displayio_scrollbox |
18 | 12 |
|
19 |
| -display=board.DISPLAY |
| 13 | +display = board.DISPLAY |
20 | 14 |
|
21 | 15 | text_string = "CircuitPython is a programming language designed to simplify experimenting and learning to code on low-cost microcontroller boards."
|
22 |
| -text_string = text_string+("\n\nWith CircuitPython, there are no upfront desktop downloads needed. Once you get your board set up, open any text editor, and start editing code. It's that simple.") |
| 16 | +text_string = text_string + ( |
| 17 | + "\n\nWith CircuitPython, there are no upfront desktop downloads needed. Once you get your board set up, open any text editor, and start editing code. It's that simple." |
| 18 | +) |
23 | 19 | # text_string = text_string+("\n\nCreate a file, edit your code, save the file, and it runs immediately. There is no compiling or uploading needed.")
|
24 | 20 | # text_string = text_string+("\n\nCircuitPython is designed with education in mind. It's an easy way to start learning how to code and you get immediate feedback from the board.")
|
25 | 21 |
|
26 |
| - |
27 | 22 | ## Base example uses the builtin monospace font: terminalio.FONT
|
28 | 23 | font = terminalio.FONT
|
29 | 24 |
|
30 | 25 | # Initialize the scroll box
|
31 |
| -my_scroll_box = displayio_scrollbox.ScrollBox(display=display, |
32 |
| - x=20, y=20, |
33 |
| - width=150, height=100, |
34 |
| - text=text_string, |
35 |
| - starting_row=0, |
36 |
| - font=font, |
37 |
| - background_color=0x333333, |
38 |
| - animation_time=1.2, |
39 |
| - x_offset=5, |
40 |
| - y_offset=5, |
41 |
| - ) |
| 26 | +my_scroll_box = displayio_scrollbox.ScrollBox( |
| 27 | + display=display, |
| 28 | + x=20, |
| 29 | + y=20, |
| 30 | + width=150, |
| 31 | + height=100, |
| 32 | + text=text_string, |
| 33 | + starting_row=0, |
| 34 | + font=font, |
| 35 | + background_color=0x333333, |
| 36 | + animation_time=1.2, |
| 37 | + x_offset=5, |
| 38 | + y_offset=5, |
| 39 | +) |
42 | 40 |
|
43 | 41 | # Set the x and y positions of the ScrollBox
|
44 |
| -my_scroll_box.x=(display.width - my_scroll_box.width)//2 |
45 |
| -my_scroll_box.y=(display.height - my_scroll_box.height)//2 |
| 42 | +my_scroll_box.x = (display.width - my_scroll_box.width) // 2 |
| 43 | +my_scroll_box.y = (display.height - my_scroll_box.height) // 2 |
46 | 44 |
|
47 | 45 |
|
48 | 46 | # Set the number of scrolling rows and number of steps based on the ScrollBox dimensions
|
49 | 47 | move_rows = my_scroll_box.height - 10
|
50 |
| -steps = math.floor(my_scroll_box.max_row/move_rows) |
51 |
| -sleep_time=0.8 |
| 48 | +steps = math.floor(my_scroll_box.max_row / move_rows) |
| 49 | +sleep_time = 0.8 |
52 | 50 |
|
53 | 51 | # Add the ScrollBox to the display
|
54 | 52 | display.show(my_scroll_box)
|
55 | 53 |
|
56 |
| -while True: |
| 54 | +while True: |
57 | 55 |
|
58 | 56 | for i in range(steps):
|
59 | 57 | # Scroll up by the "move_rows" number of pixels
|
60 | 58 | my_scroll_box.scroll(ypixels=+move_rows)
|
61 | 59 | time.sleep(sleep_time)
|
62 | 60 |
|
63 |
| - time.sleep(2*sleep_time) |
| 61 | + time.sleep(2 * sleep_time) |
| 62 | + |
| 63 | + my_scroll_box.text = "This is a shorter line now" |
64 | 64 |
|
65 | 65 | for i in range(steps):
|
66 | 66 | # Scroll down by the "move_rows" number of pixels
|
67 | 67 | my_scroll_box.scroll(ypixels=-move_rows)
|
68 | 68 | time.sleep(sleep_time)
|
69 | 69 |
|
70 |
| - time.sleep(2*sleep_time) |
71 |
| - |
72 |
| - |
73 |
| - |
74 |
| - |
75 |
| - |
76 |
| - |
77 |
| - |
| 70 | + time.sleep(2 * sleep_time) |
0 commit comments