@@ -44,14 +44,25 @@ def load_font(fontname, text):
44
44
font .load_glyphs (text .encode ('utf-8' ))
45
45
return font
46
46
47
- def make_label (text , x , y , color , font = terminalio .FONT ):
47
+ def make_label (text , x , y , color , max_glyphs = 30 , font = terminalio .FONT ):
48
48
if isinstance (font , str ):
49
- font = load_font (font , "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,?" )
50
- text_area = Label (font , text = text , color = color , max_glyphs = 30 )
49
+ font = load_font (font , "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,?() " )
50
+ text_area = Label (font , text = text , color = color , max_glyphs = max_glyphs )
51
51
text_area .x = x
52
52
text_area .y = y
53
53
return text_area
54
54
55
+ def set_label (label , value , max_length ):
56
+ text = "{}" .format (value )
57
+ if len (text ) > max_length :
58
+ text = text [:max_length - 3 ] + "..."
59
+ label .text = text
60
+
61
+ def set_status (label , action_text , player ):
62
+ label .text = "{} on {}" .format (action_text , player )
63
+ _ , _ , label_width , _ = label .bounding_box
64
+ label .x = display .width - 10 - label_width
65
+
55
66
display = tft_gizmo .TFT_Gizmo ()
56
67
group = displayio .Group (max_size = 20 )
57
68
display .show (group )
@@ -70,9 +81,9 @@ def make_label(text, x, y, color, font=terminalio.FONT):
70
81
71
82
# Draw the text fields
72
83
print ("Loading Font Glyphs..." )
73
- title_label = make_label ("None" , 20 , 20 , TEXT_COLOR , font = "/fonts/Arial-Bold-18 .bdf" )
74
- artist_label = make_label ("None" , 20 , 50 , TEXT_COLOR , font = "/fonts/Arial-16 .bdf" )
75
- album_label = make_label ("None" , 20 , 180 , TEXT_COLOR , font = "/fonts/Arial-16 .bdf" )
84
+ title_label = make_label ("None" , 18 , 30 , TEXT_COLOR , font = "/fonts/Arial-Bold-24 .bdf" )
85
+ artist_label = make_label ("None" , 18 , 70 , TEXT_COLOR , font = "/fonts/Arial-22 .bdf" )
86
+ album_label = make_label ("None" , 18 , 170 , TEXT_COLOR , font = "/fonts/Arial-22 .bdf" )
76
87
status_label = make_label ("None" , 80 , 220 , STATUS_COLOR , font = "/fonts/Arial-16.bdf" )
77
88
group .append (make_background (240 , 240 , BACKGROUND_COLOR ))
78
89
border = Rect (10 , 8 , 200 , 190 , outline = BORDER_COLOR , stroke = 1 )
@@ -90,13 +101,15 @@ def make_label(text, x, y, color, font=terminalio.FONT):
90
101
print ("paired" )
91
102
92
103
ams = connection [AppleMediaService ]
93
- title_label .text = "{}" .format (ams .title )
94
- album_label .text = "{}" .format (ams .album )
95
- artist_label .text = "{}" .format (ams .artist )
104
+ set_label (title_label , ams .title , 12 )
105
+ set_label (album_label , ams .album , 13 )
106
+ set_label (artist_label , ams .artist , 13 )
107
+ action = "?"
96
108
if ams .playing :
97
- status_label . text = "Playing on {}" . format ( ams . player_name )
109
+ action = "Playing"
98
110
elif ams .paused :
99
- status_label .text = "Paused on {}" .format (ams .player_name )
111
+ action = "Paused"
112
+ set_status (status_label , action , ams .player_name )
100
113
if cp .button_a :
101
114
ams .toggle_play_pause ()
102
115
time .sleep (0.1 )
0 commit comments