36
36
TEXT_COLOR = "#B0B0B0"
37
37
HIDDEN_TEXT_COLOR = "#808080"
38
38
39
- SHOWN_FILETYPES = ["py" , "mpy" , "bmp" , "pcf" , "bdf" , "wav" , "mp3" , "json" , "txt" ]
39
+ SHOWN_FILETYPES = ["py" , "mpy" , "bmp" , "pcf" , "bdf" , "wav" , "mp3" , "mid" , " json" , "txt" ]
40
40
41
41
f = open ("latest_bundle_data.json" , "r" )
42
42
bundle_data = json .load (f )
@@ -70,6 +70,7 @@ def asset_path(asset_name):
70
70
"bmp" : file_image_icon ,
71
71
"wav" : file_music_icon ,
72
72
"mp3" : file_music_icon ,
73
+ "mid" : file_music_icon ,
73
74
"pcf" : file_font_icon ,
74
75
"bdf" : file_font_icon ,
75
76
"json" : file_icon ,
@@ -159,73 +160,101 @@ def make_line(
159
160
160
161
def make_header (position , project_files ):
161
162
# Static files
162
- make_line ("CIRCUITPY" , position )
163
+ make_line (
164
+ "CIRCUITPY" ,
165
+ (position [0 ] + INDENT_SIZE , position [1 ]),
166
+ triangle_icon = down_triangle ,
167
+ )
163
168
make_line (
164
169
".fseventsd" ,
165
- (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 1 )),
170
+ (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * 1 )),
166
171
hidden = True ,
167
172
triangle_icon = right_triangle ,
168
173
)
169
174
make_line (
170
175
".metadata_never_index" ,
171
- (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 2 )),
176
+ (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * 2 )),
172
177
icon = file_empty_hidden_icon ,
173
178
hidden = True ,
174
179
)
175
180
make_line (
176
181
".Trashes" ,
177
- (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 3 )),
182
+ (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * 3 )),
178
183
icon = file_empty_hidden_icon ,
179
184
hidden = True ,
180
185
)
181
186
make_line (
182
187
"boot_out.txt" ,
183
- (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 4 )),
188
+ (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * 4 )),
184
189
)
185
190
make_line (
186
191
"code.py" ,
187
- (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 5 )),
192
+ (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * 5 )),
188
193
icon = file_icon ,
189
194
)
190
195
191
196
# dynamic files from project dir in learn guide repo
192
197
rows_added = 0
193
198
project_files_to_draw = []
194
- project_folders_to_draw = []
199
+ project_folders_to_draw = {}
195
200
for cur_file in project_files :
196
- if "." in cur_file [- 5 :]:
197
- cur_extension = cur_file .split ("." )[- 1 ]
198
- if cur_extension in SHOWN_FILETYPES :
199
- project_files_to_draw .append (cur_file )
200
- else :
201
- project_folders_to_draw .append (cur_file )
201
+ # string for individual file
202
+ if isinstance (cur_file , str ):
203
+ if "." in cur_file [- 5 :]:
204
+ cur_extension = cur_file .split ("." )[- 1 ]
205
+ if cur_extension in SHOWN_FILETYPES :
206
+ project_files_to_draw .append (cur_file )
207
+ # tuple for directory
208
+ elif isinstance (cur_file , tuple ):
209
+ project_folders_to_draw [cur_file [0 ]] = cur_file [1 ]
202
210
203
211
for i , file in enumerate (sorted (project_files_to_draw )):
204
212
cur_file_extension = file .split ("." )[- 1 ]
205
213
206
214
cur_file_icon = FILE_TYPE_ICON_MAP .get (cur_file_extension , file_empty_icon )
207
215
make_line (
208
216
file ,
209
- (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * (6 + i ))),
217
+ (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * (6 + i ))),
210
218
icon = cur_file_icon ,
211
219
)
212
220
rows_added += 1
213
221
214
- for i , file in enumerate (sorted (project_folders_to_draw )):
222
+ extra_rows = 0
223
+ for i , file in enumerate (sorted (project_folders_to_draw .keys ())):
215
224
make_line (
216
225
file ,
217
226
(
218
- position [0 ] + INDENT_SIZE ,
219
- position [1 ] + (LINE_SPACING * (6 + i + len (project_files_to_draw ))),
227
+ position [0 ] + INDENT_SIZE * 2 ,
228
+ position [1 ]
229
+ + (
230
+ LINE_SPACING * (6 + i + len (project_files_to_draw ) + extra_rows )
231
+ ),
220
232
),
221
- triangle_icon = right_triangle ,
233
+ triangle_icon = down_triangle ,
222
234
)
223
235
rows_added += 1
236
+ for sub_file in sorted (project_folders_to_draw [file ]):
237
+ extra_rows += 1
238
+ cur_file_extension = sub_file .split ("." )[- 1 ]
239
+ cur_file_icon = FILE_TYPE_ICON_MAP .get (cur_file_extension , folder_icon )
240
+ triangle_icon = None
241
+ if cur_file_icon == folder_icon :
242
+ triangle_icon = right_triangle
243
+ make_line (
244
+ sub_file ,
245
+ (
246
+ position [0 ] + INDENT_SIZE * 3 ,
247
+ position [1 ] + (LINE_SPACING * (6 + rows_added )),
248
+ ),
249
+ triangle_icon = triangle_icon ,
250
+ icon = cur_file_icon ,
251
+ )
252
+ rows_added += 1
224
253
225
254
make_line (
226
255
"lib" ,
227
256
(
228
- position [0 ] + INDENT_SIZE ,
257
+ position [0 ] + INDENT_SIZE * 2 ,
229
258
position [1 ] + (LINE_SPACING * (5 + rows_added + 1 )),
230
259
),
231
260
triangle_icon = down_triangle ,
@@ -280,6 +309,19 @@ def sort_libraries(libraries):
280
309
package_list , file_list = get_dependencies (libraries )
281
310
return sorted (package_list ) + sorted (file_list )
282
311
312
+ def count_files (files_list ):
313
+ _count = 0
314
+ for _file in files_list :
315
+ # string for individual file
316
+ if isinstance (_file , str ):
317
+ _count += 1
318
+
319
+ # tuple for directory
320
+ elif isinstance (_file , tuple ):
321
+ _count += 1
322
+ _count += len (_file [1 ])
323
+ return _count
324
+
283
325
def make_libraries (libraries , position ):
284
326
285
327
for i , lib_name in enumerate (libraries ):
@@ -288,7 +330,7 @@ def make_libraries(libraries, position):
288
330
triangle_icon = right_triangle
289
331
make_line (
290
332
lib_name ,
291
- (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * i )),
333
+ (position [0 ] + INDENT_SIZE * 3 , position [1 ] + (LINE_SPACING * i )),
292
334
triangle_icon = triangle_icon ,
293
335
)
294
336
@@ -300,7 +342,7 @@ def make_libraries(libraries, position):
300
342
if "main.py" in project_files :
301
343
project_files .remove ("main.py" )
302
344
303
- project_files_count = len (project_files )
345
+ project_files_count = count_files (project_files )
304
346
305
347
image_height = (
306
348
PADDING * 2
0 commit comments