Skip to content

Commit 40b9dcd

Browse files
committed
feat: possibility of disable electrode and its settings
1 parent f0e08fb commit 40b9dcd

3 files changed

Lines changed: 127 additions & 28 deletions

File tree

src/clinical_dbs_annotator/views/step1_view.py

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def __init__(self, parent_style):
8282

8383
self.left_canvas = ElectrodeCanvas()
8484
self.right_canvas = ElectrodeCanvas()
85+
86+
# Electrode disable state
87+
self.left_electrode_enabled = True
88+
self.right_electrode_enabled = True
8589
self.left_canvas.validation_callback = self._on_left_canvas_validation
8690
self.right_canvas.validation_callback = self._on_right_canvas_validation
8791
self._left_selection_valid = True
@@ -238,8 +242,8 @@ def _create_settings_group(self) -> QGroupBox:
238242
amp_limits = STIMULATION_LIMITS["amplitude"]
239243
pw_limits = STIMULATION_LIMITS["pulse_width"]
240244

241-
left_group = QGroupBox("Left")
242-
left_group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
245+
self.left_group = QGroupBox("Left")
246+
self.left_group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
243247
left_group_layout = QVBoxLayout()
244248

245249
freq_row = QHBoxLayout()
@@ -313,10 +317,10 @@ def _create_settings_group(self) -> QGroupBox:
313317
left_config_layout.addWidget(self.left_config_label)
314318
left_group_layout.addWidget(self.left_config_box)
315319
left_group_layout.addStretch(1)
316-
left_group.setLayout(left_group_layout)
320+
self.left_group.setLayout(left_group_layout)
317321

318-
right_group = QGroupBox("Right")
319-
right_group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
322+
self.right_group = QGroupBox("Right")
323+
self.right_group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
320324
right_group_layout = QVBoxLayout()
321325

322326
freq_row = QHBoxLayout()
@@ -390,12 +394,12 @@ def _create_settings_group(self) -> QGroupBox:
390394
right_config_layout.addWidget(self.right_config_label)
391395
right_group_layout.addWidget(self.right_config_box)
392396
right_group_layout.addStretch(1)
393-
right_group.setLayout(right_group_layout)
397+
self.right_group.setLayout(right_group_layout)
394398

395399
sidebar_layout.addWidget(model_group)
396400
sidebar_layout.addWidget(group_row)
397-
sidebar_layout.addWidget(left_group)
398-
sidebar_layout.addWidget(right_group)
401+
sidebar_layout.addWidget(self.left_group)
402+
sidebar_layout.addWidget(self.right_group)
399403
sidebar_layout.addStretch(1)
400404

401405
# Wrap sidebar in a scroll area so it scrolls when rows overflow
@@ -427,18 +431,24 @@ def _create_settings_group(self) -> QGroupBox:
427431
electrodes_layout = QVBoxLayout()
428432
electrodes_row = QHBoxLayout()
429433

430-
left_canvas_group = QGroupBox("Left electrode")
434+
self.left_canvas_group = QGroupBox("Left electrode")
435+
self.left_canvas_group.setCheckable(True)
436+
self.left_canvas_group.setChecked(True)
437+
self.left_canvas_group.toggled.connect(lambda checked: self._toggle_electrode('left', checked))
431438
left_canvas_layout = QVBoxLayout()
432439
left_canvas_layout.addWidget(self.left_canvas, 1)
433-
left_canvas_group.setLayout(left_canvas_layout)
440+
self.left_canvas_group.setLayout(left_canvas_layout)
434441

435-
right_canvas_group = QGroupBox("Right electrode")
442+
self.right_canvas_group = QGroupBox("Right electrode")
443+
self.right_canvas_group.setCheckable(True)
444+
self.right_canvas_group.setChecked(True)
445+
self.right_canvas_group.toggled.connect(lambda checked: self._toggle_electrode('right', checked))
436446
right_canvas_layout = QVBoxLayout()
437447
right_canvas_layout.addWidget(self.right_canvas, 1)
438-
right_canvas_group.setLayout(right_canvas_layout)
448+
self.right_canvas_group.setLayout(right_canvas_layout)
439449

440-
electrodes_row.addWidget(left_canvas_group, 1)
441-
electrodes_row.addWidget(right_canvas_group, 1)
450+
electrodes_row.addWidget(self.left_canvas_group, 1)
451+
electrodes_row.addWidget(self.right_canvas_group, 1)
442452

