1
+ import traceback
2
+
1
3
from PIL import Image , ImageDraw , ImageFont
2
4
import json
3
5
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
5
7
6
8
OUT_WIDTH = 800
7
9
PADDING = 20
14
16
TEXT_COLOR = "#B0B0B0"
15
17
HIDDEN_TEXT_COLOR = "#808080"
16
18
19
+ SHOWN_FILETYPES = ["py" , "mpy" , "bmp" , "pcf" , "bdf" , "wav" , "mp3" , "json" ]
17
20
"""
18
21
libraries_to_render = ['adafruit_bitmap_font',
19
22
'adafruit_bus_device',
48
51
folder_hidden_icon = Image .open ('img/folder_hidden.png' )
49
52
file_icon = Image .open ('img/file.png' )
50
53
file_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' )
51
56
52
57
53
58
def generate_requirement_image (learn_guide_project ):
@@ -61,6 +66,12 @@ def make_line(requirement_name, position=(0, 0), icon=None, hidden=False, triang
61
66
mask = file_hidden_icon )
62
67
else :
63
68
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 )
64
75
else :
65
76
if hidden :
66
77
im .paste (folder_hidden_icon , (position [0 ], position [1 ] + (LINE_SPACING - 24 ) // 2 ),
@@ -85,13 +96,12 @@ def make_header(position, learn_guide_project):
85
96
make_line (".fseventsd" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 1 )), hidden = True ,
86
97
triangle_icon = right_triangle )
87
98
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 ,
89
100
hidden = True )
90
101
make_line (".Trashes" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 3 )),
91
- icon = file_hidden_icon ,
102
+ icon = file_empty_hidden_icon ,
92
103
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 )))
95
105
make_line ("code.py" , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * 5 )),
96
106
icon = file_icon )
97
107
@@ -101,16 +111,20 @@ def make_header(position, learn_guide_project):
101
111
project_files_to_draw = []
102
112
project_folders_to_draw = []
103
113
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 )
106
119
else :
107
120
project_folders_to_draw .append (cur_file )
108
121
109
122
try :
110
123
project_files_to_draw .remove ("code.py" )
111
- extra_space_for_code = 1
112
124
except ValueError :
113
- extra_space_for_code = 0
125
+ pass
126
+
127
+
114
128
for i , file in enumerate (project_files_to_draw ):
115
129
make_line (file , (position [0 ] + INDENT_SIZE , position [1 ] + (LINE_SPACING * (6 + i ))))
116
130
rows_added += 1
@@ -176,26 +190,42 @@ def make_libraries(libraries, position):
176
190
(position [0 ] + INDENT_SIZE * 2 , position [1 ] + (LINE_SPACING * i )),
177
191
triangle_icon = triangle_icon )
178
192
179
- libs = get_libs_for_project (learn_guide_project )
180
- final_list_to_render = sort_libraries (libs )
181
193
182
194
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 )
190
213
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 ))
193
216
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 ))))
197
220
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 ))
199
226
227
+ #print(get_learn_guide_cp_projects())
200
228
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