Restore image settings on cancel; live sync

Save original image_width/image_offset when opening Settings and restore them if the dialog is cancelled. Add valueChanged handlers to immediately update state.image_width and state.image_offset, enforce an image width maximum of 2500, and refactor Save wiring to a dedicated handler that calls save_settings(dialog.accept, ...). Connect dialog.finished to restore temp values on rejection and clean up dialog layout/logic.
This commit is contained in:
Vxrtrauter
2026-04-04 05:36:16 +02:00
parent fda45efcb5
commit a3ff23147f
+17 -3
View File
@@ -25,6 +25,8 @@ SVG_FOLDER = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path
def settings_dialog(self): def settings_dialog(self):
temp_image_width = state.image_width
temp_image_offset = state.image_offset
def create_widget(widget_type, label_text, **kwargs): def create_widget(widget_type, label_text, **kwargs):
container = QWidget() container = QWidget()
@@ -149,12 +151,15 @@ def settings_dialog(self):
# Image Width SpinBox # Image Width SpinBox
image_width_container, image_width = create_widget(QSpinBox, "Image Width: ", width=180, height=30) image_width_container, image_width = create_widget(QSpinBox, "Image Width: ", width=180, height=30)
image_width.setMinimum(0) image_width.setMinimum(0)
image_width.setMaximum(2500)
image_width.setValue(state.image_width) image_width.setValue(state.image_width)
image_width.valueChanged.connect(lambda val: setattr(state, 'image_width', val))
# Image Offset SpinBox # Image Offset SpinBox
image_offset_container, image_offset = create_widget(QSpinBox, "Corner Image Offset: ", width=180, height=30) image_offset_container, image_offset = create_widget(QSpinBox, "Corner Image Offset: ", width=180, height=30)
image_offset.setMinimum(0) image_offset.setMinimum(0)
image_offset.setValue(state.image_offset) image_offset.setValue(state.image_offset)
image_offset.valueChanged.connect(lambda val: setattr(state, 'image_offset', val))
# Speed Limiting # Speed Limiting
down_speed_limit_container, down_speed_limit = create_widget(QSpinBox, "Max Download Speed (KiB, 0 for unlimited): ", width=180, height=30) down_speed_limit_container, down_speed_limit = create_widget(QSpinBox, "Max Download Speed (KiB, 0 for unlimited): ", width=180, height=30)
@@ -204,8 +209,11 @@ def settings_dialog(self):
save_btn = QPushButton("Save") save_btn = QPushButton("Save")
cancel_btn = QPushButton("Cancel") cancel_btn = QPushButton("Cancel")
save_btn.clicked.connect(lambda: save_settings( save_btn.clicked.connect(lambda: handle_save())
close_settings,
def handle_save():
save_settings(
dialog.accept,
api_url.text(), api_url.text(),
download_path.text(), download_path.text(),
down_speed_limit.value(), down_speed_limit.value(),
@@ -217,7 +225,7 @@ def settings_dialog(self):
interface_select.currentText(), interface_select.currentText(),
image_width.value(), image_width.value(),
image_offset.value() image_offset.value()
)) )
cancel_btn.clicked.connect(dialog.reject) cancel_btn.clicked.connect(dialog.reject)
layout.addWidget(cancel_btn) layout.addWidget(cancel_btn)
@@ -233,4 +241,10 @@ def settings_dialog(self):
dialog_layout.addWidget(tabs) dialog_layout.addWidget(tabs)
dialog_layout.addLayout(layout) dialog_layout.addLayout(layout)
def on_dialog_finished(result):
if result == QtWidgets.QDialog.DialogCode.Rejected:
state.image_width = temp_image_width
state.image_offset = temp_image_offset
dialog.finished.connect(on_dialog_finished)
dialog.exec() dialog.exec()