-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
152 lines (127 loc) · 6.15 KB
/
Copy pathgui.py
File metadata and controls
152 lines (127 loc) · 6.15 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
import os
import threading
import customtkinter as ctk
from tkinter import filedialog
import converter
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue")
def font(size, weight="normal"):
return ctk.CTkFont(family="Rubik", size=size, weight=weight)
class ConverterApp(ctk.CTk):
def __init__(self):
super().__init__()
self.title("File2File")
self.geometry("460x400")
self.resizable(False, False)
self.configure(fg_color="#2b2b2b")
self.source_path = ""
self.output_base = ""
self.output_path = ""
self._build_ui()
self.format_var.trace_add("write", self._on_format_changed)
def _build_ui(self):
ctk.CTkLabel(
self, text="File2File",
font=font(18, "bold"),
text_color="#ffffff"
).pack(padx=24, pady=(22, 18), anchor="w")
ctk.CTkLabel(self, text="Source File", font=font(11), text_color="#888888").pack(padx=24, anchor="w")
src = ctk.CTkFrame(self, fg_color="#383838", corner_radius=0)
src.pack(padx=24, pady=(4, 14), fill="x")
ctk.CTkButton(
src, text="Browse", width=72, height=28,
fg_color="#484848", hover_color="#525252",
text_color="#cccccc", font=font(12),
corner_radius=0, command=self._browse_source
).pack(side="left", padx=10, pady=10)
self.source_label = ctk.CTkLabel(src, text="No file selected", text_color="#777777", font=font(12), anchor="w")
self.source_label.pack(side="left", padx=(0, 10), fill="x", expand=True)
ctk.CTkLabel(self, text="Save As", font=font(11), text_color="#888888").pack(padx=24, anchor="w")
out = ctk.CTkFrame(self, fg_color="#383838", corner_radius=0)
out.pack(padx=24, pady=(4, 14), fill="x")
ctk.CTkButton(
out, text="Browse", width=72, height=28,
fg_color="#484848", hover_color="#525252",
text_color="#cccccc", font=font(12),
corner_radius=0, command=self._browse_output
).pack(side="left", padx=10, pady=10)
self.output_label = ctk.CTkLabel(out, text="No destination set", text_color="#777777", font=font(12), anchor="w")
self.output_label.pack(side="left", padx=(0, 10), fill="x", expand=True)
ctk.CTkLabel(self, text="Format", font=font(11), text_color="#888888").pack(padx=24, anchor="w")
self.format_var = ctk.StringVar(value="MP4")
ctk.CTkOptionMenu(
self, variable=self.format_var,
values=["MOV", "MP4", "MP3", "MKV", "WEBM", "PNG", "JPG", "WEBP", "GIF"],
width=160, height=32,
fg_color="#383838", button_color="#484848", button_hover_color="#525252",
text_color="#cccccc", dropdown_fg_color="#383838", dropdown_hover_color="#484848",
font=font(12), dropdown_font=font(12)
).pack(padx=24, pady=(4, 18), anchor="w")
self.convert_btn = ctk.CTkButton(
self, text="Convert", height=40,
fg_color="#1a1a1a", hover_color="#111111",
text_color="#ffffff", font=font(13, "bold"),
corner_radius=0, command=self._start_conversion
)
self.convert_btn.pack(padx=24, fill="x")
self.status_label = ctk.CTkLabel(self, text="Idle", font=font(11), text_color="#777777")
self.status_label.pack(padx=24, pady=(12, 0), anchor="w")
def _browse_source(self):
path = filedialog.askopenfilename(
filetypes=[("Media files", "*.mov *.mp4 *.mp3 *.mkv *.webm *.png *.jpg *.jpeg *.webp *.gif"), ("All files", "*.*")]
)
if path:
self.source_path = path
self.source_label.configure(text=path if len(path) <= 52 else f"…{path[-51:]}", text_color="#cccccc")
def _browse_output(self):
fmt = self.format_var.get().lower()
path = filedialog.asksaveasfilename(
defaultextension=f".{fmt}",
filetypes=[(f"{fmt.upper()} file", f"*.{fmt}"), ("All files", "*.*")]
)
if path:
self.output_base, _ = os.path.splitext(path)
self._refresh_output_label()
def _on_format_changed(self, *_args):
self._refresh_output_label()
def _refresh_output_label(self):
if not self.output_base:
return
fmt = self.format_var.get().lower()
self.output_path = f"{self.output_base}.{fmt}"
self.output_label.configure(
text=self.output_path if len(self.output_path) <= 52 else f"…{self.output_path[-51:]}",
text_color="#cccccc"
)
def _start_conversion(self):
if not self.source_path:
self.status_label.configure(text="Select a source file first.")
return
if not self.output_base:
self.status_label.configure(text="Set a destination path first.")
return
self._refresh_output_label()
self.convert_btn.configure(state="disabled", text="Converting…")
self.status_label.configure(text="Converting...")
threading.Thread(target=self._run_conversion, daemon=True).start()
def _run_conversion(self):
dispatch = {
"MOV": converter.to_mov, "MP4": converter.to_mp4,
"MP3": converter.to_mp3, "MKV": converter.to_mkv,
"WEBM": converter.to_webm, "PNG": converter.to_png,
"JPG": converter.to_jpg, "WEBP": converter.to_webp,
"GIF": converter.video_to_gif,
}
fmt = self.format_var.get()
destination = self.output_path
try:
dispatch[fmt](self.source_path, destination)
self.after(0, lambda: self.status_label.configure(text="Done.", text_color="#cccccc"))
except Exception as exc:
print(f"[Error] {exc}")
self.after(0, lambda e=str(exc): self.status_label.configure(text=f"Error: {e[:60]}", text_color="#888888"))
finally:
self.after(0, lambda: self.convert_btn.configure(state="normal", text="Convert"))
if __name__ == "__main__":
app = ConverterApp()
app.mainloop()