443453
electrodes_layout.addLayout(electrodes_row)
444454
electrodes_layout.addLayout(self._create_electrode_legend_layout())
@@ -878,6 +888,51 @@ def _create_clinical_scales_group(self) -> QGroupBox:
878888

879889
return gb_clinical
880890

891+
def _toggle_electrode(self, side: str, checked: bool) -> None:
892+
"""Toggle electrode enable/disable state for canvas and settings."""
893+
from PySide6.QtWidgets import QGraphicsOpacityEffect
894+
895+
if side == 'left':
896+
self.left_electrode_enabled = checked
897+
self.left_group.setEnabled(checked)
898+
self.left_canvas.setEnabled(checked)
899+
# Apply opacity to visually dim canvas and settings
900+
for widget in (self.left_canvas, self.left_group):
901+
if not checked:
902+
effect = QGraphicsOpacityEffect(widget)
903+
effect.setOpacity(0.3)
904+
widget.setGraphicsEffect(effect)
905+
else:
906+
widget.setGraphicsEffect(None)
907+
elif side == 'right':
908+
self.right_electrode_enabled = checked
909+
self.right_group.setEnabled(checked)
910+
self.right_canvas.setEnabled(checked)
911+
for widget in (self.right_canvas, self.right_group):
912+
if not checked:
913+
effect = QGraphicsOpacityEffect(widget)
914+
effect.setOpacity(0.3)
915+
widget.setGraphicsEffect(effect)
916+
else:
917+
widget.setGraphicsEffect(None)
918+
919+
def _apply_preset_scales(self, scales: list[str]) -> None:
920+
"""Apply a list of preset scales to the clinical scales container."""
921+
# Remove any existing stretches from container
922+
while self.clinical_scales_container.count():
923+
item = self.clinical_scales_container.takeAt(0)
924+
if item.spacerItem():
925+
# Just remove the stretch, no widget to delete
926+
continue
927+
elif item.widget():
928+
item.widget().deleteLater()
929+
930+
for scale_name in scales:
931+
self._add_clinical_scale_row(scale_name, with_minus=True, on_remove=self.on_remove_callback)
932+
933+
self._add_clinical_scale_row("", with_plus=True, on_add=self.on_add_callback)
934+
self.clinical_scales_container.addStretch()
935+
881936
def _create_notes_group(self) -> QGroupBox:
882937
"""Create the initial notes group box."""
883938
gb_notes = QGroupBox("Initial notes")

src/clinical_dbs_annotator/views/step3_view.py

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def __init__(self, parent_style):
6868

6969
self.left_canvas = ElectrodeCanvas()
7070
self.right_canvas = ElectrodeCanvas()
71+
72+
# Electrode disable state
73+
self.left_electrode_enabled = True
74+
self.right_electrode_enabled = True
7175
self.left_canvas.validation_callback = self._on_left_canvas_validation
7276
self.right_canvas.validation_callback = self._on_right_canvas_validation
7377
self._left_selection_valid = True
@@ -114,18 +118,24 @@ def _setup_ui(self) -> None:
114118
electrodes_layout = QVBoxLayout()
115119
electrodes_row = QHBoxLayout()
116120

117-
left_canvas_group = QGroupBox("Left electrode")
121+
self.left_canvas_group = QGroupBox("Left electrode")
122+
self.left_canvas_group.setCheckable(True)
123+
self.left_canvas_group.setChecked(True)
124+
self.left_canvas_group.toggled.connect(lambda checked: self._toggle_electrode('left', checked))
118125
left_canvas_layout = QVBoxLayout()
119126
left_canvas_layout.addWidget(self.left_canvas, 1)
120-
left_canvas_group.setLayout(left_canvas_layout)
127+
self.left_canvas_group.setLayout(left_canvas_layout)
121128

122-
right_canvas_group = QGroupBox("Right electrode")
129+
self.right_canvas_group = QGroupBox("Right electrode")
130+
self.right_canvas_group.setCheckable(True)
131+
self.right_canvas_group.setChecked(True)
132+
self.right_canvas_group.toggled.connect(lambda checked: self._toggle_electrode('right', checked))
123133
right_canvas_layout = QVBoxLayout()
124134
right_canvas_layout.addWidget(self.right_canvas, 1)
125-
right_canvas_group.setLayout(right_canvas_layout)
135+
self.right_canvas_group.setLayout(right_canvas_layout)
126136

