From 268a5a70a26d34c6710ee2511173ea612a8ef603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Mon, 8 Jul 2024 15:56:19 -0500 Subject: [PATCH] [ux] Disable used items in 'Add setting' dialog instead of removing them; update main button depending on existing selection --- pg_service_parser/gui/dlg_service_settings.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pg_service_parser/gui/dlg_service_settings.py b/pg_service_parser/gui/dlg_service_settings.py index e74d591..077c782 100644 --- a/pg_service_parser/gui/dlg_service_settings.py +++ b/pg_service_parser/gui/dlg_service_settings.py @@ -1,5 +1,5 @@ -from qgis.PyQt.QtCore import pyqtSlot -from qgis.PyQt.QtWidgets import QDialog +from qgis.PyQt.QtCore import Qt, pyqtSlot +from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem from pg_service_parser.conf.service_settings import SERVICE_SETTINGS from pg_service_parser.utils import get_ui_class @@ -9,16 +9,31 @@ class ServiceSettingsDialog(QDialog, DIALOG_UI): - def __init__(self, parent, settings_to_hide: list[str]): + def __init__(self, parent, used_settings: list[str]): QDialog.__init__(self, parent) self.setupUi(self) + self.lstSettings.itemSelectionChanged.connect(self.__selection_changed) self.buttonBox.accepted.connect(self.__accepted) - settings = set(SERVICE_SETTINGS.keys()) - set(settings_to_hide) - self.lstSettings.addItems(settings) + self.__selection_changed() # Initialize button status + + # Load data + for setting in SERVICE_SETTINGS.keys(): + item = QListWidgetItem(setting) + if setting in used_settings: + item.setFlags(item.flags() & ~Qt.ItemIsSelectable & ~Qt.ItemIsEnabled) + + self.lstSettings.addItem(item) + self.settings_to_add = [] + @pyqtSlot() + def __selection_changed(self): + self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( + bool(self.lstSettings.selectedItems()) + ) + @pyqtSlot() def __accepted(self): self.settings_to_add = [item.text() for item in self.lstSettings.selectedItems()]