23
23
get_files_for_example ,
24
24
get_learn_guide_cp_projects ,
25
25
)
26
+ from settings_required import settings_required
26
27
27
28
os .makedirs ("generated_images" , exist_ok = True )
28
29
@@ -66,6 +67,7 @@ def asset_path(asset_name):
66
67
"py" : file_icon ,
67
68
"mpy" : file_icon ,
68
69
"txt" : file_empty_icon ,
70
+ "toml" : file_icon ,
69
71
"bmp" : file_image_icon ,
70
72
"wav" : file_music_icon ,
71
73
"mp3" : file_music_icon ,
@@ -78,15 +80,17 @@ def asset_path(asset_name):
78
80
}
79
81
80
82
# If this is not done, the images fail to load in the subprocesses.
81
- for file_icon in FILE_TYPE_ICON_MAP .values ():
82
- file_icon .load ()
83
+ for _file_icon in FILE_TYPE_ICON_MAP .values ():
84
+ _file_icon .load ()
83
85
84
86
85
87
def generate_requirement_image (
86
88
project_files , libs , image_name
87
- ): # pylint: disable=too-many-statements
89
+ ): # pylint: disable=too-many-statements, too-many-locals
88
90
"""Generate a single requirement image"""
89
91
92
+ context = {"added_settings_toml" : False }
93
+
90
94
def make_line (
91
95
requirement_name , position = (0 , 0 ), icon = None , hidden = False , triangle_icon = None
92
96
): # pylint: disable=too-many-branches
@@ -159,7 +163,8 @@ def make_line(
159
163
font = font ,
160
164
)
161
165
162
- def make_header (position , project_files ):
166
+ def make_header (position , project_files , files_and_libs ):
167
+ # pylint: disable=too-many-locals
163
168
# Static files
164
169
make_line (
165
170
"CIRCUITPY" ,
@@ -194,6 +199,21 @@ def make_header(position, project_files):
194
199
icon = file_icon ,
195
200
)
196
201
202
+ # TODO: Add settings.toml if it's needed
203
+
204
+ if settings_required (files_and_libs ):
205
+ make_line (
206
+ "settings.toml" ,
207
+ (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * 6 )),
208
+ icon = file_icon ,
209
+ )
210
+ context ["added_settings_toml" ] = True
211
+
212
+ if project_files :
213
+ print (image_name )
214
+ print (project_files )
215
+ print ("=============" )
216
+
197
217
# dynamic files from project dir in learn guide repo
198
218
rows_added = 0
199
219
project_files_to_draw = []
@@ -210,13 +230,18 @@ def make_header(position, project_files):
210
230
if ".circuitpython.skip-screenshot" not in cur_file [1 ]:
211
231
project_folders_to_draw [cur_file [0 ]] = cur_file [1 ]
212
232
233
+ begin_y_offset = 7 if context ["added_settings_toml" ] else 6
213
234
for i , file in enumerate (sorted (project_files_to_draw )):
214
235
cur_file_extension = file .split ("." )[- 1 ]
215
236
216
237
cur_file_icon = FILE_TYPE_ICON_MAP .get (cur_file_extension , file_empty_icon )
238
+
217
239
make_line (
218
240
file ,
219
- (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * (6 + i ))),
241
+ (
242
+ position [0 ] + INDENT_SIZE * 2 ,
243
+ position [1 ] + (LINE_SPACING * (begin_y_offset + i )),
244
+ ),
220
245
icon = cur_file_icon ,
221
246
)
222
247
rows_added += 1
@@ -229,7 +254,8 @@ def make_header(position, project_files):
229
254
position [0 ] + INDENT_SIZE * 2 ,
230
255
position [1 ]
231
256
+ (
232
- LINE_SPACING * (6 + i + len (project_files_to_draw ) + extra_rows )
257
+ LINE_SPACING
258
+ * (begin_y_offset + i + len (project_files_to_draw ) + extra_rows )
233
259
),
234
260
),
235
261
triangle_icon = down_triangle ,
@@ -246,7 +272,7 @@ def make_header(position, project_files):
246
272
sub_file ,
247
273
(
248
274
position [0 ] + INDENT_SIZE * 3 ,
249
- position [1 ] + (LINE_SPACING * (6 + rows_added )),
275
+ position [1 ] + (LINE_SPACING * (begin_y_offset + rows_added )),
250
276
),
251
277
triangle_icon = triangle_icon ,
252
278
icon = cur_file_icon ,
@@ -257,7 +283,7 @@ def make_header(position, project_files):
257
283
"lib" ,
258
284
(
259
285
position [0 ] + INDENT_SIZE * 2 ,
260
- position [1 ] + (LINE_SPACING * (5 + rows_added + 1 )),
286
+ position [1 ] + (LINE_SPACING * (( begin_y_offset - 1 ) + rows_added + 1 )),
261
287
),
262
288
triangle_icon = down_triangle ,
263
289
)
@@ -333,11 +359,20 @@ def make_libraries(libraries, position):
333
359
triangle_icon = right_triangle
334
360
make_line (
335
361
lib_name ,
336
- (position [0 ] + INDENT_SIZE * 3 , position [1 ] + (LINE_SPACING * i )),
362
+ (
363
+ position [0 ] + INDENT_SIZE * 3 ,
364
+ position [1 ]
365
+ + (
366
+ LINE_SPACING
367
+ * (i + (1 if context ["added_settings_toml" ] else 0 ))
368
+ ),
369
+ ),
337
370
triangle_icon = triangle_icon ,
338
371
)
339
372
340
373
final_list_to_render = sort_libraries (libs )
374
+ if settings_required (final_list_to_render ):
375
+ context ["added_settings_toml" ] = True
341
376
342
377
if "code.py" in project_files :
343
378
project_files .remove ("code.py" )
@@ -352,16 +387,20 @@ def make_libraries(libraries, position):
352
387
+ 7 * LINE_SPACING
353
388
+ len (final_list_to_render ) * LINE_SPACING
354
389
+ (project_files_count ) * LINE_SPACING
390
+ + (1 if context ["added_settings_toml" ] else 0 ) * LINE_SPACING
355
391
)
356
392
img = Image .new ("RGB" , (OUT_WIDTH , image_height ), "#303030" )
357
393
draw = ImageDraw .Draw (img )
358
394
359
395
make_background_highlights (
360
- 7 + len (final_list_to_render ) + project_files_count ,
396
+ 7
397
+ + len (final_list_to_render )
398
+ + project_files_count
399
+ + (1 if context ["added_settings_toml" ] else 0 ),
361
400
offset = (PADDING , PADDING ),
362
401
)
363
-
364
- make_header ((PADDING , PADDING ), project_files )
402
+ print ( f"fltr: { final_list_to_render } " )
403
+ make_header ((PADDING , PADDING ), project_files , final_list_to_render )
365
404
make_libraries (
366
405
final_list_to_render ,
367
406
(PADDING , PADDING + (LINE_SPACING * (7 + project_files_count ))),
0 commit comments