Repository navigation
Expand file tree
/
Copy pathscript.py
More file actions
226 lines (162 loc) · 6.71 KB
/
Copy pathscript.py
File metadata and controls
226 lines (162 loc) · 6.71 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
import os
import shutil
import json
import tkinter as tk
from tkinter import filedialog, messagebox
from PIL import Image, ImageTk
folder_name = None
base_directory = None
image_paths = []
default_image = None
default_image_preview = None
def create_folder(base_directory, folder_name):
new_folder_path = os.path.join(base_directory, folder_name)
if not os.path.exists(new_folder_path):
os.makedirs(new_folder_path)
return new_folder_path
def copy_images(image_paths, folder_name):
if isinstance(image_paths, str):
shutil.copy(image_paths, folder_name)
elif isinstance(image_paths, list):
for image in image_paths:
shutil.copy(image, folder_name)
def create_json_90(folder_path, name, image_dir):
catpack_data = {
"name": name,
"default": image_dir
}
json_file = os.path.join(folder_path, "catpack.json")
with open(json_file, 'w') as f:
json.dump(catpack_data, f, indent=4)
def select_directory():
global base_directory
base_directory = filedialog.askdirectory(title="Select Output Directory")
if base_directory:
output_dir_button.config(text=f"Will be placed in: {base_directory}")
def select_images():
global image_paths
filetypes = [("Image files", "*.png *.jpg *.jpeg *.bmp")]
new_image_paths = filedialog.askopenfilenames(
title="Select Images", filetypes=filetypes)
if new_image_paths:
image_paths.extend(new_image_paths)
images_button.config(text=f"Selected {len(image_paths)} image(s)")
update_image_list()
def remove_image(image_path):
global image_paths
image_paths.remove(image_path)
update_image_list()
images_button.config(text=f"Selected {len(image_paths)} image(s)")
def view_image(image_path):
view_window = tk.Toplevel(root)
view_window.title(f"Viewing: {os.path.basename(image_path)}")
img = Image.open(image_path)
img.thumbnail((500, 500)) # Resize for display
img_preview = ImageTk.PhotoImage(img)
label = tk.Label(view_window, image=img_preview)
label.image = img_preview # Keep a reference to avoid garbage collection
label.pack()
close_button = tk.Button(view_window, text="Close", command=view_window.destroy)
close_button.pack(pady=10)
def update_image_list():
for widget in image_list_frame.winfo_children():
widget.destroy()
for image_path in image_paths:
frame = tk.Frame(image_list_frame)
frame.pack(fill="x", pady=2)
label = tk.Label(frame, text=os.path.basename(image_path), anchor="w")
label.pack(side="left", fill="x", expand=True)
view_button = tk.Button(
frame, text="View", command=lambda p=image_path: view_image(p))
view_button.pack(side="right", padx=5)
remove_button = tk.Button(
frame, text="Remove", command=lambda p=image_path: remove_image(p))
remove_button.pack(side="right")
# Add a separator line
separator = tk.Frame(image_list_frame, height=1, bg="gray")
separator.pack(fill="x", pady=2)
def select_default_image():
global default_image, default_image_full_path, default_image_preview
filetypes = [("Image files", "*.png *.jpg *.jpeg *.bmp")]
default_image_full_path = filedialog.askopenfilename(
title="Select Default Image", filetypes=filetypes)
if default_image_full_path:
default_image = os.path.basename(default_image_full_path)
default_image_button.config(text=f"Default Image: {default_image}")
img = Image.open(default_image_full_path)
img.thumbnail((100, 100))
default_image_preview = ImageTk.PhotoImage(img)
default_image_label.config(image=default_image_preview)
default_image_label.pack(pady=5)
def prompt_subfolder_name():
subfolder_window = tk.Toplevel(root)
subfolder_window.title("Set Subfolder Name")
subfolder_window.geometry("300x150")
tk.Label(subfolder_window,
text="Enter the subfolder name for images:").pack(pady=10)
subfolder_name_entry = tk.Entry(subfolder_window)
subfolder_name_entry.pack(pady=5)
tk.Label(subfolder_window,
text="Note: Setting the name to 'random' randomizes the images."
).pack(pady=10)
def confirm_subfolder_name():
subfolder_name = subfolder_name_entry.get()
if not subfolder_name:
messagebox.showerror("Error", "Please enter a subfolder name.")
return
subfolder_path = os.path.join(
base_directory, folder_name, subfolder_name)
os.makedirs(subfolder_path, exist_ok=True)
copy_images(image_paths, subfolder_path)
create_catpack(folder_name, subfolder_name)
subfolder_window.destroy()
messagebox.showinfo(
"Success", "9.0 catpack successfully created.")
confirm_button = tk.Button(
subfolder_window, text="Confirm", command=confirm_subfolder_name)
confirm_button.pack(pady=10)
def create_catpack(folder_name, subfolder_name=None):
manifest = {
"name": folder_name,
"default": subfolder_name if subfolder_name else "logos",
}
manifest_path = os.path.join(base_directory, folder_name, "catpacks.json")
with open(manifest_path, 'w') as f:
json.dump(manifest, f, indent=4)
def on_confirm():
global folder_name, default_image
folder_name = folder_name_entry.get()
if not folder_name:
messagebox.showerror("Error", "Please enter a folder name.")
return
if not base_directory:
messagebox.showerror("Error", "Please select an output folder.")
return
if not image_paths and not default_image:
messagebox.showerror("Error", "Please select at least one image.")
return
new_folder_path = create_folder(base_directory, folder_name)
# 9.0 mode: Prompt for subfolder and create JSON in the subfolder
prompt_subfolder_name()
root = tk.Tk()
root.title("CatPack Creator")
root.geometry("800x600")
tk.Label(root, text="Enter Catpack Name:").pack(pady=5)
folder_name_entry = tk.Entry(root)
folder_name_entry.pack(pady=5)
output_dir_button = tk.Button(
root, text="Select Folder", command=select_directory)
output_dir_button.pack(pady=5)
images_button = tk.Button(root, text="Add Images", command=select_images)
images_button.pack(pady=5)
# New frame to display selected images
image_list_frame = tk.Frame(root)
image_list_frame.pack(fill="both", expand=True, pady=5)
default_image_button = tk.Button(
root, text="Select Default Image", command=select_default_image)
default_image_button.pack(pady=5)
default_image_label = tk.Label(root)
default_image_label.pack()
confirm_button = tk.Button(root, text="Confirm", command=on_confirm)
confirm_button.pack(pady=10)
root.mainloop()