@@ -64,26 +64,39 @@ def read_secret(self):
64
64
image_timestamps .append (dt .datetime .fromtimestamp (post .created ))
65
65
image_ids .append (post .id )
66
66
67
+ # This creates a GUI window with a progress bar to keep track of the download
68
+
69
+ layout = [[sg .Text (f"Downloading files..." , key = 'textkey' )],
70
+ [sg .ProgressBar (25 , orientation = 'h' , size = (20 , 20 ), key = 'progbar' )],
71
+ [sg .Cancel ()]]
72
+
73
+ window = sg .Window ('Download in Progress' , layout )
74
+
67
75
# This iterates through URLs, checks if it has the specified image extension and downloads the image
68
76
69
77
for index , url in enumerate (image_urls ):
70
78
path = str (folder_lst [0 ])
71
79
file_ending = str (url )[2 :- 1 ]
80
+ event , values = window .read (timeout = 0 )
72
81
_ , extension = os .path .splitext (file_ending )
73
82
if extension in image_extensions :
74
83
try :
75
84
if os .path .exists (path + '/' + 'Downloaded Images' ):
76
85
pass
77
86
else :
78
87
os .mkdir (path + '/' + 'Downloaded Images' )
88
+ if event == 'Cancel' or event == sg .WIN_CLOSED :
89
+ break
79
90
80
91
destination = str (folder_lst [0 ]) + '/' + 'Downloaded Images' + '/'
92
+ window ['progbar' ].update_bar (index + 1 )
81
93
print (f"Downloading '{ str (image_titles [index ])[2 :- 1 ]} ' to '{ path } ' from '{ str (image_urls [index ])[2 :- 1 ]} '" )
82
94
download = wget .download (str (image_urls [index ])[2 :- 1 ], out = destination )
83
95
except :
84
96
print (f"Something went wrong while downloading '{ str (image_urls [index ])[2 :- 1 ]} '\n " )
85
97
else :
86
98
print ("\n Download complete!" )
99
+ window .close ()
87
100
sg .Popup (f"Files downloaded into:\n \n '{ path } /Downloaded Images'" , title = 'Download complete!' )
88
101
89
102
0 commit comments