Refactor signal disconnection logic for improved safety and readability

This commit is contained in:
2025-08-18 10:09:14 +02:00
parent e38bf3a851
commit 8daa1476b2
+21 -15
View File
@@ -2589,12 +2589,6 @@ class MainWindow(QtWidgets.QMainWindow):
for widget in QtWidgets.QApplication.allWidgets():
if hasattr(widget, 'img_preview') and hasattr(widget.img_preview, 'clear'):
widget.img_preview.clear()
# Disconnect any remaining signal connections
if hasattr(widget, 'disconnect'):
try:
widget.disconnect()
except:
pass
except:
pass
@@ -4363,10 +4357,16 @@ class MainWindow(QtWidgets.QMainWindow):
# Update global delay controls
if self.current_scenario:
# Temporarily disconnect signals to prevent triggering auto-save during loading
self.before_action_spinbox.valueChanged.disconnect()
self.after_action_spinbox.valueChanged.disconnect()
self.before_step_spinbox.valueChanged.disconnect()
self.after_step_spinbox.valueChanged.disconnect()
for sig in (
self.before_action_spinbox.valueChanged,
self.after_action_spinbox.valueChanged,
self.before_step_spinbox.valueChanged,
self.after_step_spinbox.valueChanged,
):
try:
sig.disconnect()
except Exception:
pass
# Load global delay settings
global_delay = self.current_scenario.global_delay
@@ -4381,11 +4381,17 @@ class MainWindow(QtWidgets.QMainWindow):
self.before_step_spinbox.valueChanged.connect(self._on_global_delay_changed)
self.after_step_spinbox.valueChanged.connect(self._on_global_delay_changed)
else:
# Reset to default values when no scenario is selected
self.before_action_spinbox.valueChanged.disconnect()
self.after_action_spinbox.valueChanged.disconnect()
self.before_step_spinbox.valueChanged.disconnect()
self.after_step_spinbox.valueChanged.disconnect()
# Reset to default values when no scenario is selected (safe disconnects)
for sig in (
self.before_action_spinbox.valueChanged,
self.after_action_spinbox.valueChanged,
self.before_step_spinbox.valueChanged,
self.after_step_spinbox.valueChanged,
):
try:
sig.disconnect()
except Exception:
pass
self.before_action_spinbox.setValue(0.0)
self.after_action_spinbox.setValue(0.0)
self.before_step_spinbox.setValue(0.0)