Skip to content

Commit 605cbeb

Browse files
committed
code format and pylint fixes
1 parent 082f9c0 commit 605cbeb

File tree

3 files changed

+58
-39
lines changed

3 files changed

+58
-39
lines changed

PyPortal_Winamp_Player/PyPortal_Winamp_Skin_Converter/convert_winamp_skin.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"""
55
PyPortal winamp skin converter.
66
"""
7-
from PIL import Image, ImageDraw
87
import sys
98
import json
9+
from PIL import Image, ImageDraw
1010

1111
# get input filename from terminal args
1212
if len(sys.argv) >= 2:
@@ -34,20 +34,17 @@
3434

3535
# scan pixel for backdrop color
3636
back_drop_color = im.getpixel((120, 29))
37-
for color in find_text_color_dict.keys():
37+
for color in find_text_color_dict:
3838
if not highest_pixel_count:
3939
highest_pixel_count = find_text_color_dict[color]
4040
text_color = color
4141
elif highest_pixel_count < find_text_color_dict[color]:
4242
highest_pixel_count = find_text_color_dict[color]
4343
text_color = color
4444

45-
#print("backdrop: {}".format(back_drop_color))
45+
# print("backdrop: {}".format(back_drop_color))
4646
time_color = text_color
47-
config_data = {
48-
"text_color": text_color,
49-
"time_color": time_color
50-
}
47+
config_data = {"text_color": text_color, "time_color": time_color}
5148

5249
find_text_color_dict = {}
5350
for i in range(21):
@@ -68,15 +65,24 @@
6865
for x_loc in time_shape_x_locs:
6966
_cur_time_shape_loc = (x_loc, 26)
7067
_cur_time_shape = (
71-
_cur_time_shape_loc, (_cur_time_shape_loc[0] + time_shape_size[0], _cur_time_shape_loc[1] + time_shape_size[1]))
68+
_cur_time_shape_loc,
69+
(
70+
_cur_time_shape_loc[0] + time_shape_size[0],
71+
_cur_time_shape_loc[1] + time_shape_size[1],
72+
),
73+
)
7274
img_draw.rectangle(_cur_time_shape, fill=back_drop_color)
7375

7476
# rectangle cutout for playlist display
7577
playlist_shape_size = (244, 48)
7678
playlist_shape_loc = (12, 257)
7779
playlist_shape = (
7880
playlist_shape_loc,
79-
(playlist_shape_loc[0] + playlist_shape_size[0], playlist_shape_loc[1] + playlist_shape_size[1]))
81+
(
82+
playlist_shape_loc[0] + playlist_shape_size[0],
83+
playlist_shape_loc[1] + playlist_shape_size[1],
84+
),
85+
)
8086

8187
img_draw.rectangle(playlist_shape, fill=back_drop_color)
8288

PyPortal_Winamp_Player/code.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
PyPortal winamp player
66
"""
77
import time
8-
import storage
98
import sys
10-
import os
9+
import storage
1110
import board
1211
import busio
1312
import digitalio
@@ -62,7 +61,7 @@
6261
sys.path.append("/sd")
6362

6463
# debugging, print files that exist on SDCard
65-
#print(os.listdir("/sd"))
64+
# print(os.listdir("/sd"))
6665

6766
# get reference to the display
6867
display = board.DISPLAY
@@ -74,7 +73,7 @@
7473
winamp_application = WinampApplication(
7574
playlist_file=PLAYLIST_FILE,
7675
skin_image=SKIN_IMAGE,
77-
skin_config_file=SKIN_CONFIG_FILE
76+
skin_config_file=SKIN_CONFIG_FILE,
7877
)
7978

8079
# Add the Group to the Display
@@ -110,7 +109,7 @@
110109
else:
111110
winamp_application.previous_track()
112111
# if touch is on top half
113-
elif p[1] <= 240 //2:
112+
elif p[1] <= 240 // 2:
114113
# if currently playing song
115114
if winamp_application.CURRENT_STATE == winamp_application.STATE_PLAYING:
116115
print("pausing")

PyPortal_Winamp_Player/winamp_helpers.py

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
PyPortal winamp displayio widget classes.
66
"""
77
import time
8-
8+
import json
99
import board
1010
import displayio
1111
import terminalio
12-
import json
1312
from audioio import AudioOut
1413
from audiomp3 import MP3Decoder
1514
from 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

341354
class 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

Comments
 (0)