-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathethoscore.py
More file actions
2947 lines (2476 loc) · 129 KB
/
ethoscore.py
File metadata and controls
2947 lines (2476 loc) · 129 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 sys
import os
import time
import pandas as pd
import json
import warnings
import cv2
import numpy as np
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
# Suppress warnings before importing modules that might trigger them
warnings.filterwarnings("ignore", category=UserWarning, module="pkg_resources")
warnings.filterwarnings("ignore")
from PySide6.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout,
QWidget, QPushButton, QLabel, QFileDialog, QComboBox,
QMessageBox, QInputDialog, QDialog,
QFormLayout, QKeySequenceEdit, QDialogButtonBox, QSpinBox,
QGroupBox, QTabWidget, QCheckBox, QSplitter, QListWidget, QListWidgetItem, QMenu, QScrollArea, QStackedWidget) # Added QStackedWidget
from PySide6.QtCore import Qt, QTimer, QSettings, QCoreApplication, Signal
from PySide6.QtGui import QKeySequence, QFont, QPainter, QColor, QPen, QBrush, QIcon
from PySide6.QtSvgWidgets import QSvgWidget
# Suppress pygame messages
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import pygame
from annotator_libs.video_handling import VideoPlayer
from annotator_libs.ui_components import (BehaviorButtons, TimelineWidget, LoadingScreen,
get_friendly_controller_name, JoystickCurveGraph)
from annotator_libs.annotation_logic import (
load_annotations_from_csv,
save_annotations_to_csv, update_annotations_on_frame_change,
handle_label_state_change, remove_labels_from_frame,
check_label_removal_on_backward_navigation, handle_behavior_removal,
get_default_behaviors
)
from annotator_libs.gamification_logic import GamificationManager, LiveScoreWidget, GamificationSettingsDialog
# Suppress Qt warnings
os.environ['QT_LOGGING_RULES'] = '*.warning=false'
class UnifiedSettingsDialog(QDialog):
"""A unified settings dialog with a sidebar for better organization."""
def __init__(self, main_window):
super().__init__(main_window)
self.main_window = main_window
self.setWindowTitle("Settings")
self.setMinimumSize(750, 550)
self.setModal(True)
# Apply dark theme style
self.setStyleSheet("""
QDialog {
background-color: #1a1a1a;
color: #e0e0e0;
}
QListWidget {
background-color: #252525;
border: none;
border-right: 1px solid #3d3d3d;
outline: none;
padding-top: 10px;
}
QListWidget::item {
padding: 12px 15px;
border-left: 3px solid transparent;
color: #888888;
font-weight: bold;
}
QListWidget::item:selected {
background-color: #2a2a2a;
color: #3498db;
border-left: 3px solid #3498db;
}
QListWidget::item:hover:!selected {
background-color: #2a2a2a;
color: #bbbbbb;
}
QStackedWidget {
background-color: #1a1a1a;
}
QGroupBox {
font-weight: bold;
border: 1px solid #3d3d3d;
border-radius: 8px;
margin-top: 20px;
padding-top: 20px;
color: #3498db;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 5px;
}
QLabel {
color: #bbbbbb;
}
QSpinBox, QComboBox, QKeySequenceEdit {
background-color: #252525;
color: white;
border: 1px solid #3d3d3d;
border-radius: 4px;
padding: 5px;
}
QCheckBox {
color: #bbbbbb;
}
QPushButton {
padding: 8px 15px;
border-radius: 5px;
font-weight: bold;
}
""")
self.setup_ui()
self.load_all_settings()
def setup_ui(self):
main_layout = QVBoxLayout(self)
main_layout.setContentsMargins(0, 0, 0, 0)
main_layout.setSpacing(0)
# Content area with sidebar
content_layout = QHBoxLayout()
content_layout.setSpacing(0)
# Sidebar
self.sidebar = QListWidget()
self.sidebar.setFixedWidth(180)
self.sidebar.addItem("General")
self.sidebar.addItem("Keyboard")
self.sidebar.addItem("Controller")
self.sidebar.addItem("Gamification")
self.sidebar.currentRowChanged.connect(self.display_page)
content_layout.addWidget(self.sidebar)
# Right side: Stacked widget
self.stacked_widget = QStackedWidget()
# Create pages
self.setup_general_page()
self.setup_keyboard_page()
self.setup_controller_page()
self.setup_gamification_page()
content_layout.addWidget(self.stacked_widget)
main_layout.addLayout(content_layout)
# Bottom buttons
button_container = QWidget()
button_container.setStyleSheet("background-color: #1a1a1a; border-top: 1px solid #3d3d3d;")
button_layout = QHBoxLayout(button_container)
self.buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel | QDialogButtonBox.RestoreDefaults,
Qt.Horizontal, self
)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.buttons.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.restore_defaults)
# Apply specific button styles
self.buttons.button(QDialogButtonBox.Ok).setStyleSheet("background-color: #3498db; color: white;")
self.buttons.button(QDialogButtonBox.Cancel).setStyleSheet("background-color: #3d3d3d; color: white;")
self.buttons.button(QDialogButtonBox.RestoreDefaults).setStyleSheet("background-color: #3d3d3d; color: white;")
button_layout.addWidget(self.buttons)
main_layout.addWidget(button_container)
self.sidebar.setCurrentRow(0)
def display_page(self, index):
self.stacked_widget.setCurrentIndex(index)
def setup_general_page(self):
page = QWidget()
layout = QVBoxLayout(page)
layout.setContentsMargins(30, 20, 30, 20)
header = QLabel("General Settings")
header.setStyleSheet("font-size: 18px; font-weight: bold; color: white; margin-bottom: 10px;")
layout.addWidget(header)
# UI Group
ui_group = QGroupBox("User Interface")
ui_form = QFormLayout(ui_group)
self.show_frame_preview_bars_checkbox = QCheckBox("Show frame preview bars (color bars above timeline)")
ui_form.addRow(self.show_frame_preview_bars_checkbox)
self.show_statistics_popup_checkbox = QCheckBox("Show statistics summary when loading next video")
ui_form.addRow(self.show_statistics_popup_checkbox)
layout.addWidget(ui_group)
# Labeling Group
labeling_group = QGroupBox("Labeling Behavior")
labeling_form = QFormLayout(labeling_group)
self.hold_time_spin = QSpinBox()
self.hold_time_spin.setRange(10, 2000)
self.hold_time_spin.setSuffix(" ms")
labeling_form.addRow("Hold detection threshold:", self.hold_time_spin)
self.label_key_mode_combo = QComboBox()
self.label_key_mode_combo.addItem("Hybrid (tap to toggle, hold to activate)", "both")
self.label_key_mode_combo.addItem("Toggle only", "toggle")
self.label_key_mode_combo.addItem("Hold only", "hold")
labeling_form.addRow("Activation mode:", self.label_key_mode_combo)
self.multitrack_checkbox = QCheckBox("Enable Multitrack (overlap multiple labels)")
labeling_form.addRow(self.multitrack_checkbox)
self.include_last_frame_checkbox = QCheckBox("Include the last selected frame in ranges")
labeling_form.addRow(self.include_last_frame_checkbox)
layout.addWidget(labeling_group)
# Auto-Save Group
save_group = QGroupBox("Auto-Save")
save_form = QFormLayout(save_group)
self.auto_save_checkbox = QCheckBox("Enable periodic auto-save")
save_form.addRow(self.auto_save_checkbox)
self.auto_save_interval_spin = QSpinBox()
self.auto_save_interval_spin.setRange(1, 60)
self.auto_save_interval_spin.setSuffix(" minutes")
save_form.addRow("Interval:", self.auto_save_interval_spin)
layout.addWidget(save_group)
layout.addStretch()
self.stacked_widget.addWidget(page)
def setup_keyboard_page(self):
page = QWidget()
layout = QVBoxLayout(page)
layout.setContentsMargins(30, 20, 30, 20)
header = QLabel("Keyboard Settings")
header.setStyleSheet("font-size: 18px; font-weight: bold; color: white; margin-bottom: 10px;")
layout.addWidget(header)
# Navigation Group
nav_group = QGroupBox("Navigation")
nav_form = QFormLayout(nav_group)
self.frame_step_spin = QSpinBox()
self.frame_step_spin.setRange(1, 100)
nav_form.addRow("Arrow key step size:", self.frame_step_spin)
self.shift_skip_spin = QSpinBox()
self.shift_skip_spin.setRange(1, 1000)
nav_form.addRow("Shift + Arrow skip size:", self.shift_skip_spin)
layout.addWidget(nav_group)
# Shortcuts Group
shortcuts_group = QGroupBox("Shortcuts")
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setStyleSheet("background-color: transparent; border: none;")
scroll_content = QWidget()
shortcuts_form = QFormLayout(scroll_content)
self.shortcut_edits = {}
shortcut_labels = {
'save': 'Save Annotations',
'load_video': 'Load Video',
'load_next_video': 'Load Next Video',
'next_frame': 'Next Frame',
'prev_frame': 'Previous Frame',
'delete': 'Delete Labels at Frame',
'undo': 'Undo Last Action',
'move_label_up': 'Move Last Label Up',
'move_label_down': 'Move Last Label Down',
}
# Add behavior shortcuts
num_behaviors = len(self.main_window.behavior_buttons.behaviors)
for i in range(1, num_behaviors + 1):
shortcut_labels[f'toggle_behavior_{i}'] = f'Toggle Label {i} ({self.main_window.behavior_buttons.behaviors[i-1]})'
for key, label in shortcut_labels.items():
edit = QKeySequenceEdit()
self.shortcut_edits[key] = edit
shortcuts_form.addRow(label, edit)
scroll.setWidget(scroll_content)
layout.addWidget(scroll)
self.stacked_widget.addWidget(page)
def setup_controller_page(self):
page = QWidget()
layout = QVBoxLayout(page)
layout.setContentsMargins(30, 20, 30, 20)
header = QLabel("Controller Settings")
header.setStyleSheet("font-size: 18px; font-weight: bold; color: white; margin-bottom: 10px;")
layout.addWidget(header)
# Controller Config Group
config_group = QGroupBox("Joystick Configuration")
config_form = QFormLayout(config_group)
self.deadzone_spin = QSpinBox()
self.deadzone_spin.setRange(0, 50)
self.deadzone_spin.setSuffix(" %")
config_form.addRow("Deadzone:", self.deadzone_spin)
self.joystick_sensitivity_spin = QSpinBox()
self.joystick_sensitivity_spin.setRange(1, 10)
config_form.addRow("Sensitivity:", self.joystick_sensitivity_spin)
self.joystick_mode_combo = QComboBox()
self.joystick_mode_combo.addItem("Linear", "linear")
self.joystick_mode_combo.addItem("Quadratic", "quadratic")
self.joystick_mode_combo.addItem("Custom", "custom")
config_form.addRow("Response curve:", self.joystick_mode_combo)
self.joystick_expo_spin = QSpinBox()
self.joystick_expo_spin.setRange(0, 100)
self.joystick_expo_spin.setSuffix(" %")
self.joystick_expo_label = QLabel("Custom Expo:")
config_form.addRow(self.joystick_expo_label, self.joystick_expo_spin)
self.joystick_super_rate_spin = QSpinBox()
self.joystick_super_rate_spin.setRange(0, 95)
self.joystick_super_rate_spin.setSuffix(" %")
self.joystick_super_rate_label = QLabel("Super Rate:")
config_form.addRow(self.joystick_super_rate_label, self.joystick_super_rate_spin)
# Add curve graph
self.curve_graph = JoystickCurveGraph()
config_form.addRow("Response Graph:", self.curve_graph)
# Connect signals to update the graph
self.deadzone_spin.valueChanged.connect(self.update_curve_graph)
self.joystick_sensitivity_spin.valueChanged.connect(self.update_curve_graph)
self.joystick_expo_spin.valueChanged.connect(self.update_curve_graph)
self.joystick_super_rate_spin.valueChanged.connect(self.update_curve_graph)
self.joystick_mode_combo.currentIndexChanged.connect(self.update_curve_graph)
layout.addWidget(config_group)
# Playback Group
playback_group = QGroupBox("Playback Control")
playback_form = QFormLayout(playback_group)
self.frame_skip_spin = QSpinBox()
self.frame_skip_spin.setRange(1, 10)
playback_form.addRow("Frame skip rate:", self.frame_skip_spin)
self.fast_forward_multiplier_spin = QSpinBox()
self.fast_forward_multiplier_spin.setRange(1, 100)
playback_form.addRow("Fast forward speed:", self.fast_forward_multiplier_spin)
layout.addWidget(playback_group)
# Mappings Group
mappings_group = QGroupBox("Button Mappings")
mappings_layout = QVBoxLayout(mappings_group)
self.automap_list = QListWidget()
self.automap_list.setMaximumHeight(120)
self.automap_list.setStyleSheet("background-color: #252525; border: 1px solid #3d3d3d; border-radius: 4px;")
mappings_layout.addWidget(self.automap_list)
btn_layout = QHBoxLayout()
configure_btn = QPushButton("Configure Buttons")
configure_btn.setStyleSheet("background-color: #3498db; color: white;")
configure_btn.clicked.connect(self.main_window.show_controller_automap_dialog)
clear_btn = QPushButton("Clear Mappings")
clear_btn.clicked.connect(self.main_window.clear_all_automappings)
btn_layout.addWidget(configure_btn)
btn_layout.addWidget(clear_btn)
mappings_layout.addLayout(btn_layout)
layout.addWidget(mappings_group)
layout.addStretch()
self.stacked_widget.addWidget(page)
def update_curve_graph(self):
"""Update the joystick curve visualization"""
mode = self.joystick_mode_combo.currentData()
self.curve_graph.set_params(
self.deadzone_spin.value(),
self.joystick_sensitivity_spin.value(),
self.joystick_expo_spin.value(),
self.joystick_super_rate_spin.value(),
mode
)
# Only show expo and super rate spins when custom mode is selected
is_custom = (mode == "custom")
self.joystick_expo_spin.setVisible(is_custom)
self.joystick_expo_label.setVisible(is_custom)
self.joystick_super_rate_spin.setVisible(is_custom)
self.joystick_super_rate_label.setVisible(is_custom)
def setup_gamification_page(self):
page = QWidget()
layout = QVBoxLayout(page)
layout.setContentsMargins(30, 20, 30, 20)
header = QLabel("Gamification Settings")
header.setStyleSheet("font-size: 18px; font-weight: bold; color: white; margin-bottom: 10px;")
layout.addWidget(header)
# Enable/Disable
self.enable_gamification_checkbox = QCheckBox("Enable Gamification (Score & Combos)")
self.enable_gamification_checkbox.setStyleSheet("font-size: 14px; font-weight: bold; color: #3498db; margin-bottom: 10px;")
layout.addWidget(self.enable_gamification_checkbox)
# Points Group
points_group = QGroupBox("Scoring")
points_form = QFormLayout(points_group)
self.points_per_label_spin = QSpinBox()
self.points_per_label_spin.setRange(1, 1000)
points_form.addRow("Points per labeled frame:", self.points_per_label_spin)
layout.addWidget(points_group)
# Combo Group
combo_group = QGroupBox("Combos")
combo_form = QFormLayout(combo_group)
self.combo_threshold_spin = QSpinBox()
self.combo_threshold_spin.setRange(2, 20)
combo_form.addRow("Combo start threshold:", self.combo_threshold_spin)
self.combo_increment_value_spin = QSpinBox()
self.combo_increment_value_spin.setRange(1, 10)
combo_form.addRow("Multiplier increment:", self.combo_increment_value_spin)
self.combo_timeout_spin = QSpinBox()
self.combo_timeout_spin.setRange(100, 5000)
self.combo_timeout_spin.setSuffix(" ms")
combo_form.addRow("Combo timeout:", self.combo_timeout_spin)
self.combo_across_behaviors_checkbox = QCheckBox("Allow combos across different behaviors")
combo_form.addRow(self.combo_across_behaviors_checkbox)
layout.addWidget(combo_group)
# Stats
stats_group = QGroupBox("Progress")
stats_layout = QHBoxLayout(stats_group)
reset_high_score_button = QPushButton("Reset Personal High Score")
reset_high_score_button.clicked.connect(self._reset_high_score)
stats_layout.addWidget(reset_high_score_button)
layout.addWidget(stats_group)
layout.addStretch()
self.stacked_widget.addWidget(page)
def load_all_settings(self):
# General Settings
mw = self.main_window
self.hold_time_spin.setValue(mw.hold_time)
self.auto_save_checkbox.setChecked(mw.auto_save_enabled)
self.auto_save_interval_spin.setValue(mw.auto_save_interval)
mode_index = self.label_key_mode_combo.findData(mw.label_key_mode)
if mode_index >= 0: self.label_key_mode_combo.setCurrentIndex(mode_index)
self.show_frame_preview_bars_checkbox.setChecked(mw.show_frame_preview_bars)
self.include_last_frame_checkbox.setChecked(mw.include_last_frame_in_range)
self.show_statistics_popup_checkbox.setChecked(mw.show_statistics_popup)
self.multitrack_checkbox.setChecked(mw.multitrack_enabled)
# Input Settings (Keyboard)
s_input = mw.input_settings
self.frame_step_spin.setValue(s_input.value('frame_step', 1, int))
self.shift_skip_spin.setValue(s_input.value('shift_skip', 10, int))
# Shortcuts
for key, edit in self.shortcut_edits.items():
edit.setKeySequence(QKeySequence(mw.shortcuts.get(key, "")))
# Controller Settings
self.deadzone_spin.setValue(s_input.value('deadzone', 10, int))
self.joystick_sensitivity_spin.setValue(s_input.value('joystick_sensitivity', 5, int))
self.joystick_expo_spin.setValue(s_input.value('joystick_expo', 50, int))
self.joystick_super_rate_spin.setValue(s_input.value('joystick_super_rate', 0, int))
self.frame_skip_spin.setValue(s_input.value('frame_skip', 1, int))
self.fast_forward_multiplier_spin.setValue(s_input.value('fast_forward_multiplier', 10, int))
mode_index = self.joystick_mode_combo.findData(s_input.value('joystick_mode', 'quadratic', str))
if mode_index >= 0: self.joystick_mode_combo.setCurrentIndex(mode_index)
self.update_curve_graph()
self.update_automap_display()
# Gamification Settings
gm = mw.gamification_manager
self.enable_gamification_checkbox.setChecked(gm.gamification_enabled)
self.points_per_label_spin.setValue(gm.points_per_label)
self.combo_threshold_spin.setValue(gm.combo_threshold)
self.combo_increment_value_spin.setValue(gm.combo_increment_value)
self.combo_timeout_spin.setValue(gm.combo_timeout_ms)
self.combo_across_behaviors_checkbox.setChecked(gm.combo_across_behaviors)
def save_all_settings(self):
mw = self.main_window
# General Settings
mw.hold_time = self.hold_time_spin.value()
mw.auto_save_enabled = self.auto_save_checkbox.isChecked()
mw.auto_save_interval = self.auto_save_interval_spin.value()
mw.label_key_mode = self.label_key_mode_combo.currentData()
mw.show_frame_preview_bars = self.show_frame_preview_bars_checkbox.isChecked()
mw.include_last_frame_in_range = self.include_last_frame_checkbox.isChecked()
mw.show_statistics_popup = self.show_statistics_popup_checkbox.isChecked()
mw.multitrack_enabled = self.multitrack_checkbox.isChecked()
mw.save_settings()
# Keyboard/Input Settings
s_input = mw.input_settings
s_input.setValue('frame_step', self.frame_step_spin.value())
s_input.setValue('shift_skip', self.shift_skip_spin.value())
# Shortcuts
for key, edit in self.shortcut_edits.items():
mw.shortcuts[key] = edit.keySequence().toString()
mw.save_shortcuts()
mw.update_menu_shortcuts()
# Controller Settings
s_input.setValue('deadzone', self.deadzone_spin.value())
s_input.setValue('joystick_sensitivity', self.joystick_sensitivity_spin.value())
s_input.setValue('joystick_expo', self.joystick_expo_spin.value())
s_input.setValue('joystick_super_rate', self.joystick_super_rate_spin.value())
s_input.setValue('frame_skip', self.frame_skip_spin.value())
s_input.setValue('fast_forward_multiplier', self.fast_forward_multiplier_spin.value())
s_input.setValue('joystick_mode', self.joystick_mode_combo.currentData())
s_input.sync()
# Update VideoPlayer
mw.video_player.update_input_settings({
'frame_step': self.frame_step_spin.value(),
'shift_skip': self.shift_skip_spin.value(),
'deadzone': self.deadzone_spin.value(),
'joystick_sensitivity': self.joystick_sensitivity_spin.value(),
'joystick_expo': self.joystick_expo_spin.value(),
'joystick_super_rate': self.joystick_super_rate_spin.value(),
'frame_skip': self.frame_skip_spin.value(),
'fast_forward_multiplier': self.fast_forward_multiplier_spin.value(),
'joystick_mode': self.joystick_mode_combo.currentData(),
'controller_automappings': mw.video_player.controller_mappings
})
mw.video_player.multitrack_enabled = mw.multitrack_enabled
mw.video_player.update_label_key_mode(mw.label_key_mode)
mw.video_player.set_show_overlay_bars(mw.show_frame_preview_bars)
mw.video_player.set_include_last_frame_in_range(mw.include_last_frame_in_range)
# Restart auto-save timer
mw.auto_save_timer.stop()
if mw.auto_save_enabled:
mw.auto_save_timer.start(mw.auto_save_interval * 60 * 1000)
# Gamification Settings
gm = mw.gamification_manager
if gm.gamification_enabled != self.enable_gamification_checkbox.isChecked():
gm.gamification_enabled = self.enable_gamification_checkbox.isChecked()
gm.gamification_enabled_changed.emit(gm.gamification_enabled)
gm.points_per_label = self.points_per_label_spin.value()
gm.combo_threshold = self.combo_threshold_spin.value()
gm.combo_increment_value = self.combo_increment_value_spin.value()
gm.combo_timeout_ms = self.combo_timeout_spin.value()
gm.combo_across_behaviors = self.combo_across_behaviors_checkbox.isChecked()
gm.save_settings(mw.gamification_settings)
def update_automap_display(self):
self.automap_list.clear()
mappings = self.main_window.video_player.controller_mappings
if mappings:
for button_name, behavior in mappings.items():
friendly_name = get_friendly_controller_name(button_name)
self.automap_list.addItem(f"{friendly_name} → {behavior}")
else:
self.automap_list.addItem("No mappings configured")
def _reset_high_score(self):
if QMessageBox.question(self, "Reset High Score", "Are you sure you want to reset your high score? This cannot be undone.") == QMessageBox.Yes:
self.main_window.gamification_manager.reset_high_score()
def restore_defaults(self):
# General defaults
self.hold_time_spin.setValue(100)
self.auto_save_checkbox.setChecked(False)
self.auto_save_interval_spin.setValue(3)
self.label_key_mode_combo.setCurrentIndex(0) # Hybrid
self.show_frame_preview_bars_checkbox.setChecked(True)
self.include_last_frame_checkbox.setChecked(True)
self.show_statistics_popup_checkbox.setChecked(True)
self.multitrack_checkbox.setChecked(True)
# Keyboard defaults
self.frame_step_spin.setValue(1)
self.shift_skip_spin.setValue(10)
# Default shortcuts
default_shortcuts = {
'save': 'Ctrl+S', 'load_video': 'Ctrl+O', 'load_next_video': 'Ctrl+N',
'next_frame': 'Right', 'prev_frame': 'Left', 'delete': 'Escape', 'undo': 'Ctrl+Z',
'move_label_up': 'Up', 'move_label_down': 'Down'
}
for i in range(1, 11):
default_shortcuts[f'toggle_behavior_{i}'] = str(i) if i <= 9 else '0'
for key, shortcut in default_shortcuts.items():
if key in self.shortcut_edits:
self.shortcut_edits[key].setKeySequence(QKeySequence(shortcut))
# Controller defaults
self.deadzone_spin.setValue(10)
self.joystick_sensitivity_spin.setValue(5)
self.joystick_expo_spin.setValue(50)
self.joystick_super_rate_spin.setValue(0)
self.frame_skip_spin.setValue(1)
self.fast_forward_multiplier_spin.setValue(10)
self.joystick_mode_combo.setCurrentIndex(1) # Quadratic
self.update_curve_graph()
# Gamification defaults
self.enable_gamification_checkbox.setChecked(True)
self.points_per_label_spin.setValue(1)
self.combo_threshold_spin.setValue(3)
self.combo_increment_value_spin.setValue(1)
self.combo_timeout_spin.setValue(1000)
self.combo_across_behaviors_checkbox.setChecked(True)
def accept(self):
self.save_all_settings()
super().accept()
class WelcomeDialog(QDialog):
"""Welcome dialog for selecting video to annotate"""
controllers_rescanned = Signal() # Signal emitted when controllers are rescanned
def __init__(self, last_video_path="", parent=None):
super().__init__(parent)
self.last_video_path = last_video_path
self.selected_video_path = None
# Initialize pygame for controller detection
pygame.init()
pygame.joystick.init()
self.controller_count = pygame.joystick.get_count()
self.controller_name = ""
if self.controller_count > 0:
try:
joystick = pygame.joystick.Joystick(0)
joystick.init()
self.controller_name = joystick.get_name()
except:
self.controller_name = "Controller detected"
self.setup_ui()
def setup_ui(self):
self.setWindowTitle("Ethoscore")
self.setModal(True)
self.setFixedSize(600, 450)
self.setStyleSheet("""
QDialog {
background-color: #1a1a1a;
color: #e0e0e0;
}
QLabel {
color: #e0e0e0;
}
QPushButton {
background-color: #333333;
color: white;
border: none;
border-radius: 6px;
padding: 10px;
font-weight: bold;
font-size: 12px;
}
QPushButton:hover {
background-color: #444444;
}
QPushButton#primaryBtn {
background-color: #3498db;
}
QPushButton#primaryBtn:hover {
background-color: #2980b9;
}
QPushButton#secondaryBtn {
background-color: #2ecc71;
}
QPushButton#secondaryBtn:hover {
background-color: #27ae60;
}
""")
layout = QVBoxLayout(self)
layout.setSpacing(25)
layout.setContentsMargins(30, 30, 30, 30)
# Title
title_label = QLabel("ETHOSCORE")
title_font = QFont()
title_font.setPointSize(24)
title_font.setBold(True)
title_font.setLetterSpacing(QFont.AbsoluteSpacing, 2)
title_label.setFont(title_font)
title_label.setAlignment(Qt.AlignCenter)
title_label.setStyleSheet("color: #3498db; margin-bottom: 10px;")
layout.addWidget(title_label)
# Top row: rescan button (left) and logo (right)
top_row = QHBoxLayout()
top_row.setSpacing(10)
# Rescan Controllers button (left)
self.rescan_btn = QPushButton("Rescan Controllers")
self.rescan_btn.setMinimumWidth(160)
self.rescan_btn.clicked.connect(self.rescan_controllers)
top_row.addWidget(self.rescan_btn, alignment=Qt.AlignLeft)
# Add stretch to push logo to the right
top_row.addStretch()
# Logo - conditionally show controller or keyboard logo (right)
logo_file = resource_path("assets/controller-logo.svg") if self.controller_count > 0 else resource_path("assets/keyboard-logo.svg")
self.logo_widget = QSvgWidget(logo_file)
self.logo_widget.setFixedSize(80, 80)
top_row.addWidget(self.logo_widget, alignment=Qt.AlignRight)
layout.addLayout(top_row)
# Show last video name if available
if self.last_video_path and os.path.exists(self.last_video_path):
last_video_name = os.path.basename(self.last_video_path)
last_video_label = QLabel(f"LAST VIDEO: {last_video_name}")
last_video_label.setAlignment(Qt.AlignCenter)
last_video_label.setStyleSheet("color: #888; font-size: 11px; font-weight: bold;")
layout.addWidget(last_video_label)
# Bottom row: 3 buttons side by side
button_row = QHBoxLayout()
button_row.setSpacing(15)
# Open Last Video button
self.open_last_btn = QPushButton("Open Last Video")
self.open_last_btn.setObjectName("secondaryBtn")
self.open_last_btn.setMinimumWidth(120)
self.open_last_btn.clicked.connect(self.open_last_video)
button_row.addWidget(self.open_last_btn)
# Open Next Video button
self.open_next_btn = QPushButton("Open Next Video")
self.open_next_btn.setObjectName("primaryBtn")
self.open_next_btn.setMinimumWidth(120)
self.open_next_btn.clicked.connect(self.open_next_video)
button_row.addWidget(self.open_next_btn)
# Select In Files button
self.select_new_btn = QPushButton("Select File")
self.select_new_btn.setMinimumWidth(120)
self.select_new_btn.clicked.connect(self.select_new_video)
button_row.addWidget(self.select_new_btn)
layout.addLayout(button_row)
# Update button visibility based on last video availability
self.update_button_visibility()
def update_button_visibility(self):
"""Update button visibility based on whether last video exists"""
has_last_video = bool(self.last_video_path and os.path.exists(self.last_video_path))
# Show/hide buttons based on last video availability
self.open_last_btn.setVisible(has_last_video)
self.open_next_btn.setVisible(has_last_video)
def open_last_video(self):
self.selected_video_path = self.last_video_path
self.accept()
def open_next_video(self):
"""Open the next alphabetical video in the same folder as the last opened video."""
if not self.last_video_path or not os.path.exists(self.last_video_path):
QMessageBox.warning(self, "Error", "No last video path found or path does not exist.")
return
current_dir = os.path.dirname(self.last_video_path)
video_files = []
for f in os.listdir(current_dir):
if f.lower().endswith(('.mp4', '.avi', '.mov', '.mkv', '.wmv')):
video_files.append(os.path.join(current_dir, f))
video_files.sort() # Sort alphabetically
if not video_files:
QMessageBox.warning(self, "Error", "No video files found in the current directory.")
return
try:
current_video_index = video_files.index(self.last_video_path)
next_video_index = (current_video_index + 1) % len(video_files)
self.selected_video_path = video_files[next_video_index]
self.accept()
except ValueError:
QMessageBox.warning(self, "Error", "Last opened video not found in its directory. Please select a new video.")
return
def select_new_video(self):
file_path, _ = QFileDialog.getOpenFileName(
self, "Select Video File", "",
"Video Files (*.mp4 *.avi *.mov *.mkv *.wmv)"
)
if file_path:
self.selected_video_path = file_path
self.accept()
def rescan_controllers(self):
"""Rescan for controllers and update the logo and UI"""
# Reinitialize pygame joystick
pygame.joystick.quit()
pygame.joystick.init()
self.controller_count = pygame.joystick.get_count()
self.controller_name = ""
if self.controller_count > 0:
try:
joystick = pygame.joystick.Joystick(0)
joystick.init()
self.controller_name = joystick.get_name()
except:
self.controller_name = "Controller detected"
# Update logo based on new controller count
logo_file = resource_path("assets/controller-logo.svg") if self.controller_count > 0 else resource_path("assets/keyboard-logo.svg")
self.logo_widget.load(logo_file)
# Emit signal to notify main application that controllers were rescanned
self.controllers_rescanned.emit()
# Note: UI update would require recreating the dialog, which is complex
# For now, just update the internal state. The dialog would need to be closed and reopened to see changes.
class VideoAnnotator(QMainWindow):
"""Main application window"""
def __init__(self):
super().__init__()
self.video_path = ""
self.annotations = {} # frame_number -> list of behaviors
self.current_behavior = []
self.view_only_mode = False # Flag to track if in view-only mode
# Initialize shortcuts first
self.shortcuts = {}
self.undo_stack = [] # Stack for undoing annotations
self.settings = QSettings('VideoAnnotator', 'Settings') # Initialize general settings here
self.input_settings = QSettings('VideoAnnotator', 'InputSettings') # Initialize input settings here
self.gamification_settings = QSettings('VideoAnnotator', 'GamificationSettings') # Initialize gamification settings
self.behavior_settings = QSettings('VideoAnnotator', 'BehaviorSettings') # Initialize behavior settings
self.load_settings() # Load general settings including auto-save
self.load_shortcuts()
self.load_behavior_settings() # Load behavior settings
# Initialize GamificationManager
self.gamification_manager = GamificationManager(self)
self.gamification_manager.load_settings(self.gamification_settings)
# Initialize LiveScoreWidget BEFORE setup_ui
self.live_score_widget = LiveScoreWidget(self.gamification_manager, self) # Pass gamification_manager
self.live_score_widget.update_score_display(self.gamification_manager.total_score, 0)
self.gamification_manager.score_updated.connect(self.live_score_widget.update_score_display)
self.gamification_manager.combo_timer_progress.connect(self.live_score_widget.update_combo_progress)
self.setup_ui()
self.load_input_settings_on_startup() # Load input settings at startup
# Apply loaded settings to video player
self.video_player.multitrack_enabled = self.multitrack_enabled
self.video_player.update_label_key_mode(self.label_key_mode)
self.video_player.set_show_overlay_bars(self.show_frame_preview_bars)
self.video_player.update_input_settings(self.get_current_input_settings_for_startup()) # Apply input settings to video player
def setup_ui(self):
self.setWindowTitle("Ethoscore")
self.setGeometry(100, 100, 1200, 800)
# Apply global dark theme
self.setStyleSheet("""
QMainWindow {
background-color: #1a1a1a;
color: #e0e0e0;
}
QWidget#centralWidget {
background-color: #1a1a1a;
}
QMenuBar {
background-color: #252525;
color: #e0e0e0;
border-bottom: 1px solid #333;
}
QMenuBar::item:selected {
background-color: #3d3d3d;
}
QMenu {
background-color: #252525;
color: #e0e0e0;
border: 1px solid #333;
}
QMenu::item:selected {
background-color: #3d3d3d;
}
QStatusBar {
background-color: #1a1a1a;
color: #888;
border-top: 1px solid #333;
}
QSplitter::handle {
background-color: #252525;
}
QSplitter::handle:horizontal {
width: 4px;
}
QSplitter::handle:hover {
background-color: #3498db;
}
QLabel {
color: #e0e0e0;
}
QToolTip {
background-color: #252525;
color: white;
border: 1px solid #333;
}
""")
# Status bar for messages
self.statusBar().showMessage("Ready")
# Create menu bar
self.create_menu_bar()
central_widget = QWidget()
central_widget.setObjectName("centralWidget")
main_layout = QVBoxLayout(central_widget)
main_layout.setContentsMargins(0, 0, 0, 0)
main_layout.setSpacing(0)
# Create splitter for resizable panels
self.splitter = QSplitter(Qt.Horizontal)
self.splitter.setHandleWidth(4)
# Left panel - video and timeline
left_widget = QWidget()
from PySide6.QtWidgets import QSizePolicy
left_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
left_panel = QVBoxLayout(left_widget)
left_panel.setContentsMargins(10, 10, 5, 10)
left_panel.setSpacing(10)
# Video player
# Pass the timeline widget to the VideoPlayer so it can update the preview
self.timeline = TimelineWidget()
self.video_player = VideoPlayer(self.timeline)
self.video_player.frame_changed.connect(self.on_frame_changed)
self.video_player.label_toggled.connect(self.on_label_state_changed)
self.video_player.remove_labels.connect(self.remove_labels_from_current_frame)
self.video_player.check_label_removal.connect(self.on_check_label_removal)
# Add view-only mode flag to video player
self.video_player.view_only_mode = False
# Override video player's keyPressEvent to check view-only mode
original_keyPressEvent = self.video_player.keyPressEvent
def video_player_keyPressEvent(event):
"""Override video player's keyPressEvent to check view-only mode"""
key = event.key()
# Check if it's a behavior key (1-9, 0)
if key in [Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_4, Qt.Key_5, Qt.Key_6, Qt.Key_7, Qt.Key_8, Qt.Key_9, Qt.Key_0]:
if self.view_only_mode:
QMessageBox.information(self, "Preview Only Mode", "Cannot modify annotations in view-only mode.")