-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
1581 lines (1355 loc) · 75.8 KB
/
interface.py
File metadata and controls
1581 lines (1355 loc) · 75.8 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os.path
import sys
import threading
import tkinter
from tkinter import Tk, Label, StringVar, filedialog, Toplevel, OptionMenu, Scrollbar, Canvas, \
Frame
from tkcolorpicker import askcolor
import cv2
from PIL import Image, ImageTk
import config
import custom_ui
import debug
import custom_button
import history_handler
import lang
import prepass
import user_theme_config
import video_stabilization
import processing
import vlc_handler
# Global properties
LIGHT_BG = "#e8e8e8"
LIGHT_ACCENT = "#fafafa"
LIGHT_FONT_COLOR = "#000000"
DARK_BG = "#262626"
DARK_ACCENT = "#545454"
DARK_FONT_COLOR = "#ffffff"
PALENIGHT_BG = "#202331"
PALENIGHT_ACCENT = "#303754"
PALENIGHT_PB = "#78408f"
CHERRY_WHITE_BG = "#990011"
CHERRY_WHITE_ACCENT = "#fcebd4"
CHERRY_WHITE_PB = CHERRY_WHITE_BG
DARK_ORANGE_BG = "#46211A"
DARK_ORANGE_ACCENT = "#A43820"
DARK_ORANGE_PB = DARK_ORANGE_BG
u_t = user_theme_config.load_theme()
USER_BG = u_t["bg"]
USER_ACCENT = u_t["accent"]
USER_FONT_COLOR = u_t["text"]
BAR_BG_ACCENT = "#6AB187"
BASIC_PB_COLOR = "#73ff7b"
BGCOLOR = "#262626"
DARKER_BG = "#292929"
WHITE = "#ffffff"
BLACK = "#000000"
ACCENT = "#545454"
PB_COLOR = "#73ff7b"
DARK = "#262626"
FONT_COLOR = "#ffffff"
TIME_FONT_SIZE = 12
BIG_FONT_SIZE = 14
# FONT = ("Helvetica", TIME_FONT_SIZE)
# BOLD_FONT = ("Helvetica", TIME_FONT_SIZE, "bold")
FONT = ("Ubuntu", TIME_FONT_SIZE)
JET_FONT = ("JetBrains Mono", TIME_FONT_SIZE - 3)
BOLD_FONT = ("Ubuntu", TIME_FONT_SIZE, "bold")
BIG_FONT = ("Ubuntu", BIG_FONT_SIZE)
BIG_FONT_BOLD = ("Ubuntu", BIG_FONT_SIZE, "bold")
TIME_WRAPPER_WIDTH = 100
TIME_WRAPPER_HEIGHT = 80
WIN_WIDTH = 1300
WIN_HEIGHT = 590
FIN_WIN_WIDTH = 300
FIN_WIN_HEIGHT = 180
SET_WIN_WIDTH = 500
SET_WIN_HEIGHT = 500
HIS_WIN_WIDTH = 800
HIS_WIN_HEIGHT = 800
LOG_STATE = "On"
call_nr = 0
video_file_path = None
prev_video_path = None
manual_scroll = False
scroll_threshold = 0.96
class Interface:
def __init__(self):
self.clear_history_button = None
self.clear_video_button = None
self.apply_user_theme_button = None
self.cards_list = None
self.history_entries = None
self.history_scroll_canvas = None
self.history_scrollbar = None
self.history_frame = None
self.log_label_text = None
self.log_canvas = None
self.log_scrollbar = None
self.log_frame = None
self.log_text = None
self.empty_label = None
self.color_picker_items_squares = None
self.color_picker_text_items = None
self.color_picker_items = None
self.user_theme_button = None
self.log_label = None
self.log_option_menu = None
self.log_options = None
self.terminal_wrapper = None
self.terminal_text = None
self.prepass_toggle_button = None
self.stab_toggle_button = None
self.periodic_exec_id = None
self.terminate_program = False
self.prep_pbar_overlay = None
self.prep_wrapper = None
self.prep_progress_bar = None
self.prep_progress_label = None
self.stab_pbar_overlay = None
self.stab_progress_label = None
self.stab_progress_bar = None
self.stab_progress_wrapper = None
self.proc_pbar_overlay = None
self.proc_progress_bar = None
self.history_title_frame = None
self.settings_window_opened = False
self.history_window_opened = False
self.history_outline_frame = None
self.theme_options = None
self.theme_selected_option = None
self.lang_option_menu = None
self.theme_option_menu = None
self.buttons_wrapper = None
self.proc_progress_wrapper = None
self.frame_wrapper = None
self.next_lang = None
self.previous_language = None
self.prev_lang_dict = None
self.history_content_list = list()
self.outline_frame = None
self.history_exit_button = None
self.history_title = None
self.history_label = None
self.history_text = None
self.history_window = None
self.history_button = None
self.result_label = None
self.finished_title_label = None
self.save_button = None
self.lang_label = None
self.theme_label = None
self.lang_selected_option = None
self.lang_options = None
self.settings_label = None
self.settings_window = None
self.proc_progress_wrapper = None
self.media_player_button = None
self.image_details = None
self.frame_details_header = None
self.frame_wrapper = None
self.button_wrapper = None
self.im_det = None
self.ok_button = None
self.finished_window = None
self.settings_wrapper = None
self.selected_file_path = None
self.win: tkinter.Tk
self.time_label = None
self.time_wrapper = None
self.progress_bar = None
self.proc_progress_label = None
self.process_video_button = None
self.browse_button = None
self.is_file_selected = False
self.opened_file_label = None
self.settings_button = None
self.settings = config.load_settings()
self.curr_lang = self.settings[0]
self.curr_theme = self.settings[1]
self.log_state = self.settings[2]
self.image_detail_dict = None
self.browse_wrapper = None
self.browse_button = None
self.set_color()
debug.log("[Interface] [1/1] Creating interface...", text_color="blue")
self.lang = lang.load_lang(self.curr_lang)
self.set_properties()
self.create_buttons_wrapper()
self.create_settings_button()
self.create_history_button()
self.create_browser()
self.create_terminal()
debug.log("[Interface] [1/2] Interface created", text_color="blue")
self.set_interface()
self.win.mainloop()
def set_interface(self):
custom_ui.set_interface_instance(self)
def set_main_focus(self):
self.win.focus_set()
def set_log_text(self):
global manual_scroll
new_text = ""
curr_text = self.log_text.get()
with open(debug.log_file_path, 'r') as log_file:
for line in log_file:
new_text += line[32:]
if curr_text in new_text:
index = new_text.find(curr_text) + len(curr_text)
new_text = new_text[index:]
else:
new_text = new_text
print(new_text)
self.log_text.set(curr_text + new_text)
self.log_frame.update_idletasks()
self.log_canvas.config(scrollregion=self.log_canvas.bbox("all"))
if not manual_scroll:
self.log_canvas.yview_moveto(1.0)
if float(self.log_canvas.yview()[1]) >= scroll_threshold:
self.log_canvas.yview_moveto(1.0)
def create_terminal(self):
self.terminal_wrapper = custom_ui.CustomLabelFrame(self.win,
text="Log",
width=490,
height=WIN_HEIGHT - 20,
radius=15,
fill=ACCENT,
fg=FONT_COLOR,
bg=BGCOLOR)
self.terminal_wrapper.canvas.place(x=800, y=10)
self.empty_label = Label(self.terminal_wrapper.canvas, width=1, height=1, bg=ACCENT, borderwidth=0)
self.empty_label.place(x=10, y=30)
self.log_canvas = Canvas(self.empty_label, width=470, height=WIN_HEIGHT - 75, bg=ACCENT, highlightthickness=0)
self.log_scrollbar = Scrollbar(self.empty_label, orient="vertical", command=self.log_canvas.yview, width=5)
self.log_scrollbar.grid(row=0, column=1, sticky="ns")
self.log_scrollbar.grid_forget()
self.log_canvas.config(yscrollcommand=self.log_scrollbar.set)
self.log_canvas.grid(row=0, column=0, sticky="nsew")
self.log_frame = Frame(self.log_canvas, bg=ACCENT)
self.log_canvas.create_window((0, 0), window=self.log_frame, anchor="nw")
self.log_text = StringVar()
self.log_label_text = Label(self.log_frame, textvariable=self.log_text, bg=ACCENT, fg=FONT_COLOR,
wraplength=468, justify="left",
font=JET_FONT)
self.log_label_text.pack()
self.log_scrollbar.bind("<MouseWheel>", self.on_mousewheel_log)
self.log_label_text.bind("<MouseWheel>", self.on_mousewheel_log)
self.log_canvas.bind("<MouseWheel>", self.on_mousewheel_log)
self.log_frame.update_idletasks()
def set_scroll_to_bottom(self):
self.log_canvas.yview_moveto(1.0)
def on_mousewheel_log(self, event):
global manual_scroll
# Set manual_scroll to True when the user manually scrolls
manual_scroll = True
if event.num == 5 or event.delta == -120:
if self.log_canvas.yview()[1] < 1.0:
self.log_canvas.yview_scroll(1, "units")
elif event.num == 4 or event.delta == 120:
if self.log_canvas.yview()[0] > 0.0:
self.log_canvas.yview_scroll(-1, "units")
def set_color(self):
"""
Sets global color variables based on the current theme.
This function updates the global variables BGCOLOR, FONT_COLOR, ACCENT, and PB_COLOR
based on the current theme specified in `self.curr_theme`.
Global Variables:
BGCOLOR (str): Background color.
FONT_COLOR (str): Font color.
ACCENT (str): Accent color.
PB_COLOR (str): Progress bar color.
"""
global BGCOLOR, FONT_COLOR, ACCENT, PB_COLOR
# Dictionary mapping theme names to corresponding color tuples
theme_colors = {
"dark": (DARK_BG, DARK_FONT_COLOR, DARK_ACCENT, BASIC_PB_COLOR),
"light": (LIGHT_BG, LIGHT_FONT_COLOR, LIGHT_ACCENT, BASIC_PB_COLOR),
"palenight": (PALENIGHT_BG, DARK_FONT_COLOR, PALENIGHT_ACCENT, BASIC_PB_COLOR),
"cherrywhite": (CHERRY_WHITE_BG, LIGHT_FONT_COLOR, CHERRY_WHITE_ACCENT, BASIC_PB_COLOR),
"brownorange": (DARK_ORANGE_BG, DARK_FONT_COLOR, DARK_ORANGE_ACCENT, BASIC_PB_COLOR),
"usertheme": (USER_BG, USER_FONT_COLOR, USER_ACCENT, BASIC_PB_COLOR)
}
# Set global color variables based on the current theme
if self.curr_theme in theme_colors:
BGCOLOR, FONT_COLOR, ACCENT, PB_COLOR = theme_colors[self.curr_theme]
def toggle_log(self, to_state):
if to_state == "On":
self.win.geometry(str(WIN_WIDTH) + "x" + str(WIN_HEIGHT))
self.log_state = "On"
if to_state == "Off":
self.win.geometry("800x" + str(WIN_HEIGHT))
self.log_state = "Off"
def set_properties(self):
# Set windows properties
debug.log("[Interface] [2/1] Setting properties...", text_color="magenta")
self.win = Tk()
self.win["bg"] = BGCOLOR
self.win.title(self.lang["title"])
if self.log_state == "On":
self.win.geometry(str(WIN_WIDTH) + "x" + str(WIN_HEIGHT))
else:
self.win.geometry("800x" + str(WIN_HEIGHT))
self.win.resizable(False, False)
# self.win.protocol(self.on_window_close)
self.win.protocol("WM_DELETE_WINDOW", self.on_window_close)
self.selected_file_path = StringVar()
# self.create_font()
debug.log("[Interface] [2/2] Properties set!\n", text_color="magenta")
self.win.after(150, self.schedule_periodic_processing_execution)
self.win.after(150, self.schedule_terminal_update)
def schedule_terminal_update(self):
# self.update_terminal_text()
self.set_log_text()
if float(self.log_canvas.yview()[1]) > scroll_threshold:
self.log_canvas.yview_moveto(1.0)
self.win.after(150, self.schedule_terminal_update)
def schedule_periodic_processing_execution(self):
if processing.initialized and processing.callback_queue.qsize() > 0:
processing.execute_callbacks()
self.periodic_exec_id = self.win.after(150, self.schedule_periodic_processing_execution)
if processing.is_finished:
processing.execute_callbacks()
self.stop_periodic_progress_update()
processing.video_writer.release()
processing.thread.join()
self.create_finished_window()
def stop_periodic_progress_update(self):
if self.periodic_exec_id is not None:
self.win.after_cancel(self.periodic_exec_id)
self.periodic_exec_id = None
# self.create_finished_window()
def on_window_close(self):
# self.terminate_program = True
# prepass.stop_thread = True
# prepass.thread.join()
# prepass.is_finished = True
# prepass.thread = None
#
# video_stabilization.stop_thread = True
# video_stabilization.thread.join()
# video_stabilization.is_finished = True
# video_stabilization.thread = None
# processing.stop_thread = True
# processing.thread.join()
debug.log("[Interface] Stopping all threads!!!")
self.stop_periodic_progress_update()
debug.log("[Interface] Stopping prepass thread...", text_color="yellow")
prepass.stop_prepass_thread()
debug.log("[Interface] Stopped prepass thread!", text_color="magenta")
debug.log("[Interface] Stopping stabilization thread...", text_color="yellow")
video_stabilization.stop_stabilization_thread()
debug.log("[Interface] Stopped stabilization thread!", text_color="magenta")
processing.force_terminate = True
processing.stop_processing_thread()
debug.log("[Interface] Stopped threads")
self.win.destroy()
sys.exit(2)
def create_buttons_wrapper(self):
# Create wrapper for settings and history buttons
self.buttons_wrapper = custom_ui.CustomLabelFrame(self.win, text="",
fill=ACCENT,
fg=FONT_COLOR,
bg=BGCOLOR,
width=150,
height=80,
radius=15)
self.buttons_wrapper.canvas.place(x=10, y=10)
def create_settings_button(self):
# Create button to open settings window
self.settings_button = custom_button.CustomButton(self.buttons_wrapper.canvas,
command=self.create_settings_window,
button_type=custom_button.settings_button,
bg=ACCENT)
self.settings_button.canvas.place(x=10, y=self.buttons_wrapper.get_height() // 8)
def create_history_button(self):
# Create button to open window containing processing history
self.history_button = custom_button.CustomButton(self.buttons_wrapper.canvas,
command=lambda: self.create_history_window(),
button_type=custom_button.history_button,
bg=ACCENT)
self.history_button.canvas.place(x=80, y=self.buttons_wrapper.get_height() // 8)
def run_browser_on_thread(self):
# Run the file browser on a separate thread
file_browser_thread = threading.Thread(target=self.create_browser)
file_browser_thread.start()
def create_browser(self):
# Wrapper for file browsing
debug.log("[Interface] [4/1] Creating Browsing wrapper...", text_color="magenta")
self.browse_wrapper = custom_ui.CustomLabelFrame(self.win,
text=self.lang["input_file"],
fill=ACCENT,
fg=FONT_COLOR,
bg=BGCOLOR,
width=620,
height=80,
radius=15)
self.browse_wrapper.canvas.place(x=170, y=10)
debug.log("[Interface] [4/2] Browsing wrapper created!", text_color="magenta")
debug.log("[Interface] [4/3] Creating browse Button...", text_color="magenta")
self.browse_button = custom_button.CustomButton(self.browse_wrapper.canvas,
text=self.lang["browse"],
command=self.browse_files,
bg=ACCENT,
button_type=custom_button.button)
self.browse_button.canvas.place(x=10, y=30)
debug.log("[Interface] [4/4] Browse Button created!", text_color="magenta")
# Label for showing opened file path
debug.log("[Interface] [4/5] Creating file path Label...", text_color="magenta")
self.opened_file_label = Label(self.browse_wrapper.canvas,
textvariable=self.selected_file_path,
fg=FONT_COLOR,
bg=ACCENT,
font=FONT,
wraplength=520,
justify="left")
self.opened_file_label.config(text=self.lang["None"], anchor="center")
# Place right to the button, vertically centered
self.opened_file_label.place(x=85, y=self.browse_button.winfo_reqheight())
debug.log("[Interface] [4/6] File path Label created!\n", text_color="magenta")
def set_selected_file_path(self, path):
if os.path.exists(path):
global video_file_path, prev_video_path
self.selected_file_path.set(path)
self.show_first_frame_details(path)
video_file_path = path
prev_video_path = video_file_path
else:
debug.log("[Interface] [-] File path does not exist!", text_color="red")
def browse_files(self):
# Open a file dialog and get the selected file path
global video_file_path
global prev_video_path
video_file_path = prev_video_path
debug.log("[Interface] Opening file browser dialog...", text_color="magenta")
file_path = filedialog.askopenfilename(title="Select a file",
filetypes=[("Video Files", "*.mp4;*.avi;*.mkv;*.mov;*.wmv")])
# Update the label with the selected file path
if file_path:
# self.selected_file_path.set(file_path)
self.set_selected_file_path(file_path)
debug.log(f"[Interface] Selected file: {file_path}", text_color="blue")
self.show_first_frame_details(file_path)
video_file_path = file_path
prev_video_path = video_file_path
else:
debug.log("[Interface] No file selected", text_color="red")
if prev_video_path:
debug.log("[Interface] Selecting previous video", text_color="blue")
self.opened_file_label.config(text=prev_video_path)
self.show_first_frame_details(prev_video_path)
def show_first_frame_details(self, path: str):
"""
Display video details, including the first frame, in a labeled frame.
Parameters:
- path (str): The path to the video file.
This method creates a labeled frame containing the first frame of the video and details about the video.
The video details include the width, height, framerate, and bitrate.
"""
# Creating a labeled frame to contain video details
debug.log("[Interface] [5/1] Creating video details wrapper...", text_color="yellow")
self.frame_wrapper = custom_ui.CustomLabelFrame(self.win,
text=self.lang["video_data"],
fill=ACCENT,
fg=FONT_COLOR,
bg=BGCOLOR,
radius=15,
width=780,
height=320)
self.frame_wrapper.canvas.place(x=10, y=100)
debug.log("[Interface] [5/2] Video details wrapper created!", text_color="yellow")
# Creating a label to display the first frame of the video
debug.log("[Interface] [5/3] Creating placeholder label for first frame...", text_color="yellow")
frame_label = Label(self.frame_wrapper.canvas)
frame_label.place(x=10, y=self.frame_wrapper.get_label_height() + 10)
debug.log("[Interface] [5/4] First frame placeholder created!", text_color="yellow")
# Opening the video and extracting details from the first frame
debug.log("[Interface] [5/5] Opening video and getting first frame data...", text_color="yellow")
cap = cv2.VideoCapture(path)
fps = "{:.0f}".format(cap.get(cv2.CAP_PROP_FPS))
bitrate = "{:.0f}".format(cap.get(cv2.CAP_PROP_BITRATE))
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
duration = "{:.0f}s".format(frame_count / int(fps))
ret, frame = cap.read()
cap.release()
debug.log("[Interface] [5/6] First frame data gathered!", text_color="yellow")
if ret:
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = Image.fromarray(frame_rgb)
# Extracting video details from the first frame
width, height = image.size
aspect_ratio = width / height
self.image_detail_dict = {
"width": f"{image.width}px",
"height": f"{image.height}px",
"frames": f"{frame_count}",
"duration": str("{:.0f}s".format(frame_count / int(fps))),
"framerate": f"{fps} fps",
"bitrate": f"{bitrate} kbps"
}
self.im_det = (f"{self.lang["width"]}: {image.width}px\n"
f"{self.lang["height"]}: {image.height}px\n"
f"{self.lang["frames"]}: {frame_count}\n"
f"{self.lang["duration"]}: {duration}\n"
f"{self.lang["framerate"]}: {fps} fps\n"
f"{self.lang["bitrate"]}: {bitrate} kbps")
# Resizing the first frame to fit within the frame wrapper
debug.log("[Interface] [5/7] Calculating first frame information...", text_color="yellow")
new_width = self.frame_wrapper.get_width() // 2
new_height = int(new_width / aspect_ratio)
image = image.resize((new_width, new_height), Image.BILINEAR)
image_file = ImageTk.PhotoImage(image)
debug.log("[Interface] [5/8] First image information set!", text_color="yellow")
# Configuring the frame label with the resized first frame
debug.log("[Interface] [5/9] Configuring image...", text_color="yellow")
frame_label.config(image=image_file)
frame_label.image = image_file
debug.log("[Interface] [5/10] Image configured!", text_color="yellow")
# Creating button to open the video with VLC
self.media_player_button = custom_button.CustomButton(self.frame_wrapper.canvas,
text=self.lang["open_vlc"],
bg=ACCENT,
width=110,
height=30,
# command=lambda: self.open_media_player(path))
command=lambda: vlc_handler.open_video(path))
self.media_player_button.canvas.place(x=10,
y=new_height + 40)
# Creating button to start processing
self.process_video_button = custom_button.CustomButton(self.frame_wrapper.canvas,
text=self.lang["process"],
bg=ACCENT,
width=110,
height=30,
command=lambda: self.process_video())
self.process_video_button.canvas.place(x=self.media_player_button.winfo_reqwidth() + 20, y=new_height + 40)
# Creating labels to display video details
debug.log("[Interface] [5/11] Creating labels to display video details...", text_color="yellow")
self.frame_details_header = Label(self.frame_wrapper.canvas,
text=self.lang["video_det"],
fg=FONT_COLOR,
bg=ACCENT,
font=BIG_FONT_BOLD)
self.frame_details_header.place(x=new_width + 30, y=20)
self.image_details = Label(self.frame_wrapper.canvas,
text=self.im_det,
fg=FONT_COLOR,
bg=ACCENT,
font=FONT,
# Left alignment
justify="left",
anchor="w"
)
self.image_details.place(x=new_width + 30,
y=self.frame_details_header.winfo_y() + self.frame_details_header.winfo_reqheight() + 20)
debug.log("[Interface] [5/12] Labels to display video details created!\n", text_color="yellow")
if self.log_canvas is not None:
self.log_canvas.yview_moveto(1.0)
self.prepass_toggle_button = custom_ui.CustomToggleButton(self.frame_wrapper.canvas,
text=self.lang["normalization"],
width=60,
height=30,
bg=ACCENT)
self.prepass_toggle_button.canvas.place(x=new_width + 30, y=190)
self.stab_toggle_button = custom_ui.CustomToggleButton(self.frame_wrapper.canvas,
text=self.lang["stabilization"],
width=60,
height=30,
bg=ACCENT)
self.stab_toggle_button.canvas.place(x=new_width + 30, y=230)
self.plotting_toggle_button = custom_ui.CustomToggleButton(self.frame_wrapper.canvas,
text=self.lang["to_plot"],
width=60,
height=30,
state=False,
bg=ACCENT)
self.plotting_toggle_button.canvas.place(x=new_width + 30, y=270)
def process_video(self):
"""
Initiates the video processing task.
Disables relevant buttons, creates a progress bar, sets the progress callback,
and starts a separate thread for video processing.
"""
if video_file_path:
# Disable buttons to prevent multiple processing requests
self.process_video_button.disable()
self.browse_button.disable()
self.prepass_toggle_button.disable()
self.stab_toggle_button.disable()
self.plotting_toggle_button.disable()
# Create and display a progress bar
# self.create_preprocess_progress_bar()
self.create_stabilization_progress_bar()
self.create_processing_progress_bar()
# Set the progress callback functions
# processing.set_progress_callback(self.update_bar)
# opencv_stabilization.set_progress_callback(self.update_bar)
# video_stabilization.set_progress_callback(self.update_bar)
# prepass.set_progress_callback(self.update_bar)
# Start video processing in a separate thread
self.win.after(150, self.schedule_periodic_processing_execution)
debug.log(f"[Interface] Preprocessing: {self.prepass_toggle_button.get_state()}")
debug.log(f"[Interface] Stabilization: {self.stab_toggle_button.get_state()}")
debug.log(f"[Interface] Plotting: {self.plotting_toggle_button.get_state()}\n")
processing.process_video_thread(video_file_path,
self.prepass_toggle_button.get_state(),
self.stab_toggle_button.get_state(),
self.plotting_toggle_button.get_state(),
self.update_bar)
self.set_scroll_to_bottom()
def create_preprocess_progress_bar(self):
self.prep_wrapper = custom_ui.CustomLabelFrame(self.win,
text=self.lang["preprocessing"],
width=780,
height=70,
fill=ACCENT,
fg=FONT_COLOR,
radius=15,
bg=BGCOLOR)
self.prep_wrapper.canvas.place(x=10, y=430)
self.prep_progress_bar = custom_ui.CustomProgressBar(self.prep_wrapper.canvas,
width=705,
height=30,
padding=6,
bg=ACCENT,
bar_bg_accent=BAR_BG_ACCENT,
pr_bar=PB_COLOR)
self.prep_progress_bar.canvas.place(x=10, y=self.prep_wrapper.get_height() // 2 - 5)
self.prep_progress_label = Label(self.prep_wrapper.canvas,
text="0%",
fg=FONT_COLOR,
bg=ACCENT,
font=BOLD_FONT)
self.prep_progress_label.place(x=720, y=30)
self.prep_pbar_overlay = custom_ui.CustomLabelFrame(self.prep_wrapper.canvas, width=690, height=30,
bg=ACCENT, fill=ACCENT)
self.prep_pbar_overlay.canvas.place(x=20, y=self.prep_progress_bar.get_height() * 2)
def create_stabilization_progress_bar(self):
self.stab_progress_wrapper = custom_ui.CustomLabelFrame(self.win,
text=self.lang["preprocessing"],
width=780,
height=70,
fill=ACCENT,
fg=FONT_COLOR,
radius=15,
bg=BGCOLOR)
self.stab_progress_wrapper.canvas.place(x=10, y=430)
self.stab_progress_bar = custom_ui.CustomProgressBar(self.stab_progress_wrapper.canvas,
width=705,
height=30,
padding=6,
bg=ACCENT,
bar_bg_accent=BAR_BG_ACCENT,
pr_bar=PB_COLOR)
self.stab_progress_bar.canvas.place(x=10, y=self.stab_progress_wrapper.get_height() // 2 - 5)
self.stab_progress_label = Label(self.stab_progress_wrapper.canvas, text="0%", fg=FONT_COLOR, bg=ACCENT,
font=BOLD_FONT)
self.stab_progress_label.place(x=720, y=30)
debug.log("[Interface] [6/6] Progress label created!", text_color="magenta")
# Create an overlay frame for the progress bar to hide flickering bug
self.stab_pbar_overlay = custom_ui.CustomLabelFrame(self.stab_progress_wrapper.canvas, width=690, height=30,
bg=ACCENT, fill=ACCENT)
self.stab_pbar_overlay.canvas.place(x=20, y=self.stab_progress_bar.get_height() * 2)
def create_processing_progress_bar(self):
"""
Creates and displays a custom progress bar with a progress label.
"""
debug.log("[Interface] [6/1] Creating progress wrapper...", text_color="magenta")
# Create a wrapper frame for the progress bar
self.proc_progress_wrapper = custom_ui.CustomLabelFrame(self.win,
text=self.lang["progress"],
width=780,
height=70,
fill=ACCENT,
fg=FONT_COLOR,
radius=15,
bg=BGCOLOR)
self.proc_progress_wrapper.canvas.place(x=10, y=510)
debug.log("[Interface] [6/2] Progress wrapper created!", text_color="magenta")
# Create the custom progress bar
debug.log("[Interface] [6/3] Creating custom progress bar...", text_color="magenta")
self.proc_progress_bar = custom_ui.CustomProgressBar(self.proc_progress_wrapper.canvas,
width=705,
height=30,
padding=6,
bg=ACCENT,
bar_bg_accent=BAR_BG_ACCENT,
pr_bar=PB_COLOR)
self.proc_progress_bar.canvas.place(x=10, y=self.proc_progress_wrapper.get_height() // 2 - 5)
debug.log("[Interface] [6/4] Custom progress bar created!", text_color="magenta")
# Create and place the progress label
debug.log("[Interface] [6/5] Creating progress label...", text_color="magenta")
self.proc_progress_label = Label(self.proc_progress_wrapper.canvas, text="0%", fg=FONT_COLOR, bg=ACCENT,
font=BOLD_FONT)
self.proc_progress_label.place(x=720, y=30)
debug.log("[Interface] [6/6] Progress label created!\n", text_color="magenta")
if self.log_canvas is not None:
self.log_canvas.yview_moveto(1.0)
# Create an overlay frame for the progress bar to hide flickering bug
self.proc_pbar_overlay = custom_ui.CustomLabelFrame(self.proc_progress_wrapper.canvas, width=690, height=30,
bg=ACCENT, fill=ACCENT)
self.proc_pbar_overlay.canvas.place(x=20, y=self.proc_progress_bar.get_height() * 2)
def update_bar(self, bar: str, value: int):
if bar == "preprocessing":
self.prep_progress_bar.set_percentage(value)
self.prep_progress_label['text'] = f"{value} %"
elif bar == "stabilization":
self.stab_progress_bar.set_percentage(value)
self.stab_progress_label['text'] = f"{value} %"
elif bar == "processing":
self.proc_progress_bar.set_percentage(value)
self.proc_progress_label['text'] = f"{value} %"
def update_progress(self, value: int):
"""
Updates the progress bar and label with the given value.
Parameters:
value (int): The progress value to be displayed.
"""
# Set the progress bar percentage
self.proc_progress_bar.set_percentage(value)
# Update the progress label with the current value
self.proc_progress_label['text'] = f"{value} %"
# Check if processing has finished
if processing.finished:
# Log the processing difference in the debug console
debug.log(f"[Interface] {self.lang['diff']}: {processing.total_difference}", text_color="blue")
# Create and display the finished window
# self.create_finished_window()
def create_finished_window(self):
"""
Creates and displays the window to show processing result.
If the window already exists, it will be closed before creating a new one.
"""
# Close existing finished window if it exists
if self.finished_window is not None:
self.close_finished_windows(to_debug=False)
# Create a new Toplevel window for displaying processing result
self.finished_window = Toplevel(self.win)
self.finished_window.title(self.lang["result_win_title"])
self.finished_window.geometry(str(FIN_WIN_WIDTH) + "x" + str(FIN_WIN_HEIGHT))
self.finished_window.configure(background=ACCENT)
self.finished_window.resizable(False, False)
debug.log(f"[Interface] Finished window opened!")
# Center the finished window on the screen
screen_width = self.finished_window.winfo_screenwidth()
screen_height = self.finished_window.winfo_screenheight()
x = (screen_width - FIN_WIN_WIDTH) // 2
y = (screen_height - FIN_WIN_HEIGHT) // 2
self.finished_window.geometry(f"+{x}+{y}")
# Add labels and buttons to the finished window
self.finished_title_label = Label(self.finished_window,
text=self.lang["proc_finished"],
fg=FONT_COLOR,
bg=ACCENT,
font=BOLD_FONT)
self.finished_title_label.pack(pady=20)
self.result_label = Label(self.finished_window,
text=f"{self.lang['diff']}: {processing.get_result()}",
fg=FONT_COLOR,
bg=ACCENT,
font=FONT)
self.result_label.pack(pady=0)
self.ok_button = custom_button.CustomButton(self.finished_window,
text=self.lang["ok"],
bg=ACCENT,
command=self.close_finished_windows,
button_type=custom_button.button)
self.ok_button.canvas.pack(pady=20)
# Enable buttons in the main window
self.process_video_button.enable()
self.browse_button.enable()
self.prepass_toggle_button.enable()
self.stab_toggle_button.enable()
self.plotting_toggle_button.enable()
def close_finished_windows(self, to_debug=True):
self.browse_button.enable()
self.process_video_button.enable()
self.ok_button.destroy()
self.finished_window.destroy()
if to_debug:
debug.log("[Interface] Finished window closed!", text_color="cyan")
def create_settings_window(self):
"""
Creates the settings window.
This method creates a window where users can configure settings such as language and theme.
Args:
self: The instance of the Interface class.
Returns:
None
"""
if self.settings_window_opened is True:
self.settings_window.focus_set()
return
# Create the settings window
self.settings_window = Toplevel(self.win)
self.settings_window.title(self.lang["settings"])
self.settings_window.geometry(f"{SET_WIN_WIDTH}x{SET_WIN_HEIGHT}")
self.settings_window.configure(background=BGCOLOR)
self.settings_window.resizable(False, False)
self.settings_window.bind("<Destroy>", lambda e: self.close_settings_window())
# Add a label for the settings window title
self.settings_wrapper = custom_ui.CustomLabelFrame(self.settings_window,
width=SET_WIN_WIDTH - 20,
height=SET_WIN_HEIGHT - 20,
fg=FONT_COLOR,
radius=15,
fill=ACCENT,
bg=BGCOLOR)
self.settings_wrapper.canvas.place(x=10, y=10)
self.settings_label = Label(self.settings_wrapper.canvas,
text=self.lang["settings"],
fg=FONT_COLOR,
bg=ACCENT,
font=BOLD_FONT,
anchor="center")
self.settings_label.place(x=self.settings_wrapper.get_width() // 2 - self.settings_label.winfo_reqwidth() // 2,
y=10)
# Add a label for the language selection
self.lang_label = Label(self.settings_wrapper.canvas,
text=self.lang["lang"],
fg=FONT_COLOR,
bg=ACCENT,
font=FONT, )
self.lang_label.place(x=(self.settings_wrapper.get_width() - self.lang_label.winfo_reqwidth()) // 2 - 40,
y=self.settings_label.winfo_y() + 50)
# Define language options
self.lang_options = [self.lang["english"], self.lang["hungarian"]]
# Set default language option based on current language setting
self.lang_selected_option = StringVar(self.settings_window)
self.lang_selected_option.set(self.lang_options[1] if self.curr_lang == "hungarian" else self.lang_options[0])
# Add language OptionMenu
self.lang_option_menu = OptionMenu(self.settings_wrapper.canvas, self.lang_selected_option, *self.lang_options)
self.lang_option_menu.config(anchor="center",
bg=ACCENT,
fg=FONT_COLOR,
activebackground=ACCENT,
# activeforeground=FONT_COLOR,
highlightbackground=ACCENT)
self.lang_option_menu.place(x=(self.settings_wrapper.get_width() - self.lang_label.winfo_reqwidth()) // 2 + 40,
y=self.lang_label.winfo_reqheight() * 2)
# Add a label for the theme selection
self.theme_label = Label(self.settings_wrapper.canvas,
text=self.lang["theme"],
fg=FONT_COLOR,
bg=ACCENT,
font=FONT,
anchor="center")
self.theme_label.place(x=(self.settings_wrapper.get_width() - self.lang_label.winfo_reqwidth()) // 2 - 40,
y=self.lang_label.winfo_reqheight() * 4)
# Define theme options
self.theme_options = [self.lang["dark"], self.lang["light"], self.lang["palenight"], self.lang["cherrywhite"],
self.lang["brownorange"], self.lang["user_theme"]]
# Set default theme option based on current theme setting
self.theme_selected_option = StringVar(self.settings_wrapper.canvas)
# Map theme index
theme_index_mapping = {
"dark": 0,
"light": 1,
"palenight": 2,
"cherrywhite": 3,
"brownorange": 4,
"usertheme": 5
}
self.theme_selected_option.set(self.theme_options[theme_index_mapping.get(self.curr_theme, 0)])
# Add theme OptionMenu
self.theme_option_menu = OptionMenu(self.settings_wrapper.canvas, self.theme_selected_option,
*self.theme_options)
self.theme_option_menu.config(anchor="center",
bg=ACCENT,
fg=FONT_COLOR,