-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
160 lines (135 loc) · 4.28 KB
/
gui.py
File metadata and controls
160 lines (135 loc) · 4.28 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
import webview
import os
import sys
import subprocess
import json
CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.json")
DEFAULT_CONFIG = {
"font": {
"family": "Montserrat",
"size": 80,
"bold": True,
"italic": False
},
"colors": {
"text": "#FFFFFF",
"highlight": "#E48200",
"outline": "#000000",
"background": "#000000",
"background_opacity": 100
},
"outline_size": 4,
"position": {
"alignment": "bottom_center",
"offset_y": 50
},
"styles": {
"karaoke": {},
"word_pop": {
"pop_scale": 130
},
"zoom_in": {
"anim_duration": 150,
"start_scale": 25,
"accel": 3
}
}
}
class Api:
def test_connection(self):
print("Python recibió la llamada desde HTML")
return "Conexión OK"
def select_input_file(self):
file_types = ('Video files (*.mp4;*.mov;*.mkv)', 'Audio files (*.mp3;*.aac;*.wav)')
result = webview.windows[0].create_file_dialog(
webview.FileDialog.OPEN,
allow_multiple=False,
file_types=file_types,
)
if result:
return result[0]
return None
def select_output_folder(self):
result = webview.windows[0].create_file_dialog(webview.FileDialog.FOLDER)
if result:
return result[0]
return None
def get_config(self):
if not os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
json.dump(DEFAULT_CONFIG, f, ensure_ascii=False, indent=2)
return DEFAULT_CONFIG
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
return json.load(f)
def save_config(self, cfg):
try:
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
json.dump(cfg, f, ensure_ascii=False, indent=2)
return "Settings saved successfully"
except Exception as e:
return f"Error saving config: {str(e)}"
def receive_form_data(self, data):
if not data["input_path"]:
return "Error: No input video"
if not data["output_path"]:
return "Error: No folder output"
# -------------------------
# Detectar modo ejecución
# -------------------------
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.path.dirname(__file__)
py_path = os.path.join(base_path, "subwizard.py")
script_path = sys.argv[0]
if script_path.endswith(".exe"):
command = ["subwizard.exe"]
else:
command = [sys.executable, py_path]
# Construcción del comando
command.extend([
data["input_path"],
"--max-words", str(data["words_per_line"]),
"--performance", data["performance"],
"--output-name", data["output_filename"],
"--output-path", data["output_path"],
"--output-type", data["output_format"],
"--style", data["sub_style"],
])
if data["language"] and data["language"] != "auto":
command.extend(["--lang", data["language"]])
printable_cmd = " ".join(
f'"{c}"' if " " in c else c for c in command
)
print("\nComando generado:")
print(printable_cmd)
# -------------------------
# Ejecutar
# -------------------------
try:
result = subprocess.run(
command,
capture_output=True,
text=True,
shell=False
)
if result.returncode != 0:
print("STDERR:")
print(result.stderr)
return f"Error:\n{result.stderr}"
print("STDOUT:")
print(result.stdout)
return "Subtitling completed successfully"
except Exception as e:
return f"Critical error: {str(e)}"
if __name__ == "__main__":
api = Api()
webview.create_window(
title="subwizard",
url="gui/gui.html",
js_api=api,
width=600,
height=800,
resizable=False,
)
webview.start()