Skip to content

Commit bc411c9

Browse files
aded settings window and persistent memory
1 parent eb719b6 commit bc411c9

3 files changed

Lines changed: 95 additions & 1 deletion

File tree

osl_visualizer/ui/configdialog.ui

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>ConfigDialog</class>
4+
<widget class="QDialog" name="ConfigDialog">
5+
<property name="windowTitle">
6+
<string>Settings</string>
7+
</property>
8+
<layout class="QVBoxLayout" name="verticalLayout">
9+
<item>
10+
<widget class="QLabel" name="jumpBeforeLabel">
11+
<property name="text">
12+
<string>Jump Before Annotation (ms):</string>
13+
</property>
14+
</widget>
15+
</item>
16+
<item>
17+
<widget class="QSpinBox" name="jumpBeforeSpinBox">
18+
<property name="maximum">
19+
<number>60000</number>
20+
</property>
21+
<property name="singleStep">
22+
<number>100</number>
23+
</property>
24+
<property name="value">
25+
<number>5000</number>
26+
</property>
27+
</widget>
28+
</item>
29+
<item>
30+
<layout class="QHBoxLayout">
31+
<item>
32+
<widget class="QPushButton" name="okButton">
33+
<property name="text">
34+
<string>OK</string>
35+
</property>
36+
</widget>
37+
</item>
38+
<item>
39+
<widget class="QPushButton" name="cancelButton">
40+
<property name="text">
41+
<string>Cancel</string>
42+
</property>
43+
</widget>
44+
</item>
45+
</layout>
46+
</item>
47+
</layout>
48+
</widget>
49+
<resources/>
50+
<connections/>
51+
</ui>

osl_visualizer/ui/mainwindow.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
</property>
216216
<addaction name="actionLoad_OSL_Json"/>
217217
<addaction name="actionSave_OSL_JSON"/>
218+
<addaction name="actionOpen_Settings"/>
218219
</widget>
219220
<addaction name="menuFile"/>
220221
</widget>
@@ -229,6 +230,11 @@
229230
<string>Save OSL JSON</string>
230231
</property>
231232
</action>
233+
<action name="actionOpen_Settings">
234+
<property name="text">
235+
<string>Open Settings</string>
236+
</property>
237+
</action>
232238
</widget>
233239
<resources/>
234240
<connections/>

osl_visualizer/viewer.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
format='%(asctime)s %(levelname)s:%(message)s',
2121
handlers=[logging.StreamHandler()]
2222
)
23+
from PyQt6 import uic
24+
from PyQt6.QtWidgets import QDialog
25+
from PyQt6.QtCore import QSettings
26+
27+
class ConfigDialog(QDialog):
28+
def __init__(self, parent=None, current_jump_before=5000):
29+
super().__init__(parent)
30+
# uic.loadUi("ui/configdialog.ui", self)
31+
uic.loadUi(os.path.join(os.path.dirname(__file__), "ui/configdialog.ui"), self)
32+
33+
self.jumpBeforeSpinBox.setValue(current_jump_before)
34+
self.okButton.clicked.connect(self.accept)
35+
self.cancelButton.clicked.connect(self.reject)
36+
37+
def get_jump_before(self):
38+
return self.jumpBeforeSpinBox.value()
2339

2440
class DatasetViewer(QMainWindow):
2541
def __init__(self):
@@ -43,6 +59,7 @@ def __init__(self):
4359
self.available_labels = []
4460
self.current_video_info = None
4561
self._updating_selection = False
62+
self.jump_before_ms = 5000
4663

4764
self.player = QMediaPlayer(self)
4865
self.audio_output = QAudioOutput(self)
@@ -71,6 +88,10 @@ def __init__(self):
7188
self.forwardFrameButton.clicked.connect(lambda: self.step_frame(1))
7289
self.addAnnotationButton.clicked.connect(self.add_annotation_at_current_time)
7390
self.removeAnnotationButton.clicked.connect(self.remove_selected_annotation)
91+
self.actionOpen_Settings.triggered.connect(self.show_config_dialog)
92+
93+
94+
self.load_settings()
7495

7596

7697

@@ -169,7 +190,7 @@ def select_annotation(self, item):
169190
else:
170191
self.metadataTextEdit.setText("")
171192

172-
jump_to = max(0, ann["position"] - 5000) # 5000 ms = 5 seconds
193+
jump_to = max(0, ann["position"] - self.jump_before_ms) # 5000 ms = 5 seconds
173194
self.player.setPosition(jump_to)
174195
self.player.play()
175196
self.playButton.setText("Pause")
@@ -395,3 +416,19 @@ def set_annotation_time_to_video(self):
395416

396417
logging.info(f"Annotation updated and resorted to {current_time}ms (index {new_index})")
397418

419+
def show_config_dialog(self):
420+
dialog = ConfigDialog(self, self.jump_before_ms)
421+
if dialog.exec():
422+
self.jump_before_ms = dialog.get_jump_before()
423+
self.save_settings() # Persist!
424+
425+
426+
def save_settings(self):
427+
settings = QSettings("OSLActionSpotting", "DatasetAnnotationTool")
428+
settings.setValue("jump_before_ms", self.jump_before_ms)
429+
430+
431+
def load_settings(self):
432+
settings = QSettings("OSLActionSpotting", "DatasetAnnotationTool")
433+
# get returns QVariant; int(None) raises TypeError, so handle missing gracefully
434+
self.jump_before_ms = settings.value("jump_before_ms", 5000)

0 commit comments

Comments
 (0)