55PyPortal winamp displayio widget classes.
66"""
77import time
8-
8+ import json
99import board
1010import displayio
1111import terminalio
12- import json
1312from audioio import AudioOut
1413from audiomp3 import MP3Decoder
1514from adafruit_display_text import bitmap_label , scrolling_label
@@ -25,12 +24,16 @@ class WinampApplication(displayio.Group):
2524 :param skin_image: BMP image file for skin background
2625 :param skin_config_file: json file containing color values
2726 """
27+
2828 STATE_PLAYING = 0
2929 STATE_PAUSED = 1
3030
31- def __init__ (self , playlist_file = "playlist.json" ,
32- skin_image = "/base_240x320.bmp" ,
33- skin_config_file = "base_config.json" ):
31+ def __init__ (
32+ self ,
33+ playlist_file = "playlist.json" ,
34+ skin_image = "/base_240x320.bmp" ,
35+ skin_config_file = "base_config.json" ,
36+ ):
3437 self .SKIN_IMAGE = skin_image
3538 self .SKIN_CONFIG_FILE = skin_config_file
3639 self .PLAYLIST_FILE = playlist_file
@@ -51,7 +54,9 @@ def __init__(self, playlist_file="playlist.json",
5154 self .clock_display .y = 22
5255
5356 # initialize playlist display
54- self .playlist_display = PlaylistDisplay (text_color = self .CONFIG_DATA ["text_color" ])
57+ self .playlist_display = PlaylistDisplay (
58+ text_color = self .CONFIG_DATA ["text_color" ]
59+ )
5560 self .playlist_display .x = 13
5661 self .playlist_display .y = 234
5762
@@ -60,21 +65,27 @@ def __init__(self, playlist_file="playlist.json",
6065 self .playlist_display .current_track_number = 1
6166
6267 # get name of current song
63- self .current_song_file_name = self .PLAYLIST ["playlist" ]["files" ][self .playlist_display .current_track_number - 1 ]
68+ self .current_song_file_name = self .PLAYLIST ["playlist" ]["files" ][
69+ self .playlist_display .current_track_number - 1
70+ ]
6471
6572 # initialize ScrollingLabel for track name
66- self .current_song_lbl = scrolling_label .ScrollingLabel (terminalio .FONT ,
67- text = self .playlist_display .current_track_title ,
68- color = self .CONFIG_DATA ["text_color" ], max_characters = 22 )
73+ self .current_song_lbl = scrolling_label .ScrollingLabel (
74+ terminalio .FONT ,
75+ text = self .playlist_display .current_track_title ,
76+ color = self .CONFIG_DATA ["text_color" ],
77+ max_characters = 22 ,
78+ )
6979 self .current_song_lbl .anchor_point = (0 , 0 )
7080 self .current_song_lbl .anchored_position = (98 , 19 )
7181
7282 # Setup the skin image file as the bitmap data source
7383 self .background_bitmap = displayio .OnDiskBitmap (self .SKIN_IMAGE )
7484
7585 # Create a TileGrid to hold the bitmap
76- self .background_tilegrid = displayio .TileGrid (self .background_bitmap ,
77- pixel_shader = self .background_bitmap .pixel_shader )
86+ self .background_tilegrid = displayio .TileGrid (
87+ self .background_bitmap , pixel_shader = self .background_bitmap .pixel_shader
88+ )
7889
7990 # initialize parent displayio.Group
8091 super ().__init__ ()
@@ -116,7 +127,6 @@ def update(self):
116127 if self .CURRENT_STATE == self .STATE_PLAYING :
117128 # if it's time to increase the time on the ClockDisplay
118129 if self ._cur_time >= self ._last_increment_time + 1 :
119-
120130 # increase ClockDisplay by 1 second
121131 self ._seconds_elapsed += 1
122132 self ._last_increment_time = self ._cur_time
@@ -125,7 +135,6 @@ def update(self):
125135 # update the track label (scrolling)
126136 self .current_song_lbl .update ()
127137
128-
129138 if self .CURRENT_STATE == self .STATE_PLAYING :
130139 # if we are supposed to be playing but aren't
131140 # it means the track ended.
@@ -136,7 +145,6 @@ def update(self):
136145 # store time for comparison later
137146 self ._prev_time = self ._cur_time
138147
139-
140148 def play_current_track (self ):
141149 """
142150 Update the track label and begin playing the song for current
@@ -159,7 +167,9 @@ def play_current_track(self):
159167 self .current_song_file .close ()
160168
161169 # open new song file
162- self .current_song_file_name = self .PLAYLIST ["playlist" ]["files" ][self .playlist_display .current_track_number - 1 ]
170+ self .current_song_file_name = self .PLAYLIST ["playlist" ]["files" ][
171+ self .playlist_display .current_track_number - 1
172+ ]
163173 self .current_song_file = open (self .current_song_file_name , "rb" )
164174 self .decoder .file = self .current_song_file
165175
@@ -171,7 +181,6 @@ def play_current_track(self):
171181 # pause so it's loaded, and ready to resume
172182 self .audio .pause ()
173183
174-
175184 def next_track (self ):
176185 """
177186 Advance to the next track.
@@ -187,7 +196,6 @@ def next_track(self):
187196 # start playing track
188197 self .play_current_track ()
189198
190-
191199 def previous_track (self ):
192200 """
193201 Go back to previous track.
@@ -204,7 +212,6 @@ def previous_track(self):
204212 # start playing track
205213 self .play_current_track ()
206214
207-
208215 def pause (self ):
209216 """
210217 Stop playing song and wait until resume function.
@@ -215,7 +222,6 @@ def pause(self):
215222 self .audio .pause ()
216223 self .CURRENT_STATE = self .STATE_PAUSED
217224
218-
219225 def resume (self ):
220226 """
221227 Resume playing song after having been paused.
@@ -240,9 +246,12 @@ class PlaylistDisplay(displayio.Group):
240246 :param song_list: Song names in the list
241247 :param current_track_number: initial track number shown at the top of the list.
242248 """
243- def __init__ (self , text_color , song_list = [], current_track_number = 0 ):
249+
250+ def __init__ (self , text_color , song_list = None , current_track_number = 0 ):
244251 super ().__init__ ()
245252
253+ if song_list is None :
254+ song_list = []
246255 self ._song_list = song_list
247256 self ._current_track_number = current_track_number
248257
@@ -265,7 +274,9 @@ def update_display(self):
265274 """
266275
267276 # get the current track plus the following 2
268- _showing_songs = self .song_list [self .current_track_number - 1 :self .current_track_number + 3 - 1 ]
277+ _showing_songs = self .song_list [
278+ self .current_track_number - 1 : self .current_track_number + 3 - 1
279+ ]
269280
270281 # format the track titles into a single string with newlines
271282 _showing_string = ""
@@ -335,7 +346,9 @@ def current_track_title(self):
335346 if self .current_track_number == 0 :
336347 return "1. {}" .format (self .song_list [0 ])
337348 else :
338- return "{}. {}" .format (self .current_track_number , self .song_list [self .current_track_number - 1 ])
349+ return "{}. {}" .format (
350+ self .current_track_number , self .song_list [self .current_track_number - 1 ]
351+ )
339352
340353
341354class ClockDisplay (displayio .Group ):
@@ -346,6 +359,7 @@ class ClockDisplay(displayio.Group):
346359
347360 :param text_color: Hex color code for the clock text
348361 """
362+
349363 def __init__ (self , text_color ):
350364 super ().__init__ ()
351365
@@ -411,8 +425,8 @@ def update_display(self):
411425 _seconds = self .seconds % 60
412426
413427 # zero pad the values and format into strings
414- _minutes_str = f' { _minutes :02} '
415- _seconds_str = f' { _seconds :02} '
428+ _minutes_str = f" { _minutes :02} "
429+ _seconds_str = f" { _seconds :02} "
416430
417431 # update the text in the minutes labels
418432 if self .first_digit .text != _minutes_str [0 ]:
0 commit comments