@@ -23,16 +23,18 @@ class WinampApplication(displayio.Group):
23
23
:param playlist_file: json file containing the playlist of songs
24
24
:param skin_image: BMP image file for skin background
25
25
:param skin_config_file: json file containing color values
26
+ :param pyportal_titano: boolean value. True if using Titano, False otherwise.
26
27
"""
27
28
28
29
STATE_PLAYING = 0
29
30
STATE_PAUSED = 1
30
-
31
+ # pylint: disable=too-many-statements
31
32
def __init__ (
32
33
self ,
33
34
playlist_file = "playlist.json" ,
34
35
skin_image = "/base_240x320.bmp" ,
35
36
skin_config_file = "base_config.json" ,
37
+ pyportal_titano = False ,
36
38
):
37
39
self .SKIN_IMAGE = skin_image
38
40
self .SKIN_CONFIG_FILE = skin_config_file
@@ -50,15 +52,35 @@ def __init__(
50
52
51
53
# initialize clock display
52
54
self .clock_display = ClockDisplay (text_color = self .CONFIG_DATA ["time_color" ])
53
- self .clock_display .x = 44
54
- self .clock_display .y = 22
55
+ if not pyportal_titano :
56
+ # standard PyPortal and pynt clock display location
57
+ # and playlist display parameters
58
+ self .clock_display .x = 44
59
+ self .clock_display .y = 22
60
+ _max_playlist_display_chars = 30
61
+ _rows = 3
62
+ else :
63
+ # PyPortal Titano clock display location
64
+ # and playlist display parameters
65
+ self .clock_display .x = 65
66
+ self .clock_display .y = 37
67
+ _max_playlist_display_chars = 42
68
+ _rows = 4
55
69
56
70
# initialize playlist display
57
71
self .playlist_display = PlaylistDisplay (
58
- text_color = self .CONFIG_DATA ["text_color" ]
72
+ text_color = self .CONFIG_DATA ["text_color" ],
73
+ max_chars = _max_playlist_display_chars ,
74
+ rows = _rows ,
59
75
)
60
- self .playlist_display .x = 13
61
- self .playlist_display .y = 234
76
+ if not pyportal_titano :
77
+ # standard PyPortal and pynt playlist display location
78
+ self .playlist_display .x = 13
79
+ self .playlist_display .y = 234
80
+ else :
81
+ # PyPortal Titano playlist display location
82
+ self .playlist_display .x = 20
83
+ self .playlist_display .y = 354
62
84
63
85
# set playlist into playlist display
64
86
self .playlist_display .from_files_list (self .PLAYLIST ["playlist" ]["files" ])
@@ -69,15 +91,26 @@ def __init__(
69
91
self .playlist_display .current_track_number - 1
70
92
]
71
93
94
+ if not pyportal_titano :
95
+ # standard PyPortal and pynt max characters for track title
96
+ _max_chars = 22
97
+ else :
98
+ # PyPortal Titano max characters for track title
99
+ _max_chars = 29
72
100
# initialize ScrollingLabel for track name
73
101
self .current_song_lbl = scrolling_label .ScrollingLabel (
74
102
terminalio .FONT ,
75
103
text = self .playlist_display .current_track_title ,
76
104
color = self .CONFIG_DATA ["text_color" ],
77
- max_characters = 22 ,
105
+ max_characters = _max_chars ,
78
106
)
79
107
self .current_song_lbl .anchor_point = (0 , 0 )
80
- self .current_song_lbl .anchored_position = (98 , 19 )
108
+ if not pyportal_titano :
109
+ # standard PyPortal and pynt track title location
110
+ self .current_song_lbl .anchored_position = (98 , 19 )
111
+ else :
112
+ # PyPortal Titano track title location
113
+ self .current_song_lbl .anchored_position = (130 , 33 )
81
114
82
115
# Setup the skin image file as the bitmap data source
83
116
self .background_bitmap = displayio .OnDiskBitmap (self .SKIN_IMAGE )
@@ -193,8 +226,15 @@ def next_track(self):
193
226
# increment current track number
194
227
self .playlist_display .current_track_number += 1
195
228
196
- # start playing track
197
- self .play_current_track ()
229
+ try :
230
+ # start playing track
231
+ self .play_current_track ()
232
+ except OSError as e :
233
+ # file not found
234
+ print ("Error playing: {}" .format (self .current_song_file_name ))
235
+ print (e )
236
+ self .next_track ()
237
+ return
198
238
199
239
def previous_track (self ):
200
240
"""
@@ -209,8 +249,15 @@ def previous_track(self):
209
249
# decrement current track number
210
250
self .playlist_display .current_track_number -= 1
211
251
212
- # start playing track
213
- self .play_current_track ()
252
+ try :
253
+ # start playing track
254
+ self .play_current_track ()
255
+ except OSError as e :
256
+ # file not found
257
+ print ("Error playing: {}" .format (self .current_song_file_name ))
258
+ print (e )
259
+ self .previous_track ()
260
+ return
214
261
215
262
def pause (self ):
216
263
"""
@@ -244,17 +291,24 @@ class PlaylistDisplay(displayio.Group):
244
291
245
292
:param text_color: Hex color code for the text in the list
246
293
:param song_list: Song names in the list
247
- :param current_track_number: initial track number shown at the top of the list.
294
+ :param current_track_number: initial track number shown at the top of the list.l
295
+ :param max_chars: int max number of characters to show in a row. Excess characters are cut.
296
+ :param rows: how many rows to show. One track per row. Default 3 rows
248
297
"""
249
298
250
- def __init__ (self , text_color , song_list = None , current_track_number = 0 ):
299
+ def __init__ (
300
+ self , text_color , song_list = None , current_track_number = 0 , max_chars = 30 , rows = 3
301
+ ):
251
302
super ().__init__ ()
252
303
304
+ self ._rows = rows
253
305
if song_list is None :
254
306
song_list = []
255
307
self ._song_list = song_list
256
308
self ._current_track_number = current_track_number
257
309
310
+ self ._max_chars = max_chars
311
+
258
312
# the label to show track titles inside of
259
313
self ._label = bitmap_label .Label (terminalio .FONT , color = text_color )
260
314
@@ -275,13 +329,15 @@ def update_display(self):
275
329
276
330
# get the current track plus the following 2
277
331
_showing_songs = self .song_list [
278
- self .current_track_number - 1 : self .current_track_number + 3 - 1
332
+ self .current_track_number - 1 : self .current_track_number + self . _rows - 1
279
333
]
280
334
281
335
# format the track titles into a single string with newlines
282
336
_showing_string = ""
283
337
for index , song in enumerate (_showing_songs ):
284
- _cur_line = "{}. {}" .format (self .current_track_number + index , song [:30 ])
338
+ _cur_line = "{}. {}" .format (
339
+ self .current_track_number + index , song [: self ._max_chars ]
340
+ )
285
341
_showing_string = "{}{}\n " .format (_showing_string , _cur_line )
286
342
287
343
# put it into the label
0 commit comments