mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +02:00
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:
@@ -25,6 +25,8 @@ SVG_FOLDER = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path
|
||||
|
||||
|
||||
def settings_dialog(self):
|
||||
temp_image_width = state.image_width
|
||||
temp_image_offset = state.image_offset
|
||||
|
||||
def create_widget(widget_type, label_text, **kwargs):
|
||||
container = QWidget()
|
||||
@@ -149,12 +151,15 @@ def settings_dialog(self):
|
||||
# Image Width SpinBox
|
||||
image_width_container, image_width = create_widget(QSpinBox, "Image Width: ", width=180, height=30)
|
||||
image_width.setMinimum(0)
|
||||
image_width.setMaximum(2500)
|
||||
image_width.setValue(state.image_width)
|
||||
image_width.valueChanged.connect(lambda val: setattr(state, 'image_width', val))
|
||||
|
||||
# Image Offset SpinBox
|
||||
image_offset_container, image_offset = create_widget(QSpinBox, "Corner Image Offset: ", width=180, height=30)
|
||||
image_offset.setMinimum(0)
|
||||
image_offset.setValue(state.image_offset)
|
||||
image_offset.valueChanged.connect(lambda val: setattr(state, 'image_offset', val))
|
||||
|
||||
# Speed Limiting
|
||||
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")
|
||||
cancel_btn = QPushButton("Cancel")
|
||||
save_btn.clicked.connect(lambda: save_settings(
|
||||
close_settings,
|
||||
save_btn.clicked.connect(lambda: handle_save())
|
||||
|
||||
def handle_save():
|
||||
save_settings(
|
||||
dialog.accept,
|
||||
api_url.text(),
|
||||
download_path.text(),
|
||||
down_speed_limit.value(),
|
||||
@@ -217,7 +225,7 @@ def settings_dialog(self):
|
||||
interface_select.currentText(),
|
||||
image_width.value(),
|
||||
image_offset.value()
|
||||
))
|
||||
)
|
||||
|
||||
cancel_btn.clicked.connect(dialog.reject)
|
||||
layout.addWidget(cancel_btn)
|
||||
@@ -233,4 +241,10 @@ def settings_dialog(self):
|
||||
dialog_layout.addWidget(tabs)
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user