1+ import traceback
2+
13from PIL import Image , ImageDraw , ImageFont
24import json
35
4- from python_generator .get_imports import get_libs_for_project , get_files_for_project
6+ from python_generator .get_imports import get_libs_for_project , get_files_for_project , get_learn_guide_cp_projects
57
68OUT_WIDTH = 800
79PADDING = 20
1416TEXT_COLOR = "#B0B0B0"
1517HIDDEN_TEXT_COLOR = "#808080"
1618
19+ SHOWN_FILETYPES = ["py" , "mpy" , "bmp" , "pcf" , "bdf" , "wav" , "mp3" , "json" ]
1720"""
1821libraries_to_render = ['adafruit_bitmap_font',
1922 'adafruit_bus_device',
4851folder_hidden_icon = Image .open ('img/folder_hidden.png' )
4952file_icon = Image .open ('img/file.png' )
5053file_hidden_icon = Image .open ('img/file_hidden.png' )
54+ file_empty_icon = Image .open ('img/file_empty.png' )
55+ file_empty_hidden_icon = Image .open ('img/file_empty_hidden.png' )
5156
5257
5358def generate_requirement_image (learn_guide_project ):
@@ -61,6 +66,12 @@ def make_line(requirement_name, position=(0, 0), icon=None, hidden=False, triang
6166 mask = file_hidden_icon )
6267 else :
6368 im .paste (file_icon , (position [0 ], position [1 ] + (LINE_SPACING - 24 ) // 2 ), mask = file_icon )
69+
70+ elif "." in requirement_name [- 5 :]:
71+ if hidden :
72+ im .paste (file_empty_hidden_icon , (position [0 ], position [1 ] + (LINE_SPACING - 24 ) // 2 ), mask = file_empty_icon )
73+ else :
74+ im .paste (file_empty_icon , (position [0 ], position [1 ] + (LINE_SPACING - 24 ) // 2 ), mask = file_empty_icon )
6475 else :
6576 if hidden :
6677 im .paste (folder_hidden_icon , (position [0 ], position [1 ] + (LINE_SPACING - 24 ) // 2 ),
@@ -85,13 +96,12 @@ def make_header(position, learn_guide_project):
8596 make_line (".fseventsd" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 1 )), hidden = True ,
8697 triangle_icon = right_triangle )
8798 make_line (".metadata_never_index" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 2 )),
88- icon = file_hidden_icon ,
99+ icon = file_empty_hidden_icon ,
89100 hidden = True )
90101 make_line (".Trashes" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 3 )),
91- icon = file_hidden_icon ,
102+ icon = file_empty_hidden_icon ,
92103 hidden = True )
93- make_line ("boot_out.txt" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 4 )),
94- icon = file_icon )
104+ make_line ("boot_out.txt" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 4 )))
95105 make_line ("code.py" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 5 )),
96106 icon = file_icon )
97107
@@ -101,16 +111,20 @@ def make_header(position, learn_guide_project):
101111 project_files_to_draw = []
102112 project_folders_to_draw = []
103113 for cur_file in project_files :
104- if cur_file .endswith (".py" ):
105- project_files_to_draw .append (cur_file )
114+ if "." in cur_file [- 5 :]:
115+ cur_extension = cur_file .split ("." )[- 1 ]
116+ if cur_extension in SHOWN_FILETYPES :
117+ if cur_file != "main.py" :
118+ project_files_to_draw .append (cur_file )
106119 else :
107120 project_folders_to_draw .append (cur_file )
108121
109122 try :
110123 project_files_to_draw .remove ("code.py" )
111- extra_space_for_code = 1
112124 except ValueError :
113- extra_space_for_code = 0
125+ pass
126+
127+
114128 for i , file in enumerate (project_files_to_draw ):
115129 make_line (file , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * (6 + i ))))
116130 rows_added += 1
@@ -176,26 +190,42 @@ def make_libraries(libraries, position):
176190 (position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * i )),
177191 triangle_icon = triangle_icon )
178192
179- libs = get_libs_for_project (learn_guide_project )
180- final_list_to_render = sort_libraries (libs )
181193
182194
183- project_files_count = len (get_files_for_project (learn_guide_project ))
184- if "code.py" in get_files_for_project (learn_guide_project ):
185- project_files_count -= 1
186- image_height = PADDING * 2 + 7 * LINE_SPACING + len (final_list_to_render ) * LINE_SPACING + (
187- project_files_count ) * LINE_SPACING
188- im = Image .new ("RGB" , (OUT_WIDTH , image_height ), "#303030" )
189- draw = ImageDraw .Draw (im )
195+ try :
196+ libs = get_libs_for_project (learn_guide_project )
197+ final_list_to_render = sort_libraries (libs )
198+
199+ project_file_list = get_files_for_project (learn_guide_project )
200+
201+ project_files_count = len (project_file_list )
202+
203+ if "code.py" in project_file_list :
204+ project_files_count -= 1
205+
206+ if "main.py" in project_file_list :
207+ project_files_count -= 1
208+
209+ image_height = PADDING * 2 + 7 * LINE_SPACING + len (final_list_to_render ) * LINE_SPACING + (
210+ project_files_count ) * LINE_SPACING
211+ im = Image .new ("RGB" , (OUT_WIDTH , image_height ), "#303030" )
212+ draw = ImageDraw .Draw (im )
190213
191- make_background_highlights (7 + len (final_list_to_render ) + project_files_count ,
192- offset = (PADDING , PADDING ))
214+ make_background_highlights (7 + len (final_list_to_render ) + project_files_count ,
215+ offset = (PADDING , PADDING ))
193216
194- make_header ((PADDING , PADDING ), learn_guide_project )
195- make_libraries (final_list_to_render ,
196- (PADDING , PADDING + (LINE_SPACING * (7 + project_files_count ))))
217+ make_header ((PADDING , PADDING ), learn_guide_project )
218+ make_libraries (final_list_to_render ,
219+ (PADDING , PADDING + (LINE_SPACING * (7 + project_files_count ))))
197220
198- im .save ("{}_required_files.png" .format (learn_guide_project ))
221+ im .save ("generated_images/{}_files.png" .format (learn_guide_project ))
222+ except SyntaxError as e :
223+ print (e )
224+ traceback .print_exc ()
225+ print ("SyntaxError finding imports for {}" .format (learn_guide_project ))
199226
227+ #print(get_learn_guide_cp_projects())
200228
201- generate_requirement_image ("PyPortal_Quarantine_Clock" )
229+ for cp_project in get_learn_guide_cp_projects ():
230+ print ("making screenshot for: {}" .format (cp_project ))
231+ generate_requirement_image (cp_project )
0 commit comments