Refactor signal disconnection logic for improved safety and readability
This commit is contained in:
@@ -2589,12 +2589,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
for widget in QtWidgets.QApplication.allWidgets():
|
for widget in QtWidgets.QApplication.allWidgets():
|
||||||
if hasattr(widget, 'img_preview') and hasattr(widget.img_preview, 'clear'):
|
if hasattr(widget, 'img_preview') and hasattr(widget.img_preview, 'clear'):
|
||||||
widget.img_preview.clear()
|
widget.img_preview.clear()
|
||||||
# Disconnect any remaining signal connections
|
|
||||||
if hasattr(widget, 'disconnect'):
|
|
||||||
try:
|
|
||||||
widget.disconnect()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -4363,10 +4357,16 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
# Update global delay controls
|
# Update global delay controls
|
||||||
if self.current_scenario:
|
if self.current_scenario:
|
||||||
# Temporarily disconnect signals to prevent triggering auto-save during loading
|
# Temporarily disconnect signals to prevent triggering auto-save during loading
|
||||||
self.before_action_spinbox.valueChanged.disconnect()
|
for sig in (
|
||||||
self.after_action_spinbox.valueChanged.disconnect()
|
self.before_action_spinbox.valueChanged,
|
||||||
self.before_step_spinbox.valueChanged.disconnect()
|
self.after_action_spinbox.valueChanged,
|
||||||
self.after_step_spinbox.valueChanged.disconnect()
|
self.before_step_spinbox.valueChanged,
|
||||||
|
self.after_step_spinbox.valueChanged,
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
sig.disconnect()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# Load global delay settings
|
# Load global delay settings
|
||||||
global_delay = self.current_scenario.global_delay
|
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.before_step_spinbox.valueChanged.connect(self._on_global_delay_changed)
|
||||||
self.after_step_spinbox.valueChanged.connect(self._on_global_delay_changed)
|
self.after_step_spinbox.valueChanged.connect(self._on_global_delay_changed)
|
||||||
else:
|
else:
|
||||||
# Reset to default values when no scenario is selected
|
# Reset to default values when no scenario is selected (safe disconnects)
|
||||||
self.before_action_spinbox.valueChanged.disconnect()
|
for sig in (
|
||||||
self.after_action_spinbox.valueChanged.disconnect()
|
self.before_action_spinbox.valueChanged,
|
||||||
self.before_step_spinbox.valueChanged.disconnect()
|
self.after_action_spinbox.valueChanged,
|
||||||
self.after_step_spinbox.valueChanged.disconnect()
|
self.before_step_spinbox.valueChanged,
|
||||||
|
self.after_step_spinbox.valueChanged,
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
sig.disconnect()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
self.before_action_spinbox.setValue(0.0)
|
self.before_action_spinbox.setValue(0.0)
|
||||||
self.after_action_spinbox.setValue(0.0)
|
self.after_action_spinbox.setValue(0.0)
|
||||||
self.before_step_spinbox.setValue(0.0)
|
self.before_step_spinbox.setValue(0.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user