127-
electrodes_row.addWidget(left_canvas_group, 1)
128-
electrodes_row.addWidget(right_canvas_group, 1)
137+
electrodes_row.addWidget(self.left_canvas_group, 1)
138+
electrodes_row.addWidget(self.right_canvas_group, 1)
129139

130140
electrodes_layout.addLayout(electrodes_row)
131141
electrodes_layout.addLayout(self._create_electrode_legend_layout())
@@ -206,8 +216,8 @@ def _create_stimulation_params_group(self) -> QWidget:
206216
amp_limits = STIMULATION_LIMITS["amplitude"]
207217
pw_limits = STIMULATION_LIMITS["pulse_width"]
208218

209-
left_group = QGroupBox("Left")
210-
left_group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
219+
self.left_group = QGroupBox("Left")
220+
self.left_group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
211221
left_group_layout = QVBoxLayout()
212222

213223
freq_row = QHBoxLayout()
@@ -281,10 +291,10 @@ def _create_stimulation_params_group(self) -> QWidget:
281291
left_config_layout.addWidget(self.left_config_label)
282292
left_group_layout.addWidget(self.left_config_box)
283293
left_group_layout.addStretch(1)
284-
left_group.setLayout(left_group_layout)
294+
self.left_group.setLayout(left_group_layout)
285295

286-
right_group = QGroupBox("Right")
287-
right_group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
296+
self.right_group = QGroupBox("Right")
297+
self.right_group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
288298
right_group_layout = QVBoxLayout()
289299

290300
freq_row = QHBoxLayout()
@@ -358,11 +368,11 @@ def _create_stimulation_params_group(self) -> QWidget:
358368
right_config_layout.addWidget(self.right_config_label)
359369
right_group_layout.addWidget(self.right_config_box)
360370
right_group_layout.addStretch(1)
361-
right_group.setLayout(right_group_layout)
371+
self.right_group.setLayout(right_group_layout)
362372

363373
sidebar_layout.addWidget(group_row)
364-
sidebar_layout.addWidget(left_group)
365-
sidebar_layout.addWidget(right_group)
374+
sidebar_layout.addWidget(self.left_group)
375+
sidebar_layout.addWidget(self.right_group)
366376
sidebar_layout.addStretch(1)
367377

368378
return container
@@ -616,6 +626,34 @@ def _create_session_scales_group(self) -> QGroupBox:
616626

617627
return gb_scales
618628

629+
def _toggle_electrode(self, side: str, checked: bool) -> None:
630+
"""Toggle electrode enable/disable state for canvas and settings."""
631+
from PySide6.QtWidgets import QGraphicsOpacityEffect
632+
633+
if side == 'left':
634+
self.left_electrode_enabled = checked
635+
self.left_group.setEnabled(checked)
636+
self.left_canvas.setEnabled(checked)
637+
# Apply opacity to visually dim canvas and settings
638+
for widget in (self.left_canvas, self.left_group):
639+
if not checked:
640+
effect = QGraphicsOpacityEffect(widget)
641+
effect.setOpacity(0.3)
642+
widget.setGraphicsEffect(effect)
643+
else:
644+
widget.setGraphicsEffect(None)
645+
elif side == 'right':
646+
self.right_electrode_enabled = checked
647+
self.right_group.setEnabled(checked)
648+
self.right_canvas.setEnabled(checked)
649+
for widget in (self.right_canvas, self.right_group):
650+
if not checked:
651+
effect = QGraphicsOpacityEffect(widget)
652+
effect.setOpacity(0.3)
653+
widget.setGraphicsEffect(effect)
654+
else:
655+
widget.setGraphicsEffect(None)
656+
619657
def _create_session_notes_group(self) -> QGroupBox:
620658
gb_notes = QGroupBox("Session notes")
621659
gb_notes.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

styles/light_theme.qss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ QGroupBox::title {
312312
background-color: #ffffff;
313313
}
314314

315+
QGroupBox::indicator:unchecked {
316+
border: 1px solid #475569;
317+
border-radius: 2px;
318+
margin-top: 2px;
319+
}
320+
315321
/* Horizontal Lines */
316322
QFrame[frameShape="4"] {
317323
background: #cbd5e1;

0 commit comments

Comments
 (0)