Skip to content

Commit 1c63ca4

Browse files
authored
Add files via upload
1 parent fb72a06 commit 1c63ca4

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Thu Apr 4 23:33:02 2024
4+
5+
@author: Anas Odeh
6+
"""
7+
8+
from pathlib import Path
9+
from tkinter import Tk, Canvas, Button, PhotoImage, messagebox
10+
from tkinter.ttk import Progressbar
11+
import os
12+
import shutil
13+
import easygui
14+
import threading
15+
from tkinter import *
16+
from tkinter import font
17+
from PIL import ImageTk, Image
18+
import time
19+
20+
21+
w=Tk()
22+
23+
#Using piece of code from old splash screen
24+
width_of_window = 427
25+
height_of_window = 250
26+
screen_width = w.winfo_screenwidth()
27+
screen_height = w.winfo_screenheight()
28+
x_coordinate = (screen_width/2)-(width_of_window/2)
29+
y_coordinate = (screen_height/2)-(height_of_window/2)
30+
w.geometry("%dx%d+%d+%d" %(width_of_window,height_of_window,x_coordinate,y_coordinate))
31+
# w.configure(bg='#ED1B76')
32+
w.overrideredirect(1) #for hiding titlebar
33+
34+
#new window to open
35+
def new_win():
36+
q=Tk()
37+
q.title('main window')
38+
q.mainloop()
39+
40+
Frame(w, width=800, height=250, bg='black').place(x=0,y=0)
41+
label1=Label(w, text='ImageRenamingApp\nBy Anas Odeh', fg='#F64A4A', bg='black')
42+
label1.configure(font=("Arial", 24, "bold"))
43+
label1.place(x=55,y=60)
44+
45+
label2=Label(w, text='Loading...', fg='#F64A4A', bg='black')
46+
label2.configure(font=("Arial", 20))
47+
label2.place(x=160,y=180)
48+
49+
#making animation
50+
51+
image_a=ImageTk.PhotoImage(Image.open('Group 2.png'))
52+
image_b=ImageTk.PhotoImage(Image.open('Group 1.png'))
53+
54+
55+
for i in range(5): #5loops
56+
l1=Label(w, image=image_a, border=0, relief=SUNKEN).place(x=180, y=160)
57+
l2=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=200, y=160)
58+
l3=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=220, y=160)
59+
l4=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=240, y=160)
60+
w.update_idletasks()
61+
time.sleep(0.07)
62+
63+
l1=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=180, y=160)
64+
l2=Label(w, image=image_a, border=0, relief=SUNKEN).place(x=200, y=160)
65+
l3=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=220, y=160)
66+
l4=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=240, y=160)
67+
w.update_idletasks()
68+
time.sleep(0.07)
69+
70+
l1=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=180, y=160)
71+
l2=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=200, y=160)
72+
l3=Label(w, image=image_a, border=0, relief=SUNKEN).place(x=220, y=160)
73+
l4=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=240, y=160)
74+
w.update_idletasks()
75+
time.sleep(0.07)
76+
77+
l1=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=180, y=160)
78+
l2=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=200, y=160)
79+
l3=Label(w, image=image_b, border=0, relief=SUNKEN).place(x=220, y=160)
80+
l4=Label(w, image=image_a, border=0, relief=SUNKEN).place(x=240, y=160)
81+
w.update_idletasks()
82+
time.sleep(0.07)
83+
84+
w.destroy()
85+
86+
OUTPUT_PATH = Path(__file__).parent
87+
ASSETS_PATH = OUTPUT_PATH / Path(r"C:\Users\Home\Desktop\Anas Odeh\computional biology\build\assets\frame0")
88+
89+
def relative_to_assets(path: str) -> Path:
90+
return ASSETS_PATH / Path(path)
91+
92+
def update_progress(value):
93+
# Update the progress bar's value
94+
progress_bar['value'] = value
95+
# Update the text above the progress bar to show current progress percentage
96+
progress_text = f"Progress: {int(value)}%"
97+
canvas.itemconfig(progress_label, text=progress_text)
98+
window.update_idletasks()
99+
100+
def complete_progress():
101+
messagebox.showinfo("Success", "Images have been successfully renamed and pooled.")
102+
# Reset progress bar and label when done
103+
progress_bar['value'] = 0
104+
canvas.itemconfig(progress_label, text="Progress: 0%")
105+
106+
def process_images():
107+
base_directory = input_folder
108+
output_directory = os.path.join(base_directory, 'pooled_images')
109+
110+
if not os.path.exists(output_directory):
111+
os.makedirs(output_directory)
112+
113+
items = [item for item in os.listdir(base_directory) if os.path.isdir(os.path.join(base_directory, item)) and item != 'pooled_images']
114+
total_items = len(items)
115+
116+
for index, item in enumerate(items, start=1):
117+
item_path = os.path.join(base_directory, item)
118+
for file in os.listdir(item_path):
119+
if file.lower().endswith(('.png', '.jpg', '.jpeg', '.tif')):
120+
old_file_path = os.path.join(item_path, file)
121+
new_file_name = f"{item}{os.path.splitext(file)[1]}"
122+
new_file_path_in_subfolder = os.path.join(item_path, new_file_name)
123+
new_file_path_in_output = os.path.join(output_directory, new_file_name)
124+
125+
# Rename within the subfolder
126+
if not os.path.exists(new_file_path_in_subfolder):
127+
shutil.move(old_file_path, new_file_path_in_subfolder)
128+
129+
# Copy to the pooled_images directory
130+
if not os.path.exists(new_file_path_in_output):
131+
shutil.copy2(new_file_path_in_subfolder, new_file_path_in_output)
132+
break
133+
134+
progress = (index / total_items) * 100
135+
window.after(100, update_progress, progress)
136+
137+
window.after(100, complete_progress)
138+
139+
def start_image_processing_thread():
140+
if 'input_folder' not in globals():
141+
messagebox.showerror("Error", "Please select your input folder first!")
142+
return
143+
144+
# Start the image processing in a separate thread to avoid UI freezing
145+
threading.Thread(target=process_images, daemon=True).start()
146+
147+
def select_input_folder():
148+
folder = easygui.diropenbox()
149+
if folder:
150+
global input_folder
151+
input_folder = folder
152+
153+
window = Tk()
154+
window.geometry("1440x1024")
155+
window.configure(bg="#FFFFFF")
156+
157+
canvas = Canvas(window, bg="#FFFFFF", height=1024, width=1440, bd=0, highlightthickness=0, relief="ridge")
158+
canvas.place(x=0, y=0)
159+
160+
image_image_1 = PhotoImage(file=relative_to_assets("image_1.png"))
161+
image_1 = canvas.create_image(719.0, 512.0, image=image_image_1)
162+
163+
canvas.create_text(60.0, 964.0, anchor="nw", text="©️By using this application, you must cite the name of the app developer, Anas Odeh", fill="#FFFFFF", font=("Inter Bold", 32 * -1))
164+
165+
image_image_2 = PhotoImage(file=relative_to_assets("image_2.png"))
166+
image_2 = canvas.create_image(735.0, 55.0, image=image_image_2)
167+
168+
button_image_1 = PhotoImage(file=relative_to_assets("button_1.png"))
169+
button_1 = Button(image=button_image_1, borderwidth=0, highlightthickness=0, command=select_input_folder, relief="flat")
170+
button_1.place(x=446.0, y=236.0, width=603.0, height=45.0)
171+
172+
button_image_2 = PhotoImage(file=relative_to_assets("button_2.png"))
173+
button_2 = Button(image=button_image_2, borderwidth=0, highlightthickness=0, command=start_image_processing_thread, relief="flat")
174+
button_2.place(x=594.0, y=317.0, width=283.0, height=41.0)
175+
176+
# Create and place the progress label and bar
177+
progress_label = canvas.create_text(720, 400, text="Progress: 0%", fill="white", font=("Helvetica", 24))
178+
progress_bar = Progressbar(canvas, orient='horizontal', length=1000, mode='determinate')
179+
progress_bar.place(x=220, y=425)
180+
181+
image_image_3 = PhotoImage(file=relative_to_assets("image_3.png"))
182+
image_3 = canvas.create_image(712.0, 150.0, image=image_image_3)
183+
184+
window.resizable(False, False)
185+
window.mainloop()

0 commit comments

Comments
 (0)