scripts/images/manage.py

129 lines
3.5 KiB
Python
Raw Normal View History

2023-03-08 13:41:14 +03:00
import os
import shutil
import tkinter
2023-05-08 18:21:26 +03:00
from time import sleep
2023-03-08 13:41:14 +03:00
from PIL import ImageTk, Image
# Dialog box for selecting a folder.
file_path = input("Path: ")
files = []
print("started loading files")
for dirpath, _, filenames in os.walk(file_path):
for f in filenames:
files.append(os.path.abspath(os.path.join(dirpath, f)))
2023-05-08 18:21:26 +03:00
files = sorted(files, key=os.path.getsize, reverse=True)
2023-03-08 13:41:14 +03:00
print("files loaded")
if not os.path.exists(os.path.join(file_path, "sorted")):
os.makedirs(os.path.join(file_path, "sorted"))
if not os.path.exists(os.path.join(file_path, "sorted/drawn")):
os.makedirs(os.path.join(file_path, "sorted/drawn"))
drawn = os.path.join(file_path, "sorted/drawn")
if not os.path.exists(os.path.join(file_path, "sorted/real")):
os.makedirs(os.path.join(file_path, "sorted/real"))
real = os.path.join(file_path, "sorted/real")
if not os.path.exists(os.path.join(file_path, "sorted/comic")):
os.makedirs(os.path.join(file_path, "sorted/comic"))
comic = os.path.join(file_path, "sorted/comic")
if not os.path.exists(os.path.join(file_path, "sorted/other")):
os.makedirs(os.path.join(file_path, "sorted/other"))
other = os.path.join(file_path, "sorted/other")
if not os.path.exists(os.path.join(file_path, "sorted/delete")):
os.makedirs(os.path.join(file_path, "sorted/delete"))
delete = os.path.join(file_path, "sorted/delete")
class Window:
def __init__(self, master, files):
self.img = None
self.label = None
self.files = files
self.cur = 0
self.master = master
init_file = self.files[0]
self.show_file(init_file)
def show_file(self, f):
self.img = Image.open(f)
2023-05-08 18:21:26 +03:00
x = self.img.height / 1080
self.img = self.img.resize((int(self.img.width / x), 1080), Image.LANCZOS)
2023-03-08 13:41:14 +03:00
self.img = ImageTk.PhotoImage(self.img)
self.label = tkinter.Label(self.master, image=self.img)
2023-05-08 18:21:26 +03:00
self.label.pack_propagate(0)
self.label.pack(side=tkinter.TOP, expand=True, fill=tkinter.X)
2023-03-08 13:41:14 +03:00
def next(self, event):
self.cur += 1
self.show_file(self.files[self.cur])
2023-05-08 18:21:26 +03:00
sleep(0.1)
2023-03-08 13:41:14 +03:00
def real(self, event):
self.label.destroy()
shutil.move(
self.files[self.cur],
os.path.join(real, str(self.files[self.cur]).split("/")[-1]),
)
self.next(event)
def drawn(self, event):
self.label.destroy()
shutil.move(
self.files[self.cur],
os.path.join(drawn, str(self.files[self.cur]).split("/")[-1]),
)
self.next(event)
def comic(self, event):
self.label.destroy()
shutil.move(
self.files[self.cur],
os.path.join(comic, str(self.files[self.cur]).split("/")[-1]),
)
self.next(event)
def other(self, event):
self.label.destroy()
shutil.move(
self.files[self.cur],
os.path.join(other, str(self.files[self.cur]).split("/")[-1]),
)
self.next(event)
def delete(self, event):
self.label.destroy()
shutil.move(
self.files[self.cur],
os.path.join(delete, str(self.files[self.cur]).split("/")[-1]),
)
self.next(event)
root = tkinter.Tk()
root.title("1 - real; 2 - drawn; 3 - comic; 4 - other; 5 - delete")
window = Window(root, files)
root.bind("<Return>", window.next)
root.bind("1", window.real)
root.bind("2", window.drawn)
root.bind("3", window.comic)
root.bind("4", window.other)
root.bind("5", window.delete)
root.mainloop()
root.mainloop()