@@ -62,6 +62,49 @@ def confirm_settings(self):
62
62
63
63
return messagebox .askyesno ("Export confirmation" , confirm_msg )
64
64
65
+ def increase_progress_bar_value (self ):
66
+ """
67
+ Increase the progress bar value by one
68
+ """
69
+
70
+ self .progress_bar ["value" ] += 1
71
+ print ("Increased progress bar value by one" )
72
+
73
+ def clear_progress_window (self ):
74
+ """
75
+ Clear the progress window
76
+ """
77
+
78
+ if self .progress_window is not None :
79
+ self .progress_window .destroy ()
80
+
81
+ def display_progress_window (self , progress_maximum = 100 ):
82
+ """
83
+ Display the progress window
84
+
85
+ :param progress_maximum: The maximum value of the progress bar (default is 100)
86
+ """
87
+
88
+ self .clear_progress_window ()
89
+
90
+ self .progress_window = Toplevel (self )
91
+ self .progress_window .title ("Exporting" )
92
+ self .progress_window .geometry ("300x100" )
93
+
94
+ Label (self .progress_window ,
95
+ text = "Exporting images" ,
96
+ font = ("Segoe UI" , 16 )).pack (fill = "x" , side = "top" )
97
+
98
+ self .progress_bar = ttk .Progressbar (self .progress_window ,
99
+ orient = "horizontal" ,
100
+ length = 280 ,
101
+ mode = "determinate" )
102
+ self .progress_bar .pack (expand = True , fill = "both" , side = "bottom" )
103
+ self .progress_bar ["value" ] = 0
104
+ self .progress_bar ["maximum" ] = progress_maximum
105
+
106
+ self .progress_window .update ()
107
+
65
108
def get_settings_status (self ):
66
109
"""
67
110
Check if our settings are valid (directory exists, width and height are digits etc)
@@ -114,39 +157,31 @@ def export_button_handler(self):
114
157
else :
115
158
# Valid settings, confirm settings with the user and export
116
159
if self .confirm_settings ():
117
- # result = imgedit.export_all_in_dir(
118
- # self.selected_directory.get(),
119
- # int(self.export_properties["width"].get()),
120
- # int(self.export_properties["height"].get()),
121
- # self.export_properties["type"].get(),
122
- # self.overwrite_original.get()
123
- # )
124
-
125
- # Display progress
126
- if self .progress_window is not None :
127
- self .progress_window .destroy ()
128
-
129
- self .progress_window = Toplevel (self )
130
- self .progress_window .title ("Exporting" )
131
- self .progress_window .geometry ("300x100" )
132
- #self.progress_window.iconbitmap("icon.ico")
133
-
134
- Label (self .progress_window ,
135
- text = "Exporting images" ,
136
- font = ("Segoe UI" , 16 )).pack (fill = "x" , side = "top" )
137
-
138
- progress_bar = ttk .Progressbar (self .progress_window ,
139
- orient = "horizontal" ,
140
- length = 280 ,
141
- mode = "determinate" )
142
- progress_bar .pack (expand = True , fill = "both" , side = "bottom" )
143
- progress_bar ["value" ] = 60
144
- progress_bar ["maximum" ] = 100
145
-
146
- # if result:
147
- # # at this point, we are done with our exports, display a success message
148
- # messagebox.showinfo("Exports completed",
149
- # "All images were exported successfully")
160
+ num_of_images = imgedit .image_files_in_dir (self .selected_directory .get ())
161
+ self .display_progress_window (num_of_images )
162
+ print ("Progress window is on screen" )
163
+
164
+ print ("Exporting images" )
165
+ result = imgedit .export_all_in_dir (
166
+ self .selected_directory .get (),
167
+ int (self .export_properties ["width" ].get ()),
168
+ int (self .export_properties ["height" ].get ()),
169
+ self .export_properties ["type" ].get (),
170
+ self .overwrite_original .get (),
171
+ self .increase_progress_bar_value
172
+ )
173
+
174
+ self .clear_progress_window ()
175
+ print ("Progress window is cleared" )
176
+
177
+ if result :
178
+ # at this point, we are done with our exports, display a success message
179
+ messagebox .showinfo ("Exports completed" ,
180
+ "All images were exported successfully" )
181
+ else :
182
+ # one or more images failed to export, display a warning
183
+ messagebox .showwarning ("Exports failed" ,
184
+ "One or more images failed to export" )
150
185
151
186
def browse_for_directory (self ):
152
187
"""
@@ -253,6 +288,7 @@ def __init__(self, parent=None):
253
288
# properties
254
289
self .save_as_dropdown = None
255
290
self .progress_window = None
291
+ self .progress_bar = None
256
292
257
293
self .selected_directory = StringVar (self )
258
294
self .overwrite_original = BooleanVar (self )
0 commit comments