@@ -44,14 +44,25 @@ def load_font(fontname, text):
4444 font .load_glyphs (text .encode ('utf-8' ))
4545 return font
4646
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 ):
4848 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 )
5151 text_area .x = x
5252 text_area .y = y
5353 return text_area
5454
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+
5566display = tft_gizmo .TFT_Gizmo ()
5667group = displayio .Group (max_size = 20 )
5768display .show (group )
@@ -70,9 +81,9 @@ def make_label(text, x, y, color, font=terminalio.FONT):
7081
7182 # Draw the text fields
7283 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" )
7687 status_label = make_label ("None" , 80 , 220 , STATUS_COLOR , font = "/fonts/Arial-16.bdf" )
7788 group .append (make_background (240 , 240 , BACKGROUND_COLOR ))
7889 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):
90101 print ("paired" )
91102
92103 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 = "?"
96108 if ams .playing :
97- status_label . text = "Playing on {}" . format ( ams . player_name )
109+ action = "Playing"
98110 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 )
100113 if cp .button_a :
101114 ams .toggle_play_pause ()
102115 time .sleep (0.1 )
0 commit comments