-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArchiveExtractor.py
More file actions
243 lines (201 loc) · 8.33 KB
/
ArchiveExtractor.py
File metadata and controls
243 lines (201 loc) · 8.33 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
import os
import sys
import threading
import time
import traceback
from queue import Queue, Empty
from tkinter import filedialog, messagebox
import ttkbootstrap as tb
import patoolib # pip install patool
import tkinter as tk # make sure to import tkinter for Listbox
from tkinterdnd2 import DND_FILES, TkinterDnD
# =================== APP CONFIG ===================
APP_NAME = "QuickExtract - Archive Extractor"
APP_VERSION = "2.0.0"
# =================== APP ===================
# Use TkinterDnD for drag-and-drop support
app = TkinterDnD.Tk()
app.title(f"{APP_NAME} {APP_VERSION}")
app.geometry("1000x600")
tb.Style("darkly")
# =================== UTILITY ===================
def resource_path(file_name):
base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, file_name)
def log_error():
with open("error.log", "a", encoding="utf-8") as f:
f.write(traceback.format_exc() + "\n")
def show_about():
messagebox.showinfo(
f"About {APP_NAME} v{APP_VERSION}",
f"{APP_NAME} v{APP_VERSION}\n"
"Batch and single archive extractor supporting 70+ formats.\n\n"
"Features:\n"
"• Drag & drop or browse archives\n"
"• Batch extraction\n"
"• Per-file extraction progress\n"
"• Pause / Stop extraction\n"
"• Error logging\n\n"
"Built with Python, Tkinter & ttkbootstrap\n"
"© 2026 Mate Technologies"
)
try:
app.iconbitmap(resource_path("logo.ico"))
except Exception:
pass
# =================== MENU ===================
menubar = tb.Menu(app)
help_menu = tb.Menu(menubar, tearoff=0)
help_menu.add_command(label="About", command=show_about)
menubar.add_cascade(label="Help", menu=help_menu)
app.config(menu=menubar)
# =================== FLAGS & QUEUE ===================
stop_flag = False
pause_flag = False
ui_queue = Queue()
tb.Label(app, text=APP_NAME, font=("Segoe UI", 22, "bold")).pack(pady=(10, 2))
tb.Label(
app,
text="Fast, Drag & Drop Archive Extractor – Supports 70+ Formats",
font=("Segoe UI", 10, "italic"),
foreground="#9ca3af"
).pack(pady=(0, 10))
# =================== FRAME: Archive Selection ===================
frame1 = tb.Labelframe(app, text="Archive Selection & Controls", padding=10)
frame1.pack(fill="x", padx=10, pady=6)
archive_list = []
output_path = tb.StringVar()
def add_archives():
files = filedialog.askopenfilenames(title="Select Archives")
for f in files:
if f not in archive_list:
archive_list.append(f)
ui_queue.put(("add", f))
def clear_archives():
archive_list.clear()
ui_queue.put(("clear", None))
def set_output_folder():
folder = filedialog.askdirectory()
if folder:
output_path.set(folder)
# Listbox to show selected archives
list_frame = tb.Frame(frame1)
list_frame.pack(fill="x", pady=6)
archive_listbox = tk.Listbox(list_frame, height=6, selectmode="extended")
archive_listbox.pack(side="left", fill="x", expand=True)
# Make the archive_listbox a drop target
archive_listbox.drop_target_register(DND_FILES)
archive_listbox.dnd_bind('<<Drop>>', lambda e: drop(e))
scroll = tb.Scrollbar(list_frame, command=archive_listbox.yview)
scroll.pack(side="right", fill="y")
archive_listbox.config(yscrollcommand=scroll.set)
tb.Button(frame1, text="Add Archives", command=add_archives, bootstyle="success").pack(side="left", padx=4)
tb.Button(frame1, text="Clear List", command=clear_archives, bootstyle="danger-outline").pack(side="left", padx=4)
tb.Label(frame1, text="Output Folder:", width=13).pack(side="left", padx=(12,0))
tb.Entry(frame1, textvariable=output_path, width=40).pack(side="left", padx=6)
tb.Button(frame1, text="Browse", command=set_output_folder).pack(side="left", padx=4)
extract_btn = tb.Button(frame1, text="🗜 Extract", bootstyle="success")
pause_btn = tb.Button(frame1, text="⏸ Pause", bootstyle="warning-outline", state="disabled")
stop_btn = tb.Button(frame1, text="🛑 Stop", bootstyle="danger-outline", state="disabled")
extract_btn.pack(side="left", padx=4)
pause_btn.pack(side="left", padx=4)
stop_btn.pack(side="left", padx=4)
# =================== FRAME: Progress ===================
frame2 = tb.Labelframe(app, text="Progress", padding=8)
frame2.pack(fill="x", padx=10)
progress_var = tb.IntVar()
tb.Progressbar(frame2, variable=progress_var, maximum=100, length=500).pack(side="left", padx=10)
status_lbl = tb.Label(frame2, text="Status: Ready")
status_lbl.pack(side="left", padx=10)
# =================== FRAME: Log ===================
frame3 = tb.Labelframe(app, text="Extraction Log", padding=8)
frame3.pack(fill="both", expand=True, padx=10, pady=6)
# Use tk.Text instead of tb.Text
log_text = tk.Text(frame3, height=10)
log_text.pack(side="left", fill="both", expand=True)
# Scrollbar properly linked to the text widget
log_scroll = tk.Scrollbar(frame3, command=log_text.yview)
log_scroll.pack(side="right", fill="y")
log_text.config(yscrollcommand=log_scroll.set, state="disabled")
# =================== EXTRACTION CORE ===================
def extract_archives():
global stop_flag, pause_flag
stop_flag = pause_flag = False
extract_btn.config(state="disabled")
pause_btn.config(state="normal")
stop_btn.config(state="normal")
total_files = len(archive_list)
if total_files == 0:
messagebox.showerror("Error","No archives selected.")
extract_btn.config(state="normal")
return
output_dir = output_path.get() or os.path.dirname(archive_list[0])
for idx, archive in enumerate(archive_list,1):
if stop_flag:
ui_queue.put(("log", "Extraction stopped by user."))
break
while pause_flag:
status_lbl.config(text="Status: Paused")
time.sleep(0.1)
ui_queue.put(("log", f"Extracting: {archive}"))
try:
patoolib.extract_archive(archive, outdir=output_dir, interactive=False)
ui_queue.put(("log", f"✅ Completed: {archive}"))
except Exception:
log_error()
ui_queue.put(("log", f"❌ Failed: {archive}"))
percent = int((idx/total_files)*100)
ui_queue.put(("progress", percent))
ui_queue.put(("complete", "Extraction finished."))
# =================== UI QUEUE PROCESS ===================
def process_ui_queue():
try:
while True:
cmd, data = ui_queue.get_nowait()
if cmd == "add":
archive_listbox.insert("end", data)
elif cmd == "clear":
archive_listbox.delete(0,"end")
elif cmd == "progress":
progress_var.set(data)
elif cmd == "log":
log_text.config(state="normal")
log_text.insert("end", data+"\n")
log_text.see("end")
log_text.config(state="disabled")
elif cmd == "complete":
progress_var.set(100)
status_lbl.config(text=f"Status: {data}")
extract_btn.config(state="normal")
pause_btn.config(state="disabled")
stop_btn.config(state="disabled")
except Empty:
pass
app.after(100, process_ui_queue)
# =================== BUTTON COMMANDS ===================
def toggle_pause():
global pause_flag
pause_flag = not pause_flag
pause_btn.config(text="▶ Resume" if pause_flag else "⏸ Pause")
def stop_extraction():
global stop_flag
stop_flag = True
status_lbl.config(text="Status: Stopping...")
extract_btn.config(command=lambda: threading.Thread(target=extract_archives, daemon=True).start())
pause_btn.config(command=toggle_pause)
stop_btn.config(command=stop_extraction)
# =================== DRAG & DROP ===================
def drop(event):
files = app.tk.splitlist(event.data)
for f in files:
if os.path.isfile(f) and f not in archive_list:
archive_list.append(f)
ui_queue.put(("add", f))
try:
app.drop_target_register(DND_FILES)
app.dnd_bind('<<Drop>>', drop)
except:
pass # fallback if dnd not supported
# =================== START UI LOOP ===================
app.after(100, process_ui_queue)
app.mainloop()