-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyfile.py
More file actions
325 lines (251 loc) · 8.62 KB
/
pyfile.py
File metadata and controls
325 lines (251 loc) · 8.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import customtkinter
import os
from tkinter import *
from tkinter import filedialog
from find_duplicates import generate_duplicates
from find_unique import generate_unique
from copy_files import copy_files_from_csv
GEOMETRY_X = 500 #probably not necessary but easy to change the window dimension here
GEOMETRY_Y = 320
sidebar_width = int(GEOMETRY_X * 0.14)
main_frame_width = GEOMETRY_X - sidebar_width
customtkinter.set_appearance_mode("Dark")
customtkinter.set_default_color_theme("blue")
root = customtkinter.CTk() #configure the root frame for customtkinter
root.title("PYFile Image Manager")
root.geometry(f"{GEOMETRY_X}x{GEOMETRY_Y}")
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(1, weight=1)
def menu_frame(): #configure the left menu bar frame
sidebar_frame = customtkinter.CTkFrame(root,
width=sidebar_width,
height=GEOMETRY_Y,
corner_radius=0,
fg_color="#303030"
)
sidebar_frame.grid(row=0,
column=0,
sticky="nsw"
)
sidebar_label = customtkinter.CTkLabel(sidebar_frame,
text="Manage Images",
font=customtkinter.CTkFont(size=20, weight="bold")
)
sidebar_label.grid(row=0,
column=0,
padx=20,
pady=(20, 10)
)
sidebar_button_1 = customtkinter.CTkButton(sidebar_frame,
text="Generate File Listing",
command=generate_files_frame
)
sidebar_button_1.grid(row=1,
column=0,
padx=20,
pady=10
)
sidebar_button_3 = customtkinter.CTkButton(sidebar_frame,
text="Copy Files",
command=copy_files_frame
)
sidebar_button_3.grid(row=3,
column=0,
padx=20,
pady=10
)
sidebar_button_4 = customtkinter.CTkButton(sidebar_frame,
text="Delete Files",
command=delete_files_frame
)
sidebar_button_4.grid(row=4,
column=0,
padx=20,
pady=10
)
sidebar_button_5 = customtkinter.CTkButton(sidebar_frame,
text="Return Home",
command=home_frame
)
sidebar_button_5.grid(row=5,
column=0,
padx=20,
pady=10
)
def home_frame(): #define the home frame which is the one displayed when first launched.
main_frame = customtkinter.CTkFrame(root,
width=main_frame_width,
corner_radius=0,
fg_color="#404040"
)
main_frame.grid(row=0,
column=1,
sticky="nsew"
)
main_label = customtkinter.CTkLabel(main_frame,
text="Select option from menu",
font=customtkinter.CTkFont(size=20, weight="bold")
)
main_label.grid(row=0,
column=0,
padx=20,
pady=(20, 10)
)
def generate_files_frame(): #define the frame appearance when requesting Generate Duplicate List
global path_name
main_frame = customtkinter.CTkFrame(root,
width=main_frame_width,
corner_radius=0,
fg_color="#404040"
)
main_frame.grid(row=0,
column=1,
sticky="nsew"
)
main_label = customtkinter.CTkLabel(main_frame,
text="Create File List",
font=customtkinter.CTkFont(size=20, weight="bold")
)
main_label.grid(row=0,
column=0,
padx=20,
pady=(20, 10),
sticky="nsw"
)
selectFolderPath_button = customtkinter.CTkButton(main_frame,
text="Select a Folder Path",
command=select_folder
)
selectFolderPath_button.grid(row=2,
column=0,
padx=20,
pady=10,
sticky="w"
)
selectGenerateList_button = customtkinter.CTkButton(main_frame,
text="Generate Lists",
command=generate_lists_clicked
)
selectGenerateList_button.grid(row=3,
column=0,
padx=20,
pady=10,
sticky="w"
)
selectOpenList_button = customtkinter.CTkButton(main_frame,
text="Open",
command=open_the_csv
)
selectOpenList_button.grid(row=4,
column=0,
padx=20,
pady=10,
sticky="w"
)
def copy_files_frame(): #define the main frame when a list is generated and the copy process is to be enacted
main_frame = customtkinter.CTkFrame(root,
width=main_frame_width,
corner_radius=0,
fg_color="#404040"
)
main_frame.grid(row=0,
column=1,
sticky="nsew"
)
main_label = customtkinter.CTkLabel(main_frame,
text="Copy Files",
font=customtkinter.CTkFont(size=20, weight="bold")
)
main_label.grid(row=0,
column=0,
padx=20,
pady=(20, 10)
)
selectFolderPath_button = customtkinter.CTkButton(main_frame,
text="Select Source csv",
command=select_source_csv
)
selectFolderPath_button.grid(row=2,
column=0,
padx=20,
pady=10,
sticky="w"
)
selectGenerateList_button = customtkinter.CTkButton(main_frame,
text="Select Destination Path",
command=select_destination_path
)
selectGenerateList_button.grid(row=3,
column=0,
padx=20,
pady=10,
sticky="w"
)
selectOpenList_button = customtkinter.CTkButton(main_frame,
text="Start Copying",
command=start_copying
)
selectOpenList_button.grid(row=4,
column=0,
padx=20,
pady=10,
sticky="w"
)
def delete_files_frame(): #define the main frame when the intent is to bulk delete files from a list (usually delete duplicates)
main_frame = customtkinter.CTkFrame(root,
width=main_frame_width,
corner_radius=0,
fg_color="#404040"
)
main_frame.grid(row=0,
column=1,
sticky="nsew"
)
main_label = customtkinter.CTkLabel(main_frame,
text="This frame will provide\nfunctionality for the deleting\nfiles function",
font=customtkinter.CTkFont(size=20, weight="bold")
)
main_label.grid(row=0,
column=0,
padx=20,
pady=20,
sticky="w"
)
def select_folder(): #select the folder to create the list of duplicate and unique files
global path_name
path_name = filedialog.askdirectory(initialdir="/",
title="Select a Folder"
)
print(path_name, "was selected as the path for analysis")
def generate_lists_clicked():
print("Searching for duplicates in", path_name)
generate_duplicates(path_name)
print("Searching for unique files in", path_name)
generate_unique(path_name)
#refer https://stackoverflow.com/questions/77383219/how-do-i-make-a-customtkinter-button-run-a-function-without-freezing for big directory may need to thread
def open_the_csv():
if os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", "Duplicates.csv")) != 0:
os.startfile(os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", "Duplicates.csv"))
if os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", "UniqueFiles.csv")) != 0:
os.startfile(os.path.join(os.path.dirname(os.path.abspath(__file__)), "output", "UniqueFiles.csv"))
def select_source_csv(): #for copying or deleting the csv contents
global source_name
source_name = filedialog.askopenfilename(initialdir=os.path.join(os.path.dirname((os.path.abspath(__file__))), "Output"),
title="Select Duplicates or UniqueFiles csv File"
)
print(source_name, "was selected as the source csv")
def select_destination_path(): #for copying the csv contents to
global destination_name
destination_name = filedialog.askdirectory(initialdir="/",
title="Select a destination Folder"
)
print(destination_name, "was selected as the destination folder")
def start_copying():
print("Copying commenced")
copy_files_from_csv(source_name, destination_name)
#placeholders for actions invoked by pressing a button
def delete_files_clicked():
pass
home_frame() #create the home frame when starting main.py
menu_frame() #create the menu sidebar too
root.mainloop() #go time