-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
83 lines (71 loc) · 2.98 KB
/
main.py
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
from tkinter import *
from tkinter.filedialog import askopenfilename, askdirectory
from tkinter import messagebox
# from patoolib import extract_archive
from pyunpack import Archive
import os,sys
def resource_path(path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, path)
# creating the window ↓↓↓
win = Tk()
win.geometry("400x270")
win.title("Artin Zip Extractor")
win.resizable(0,0)
win.iconbitmap(resource_path("./logo.ico"))
win.configure(bg="hotpink")
forbidden_characters = ['/', '\\', ':', '*', '?', '"', '<', '>', '|']
def browse():
address.config(state='normal')
address.delete(0,"end")
global loc, file_name
loc = askopenfilename(initialdir="select...", title="save")
file_name = loc.split("/")[-1].split(".")[0]
print(file_name)
address.insert(0,loc)
address.config(state='readonly')
def extract():
if address.get():
if not any(char in name_input.get() for char in forbidden_characters):
global destination
def extract(zip_file, destination):
if not os.path.exists(destination):
os.makedirs(destination)
try:
# extract_archive(zip_file, outdir=destination)
Archive(zip_file).extractall(destination)
if name_input.get():
os.rename(f"{destination}/{file_name}", f"{destination}/{name_input.get()}")
messagebox.showinfo(title="Zip File", message="Your file extracted successfuly!")
else:
messagebox.showinfo(title="Zip File", message="Your file extracted successfuly!")
except:
address.config(state="normal")
address.delete(0,"end")
address.config(state="disabled")
name_input.delete(0,"end")
messagebox.showerror(title="Zip File", message="the zip file is not valid")
else:
name_input.delete(0,"end")
messagebox.showerror(title="Zip File", message="output name is not suitable")
return
zip_file_path = loc
destination = askdirectory(initialdir="where to", title="save")
extract(zip_file_path, destination)
else:
messagebox.showerror(title="Zip File", message="please choose your zipfile first")
# widgets ↓↓↓
browse_btn = Button(win, text="select...",font=("None",14), relief="flat", command=browse)
browse_btn.pack(pady=(10,0), padx=(0,188))
address = Entry(win, font=("None", 12), width=30, state="readonly")
address.pack(pady=(5,0))
name_label = Label(win, text="Enter the name:", bg="hotpink", font=("None",14))
name_input = Entry(win, font=("None", 12), width=30)
name_label.pack(pady=(40,0))
name_input.pack()
extract_btn = Button(win, text="Extract",font=("None",14), relief="flat",command=extract)
extract_btn.pack(pady=(40,0))
win.mainloop()