-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
190 lines (156 loc) · 6.99 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
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
import tkinter as tk
from tkinter import ttk, filedialog as fd, messagebox
import threading
from modules import actions
import os
os.environ['TK_SILENCE_DEPRECATION'] = '1'
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title('Convert Premier')
self.iconbitmap('./assets/icon.ico')
self.frm = ttk.Frame(self, padding=10, width=300, height=400)
self.frm.grid()
self.setup_styles()
self.setup_widgets()
def setup_styles(self):
self.style = ttk.Style()
self.style.configure(
'TEntry',
padding=[5, 2],
font=('Arial', 12),
fieldbackground='white',
foreground='black',
borderwidth=2,
relief='solid',
bordercolor='#ccc'
)
self.style.configure(
'TButton',
padding=[5, 5],
font=('Arial', 12),
relief='raised',
borderwidth=2,
)
self.style.configure(
'TLabel',
font=('Arial', 12),
)
self.style.configure(
'TLabelFrame',
font=('Arial', 12, 'bold'),
borderwidth=2,
relief='solid',
)
def setup_widgets(self):
self.nameProject_entry, _ = self.create_entry(
self.frm, "Nombre del proyecto", 0, 0)
self.select_file_btn = self.create_button(
self.frm, "Select File", self.select_file, 2, 0)
self.process_video_btn = self.create_button(
self.frm, "Procesar Video", self.process_video, 3, 0)
# Crear un LabelFrame para el grupo Miniatura
self.miniature_frame = ttk.LabelFrame(
self.frm, text="Miniatura", padding=(10, 5))
self.miniature_frame.grid(
column=0, row=4, padx=10, pady=10, sticky=(tk.W, tk.E))
# Crear las entradas para el grupo Miniatura
self.scale_var = tk.StringVar(value='25')
self.scale_entry, self.scale_label = self.create_entry(
self.miniature_frame, "Escala", 0, 0, validate=True, textvariable=self.scale_var)
self.right_cut_percentage_var = tk.StringVar(value='0')
self.right_cut_percentage_entry, _ = self.create_entry(
self.miniature_frame, "Porcentaje de corte a la derecha", 1, 0, textvariable=self.right_cut_percentage_var)
self.left_cut_percentage_var = tk.StringVar(value='50')
self.left_cut_percentage_entry, _ = self.create_entry(
self.miniature_frame, "Porcentaje de corte a la izquierda", 1, 1, textvariable=self.left_cut_percentage_var)
self.vertical_position_var = tk.StringVar(value='0.354622')
self.vertical_position_entry, _ = self.create_entry(
self.miniature_frame, "Posición vertical miniatura", 2, 0, textvariable=self.vertical_position_var)
self.horizontal_position_var = tk.StringVar(value='0.119977')
self.horizontal_position_entry, _ = self.create_entry(
self.miniature_frame, "Posición horizontal miniatura", 2, 1, textvariable=self.horizontal_position_var)
self.hide_miniature_frame_and_button()
self.file_label = ttk.Label(self.frm, text="")
self.file_label.grid(column=0, row=5)
self.select_dir_btn = self.create_button(
self.frm, "Select Directory Save Project", self.select_directory, 6, 0)
self.dir_label = ttk.Label(self.frm, text="")
self.dir_label.grid(column=0, row=7)
def select_directory(self):
directory = fd.askdirectory()
if directory: # Si se seleccionó un directorio
self.dir_label.config(text=directory)
def create_entry(self, parent, label_text, row, column, validate=False, textvariable=None):
label = ttk.Label(parent, text=label_text)
label.grid(column=column, row=row * 2)
if validate:
validate_command = self.register(self.validate_input)
entry = ttk.Entry(parent, width=40, validate='key', validatecommand=(
validate_command, '%P'), textvariable=textvariable) # Cambié width a 40
else:
# Cambié width a 40
entry = ttk.Entry(parent, width=40, textvariable=textvariable)
entry.grid(column=column, row=row * 2 + 1)
return entry, label # Devuelve tanto la entrada como la etiqueta
def create_button(self, parent, text, command, row, column):
btn = ttk.Button(parent, text=text, command=command)
btn.grid(column=column, row=row)
return btn
def select_file(self):
filename = fd.askopenfilename(
filetypes=[('videos', '*.mp4'), ('All files', '*.*')])
if filename: # Si un archivo fue seleccionado
self.file_label.config(text=filename)
self.show_miniature_frame_and_button()
else: # Si no se seleccionó ningún archivo (se presionó 'Cancelar')
self.hide_miniature_frame_and_button()
def process_video(self):
new_video = self.file_label.cget("text")
name_project = self.nameProject_entry.get()
# Suponiendo que quieres mostrar el estado en la interfaz, podrías necesitar una etiqueta para mostrar esto
loading = tk.StringVar()
# Puedes crear una etiqueta para mostrar el estado de 'loading' si lo deseas
loading_label = ttk.Label(self.frm, textvariable=loading)
# Ajusta la fila y columna como necesites
loading_label.grid(column=0, row=6)
dir_label = self.dir_label.cget("text")
if(dir_label == ""):
messagebox.showerror('Error', 'Selecciona un directorio para guardar el proyecto')
run_translate(
new_video,
name_project,
loading,
miniature={
'scale': self.scale_var.get(),
'right_cut_percentage': self.right_cut_percentage_var.get(),
'left_cut_percentage': self.left_cut_percentage_var.get(),
'vertical_position': self.vertical_position_var.get(),
'horizontal_position': self.horizontal_position_var.get(),
},
save_directory=dir_label
)
def validate_input(self, value_if_allowed):
if value_if_allowed == '' or value_if_allowed.isdigit():
return True
return False
def show_miniature_frame_and_button(self):
self.miniature_frame.grid(
column=0, row=4, padx=10, pady=10, sticky=(tk.W, tk.E))
self.process_video_btn.grid(column=0, row=3) # Muestra el botón
def hide_miniature_frame_and_button(self):
self.miniature_frame.grid_remove()
self.process_video_btn.grid_remove() # Oculta el botón
def run_translate(new_video: str, name_project: str, loading, miniature: dict = None, save_directory: str = None):
print(miniature)
t = threading.Thread(target=actions.edit_video, args=(
new_video,
name_project,
loading,
miniature,
save_directory
))
t.start()
if __name__ == "__main__":
app = App()
app.mainloop()