File indexing completed on 2024-05-12 04:58:41
0001 # ============================================================ 0002 # RunAction plugin for Falkon 0003 # Copyright (C) 2018 David Rosca <nowrep@gmail.com> 0004 # 0005 # This program is free software: you can redistribute it and/or modify 0006 # it under the terms of the GNU General Public License as published by 0007 # the Free Software Foundation, either version 3 of the License, or 0008 # (at your option) any later version. 0009 # 0010 # This program is distributed in the hope that it will be useful, 0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 # GNU General Public License for more details. 0014 # 0015 # You should have received a copy of the GNU General Public License 0016 # along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 # ============================================================ 0018 import os 0019 from PySide6 import QtCore, QtWidgets, QtUiTools 0020 from runaction.i18n import i18n 0021 0022 0023 class SettingsDialog(QtWidgets.QDialog): 0024 def __init__(self, manager, parent=None): 0025 super().__init__(parent) 0026 0027 self.manager = manager 0028 0029 file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "settings.ui")) 0030 file.open(QtCore.QFile.ReadOnly) 0031 self.ui = QtUiTools.QUiLoader().load(file, self) 0032 file.close() 0033 0034 layout = QtWidgets.QVBoxLayout(self) 0035 layout.addWidget(self.ui) 0036 0037 self.setMinimumSize(400, 250) 0038 self.setWindowTitle(i18n("Run Action Settings")) 0039 self.ui.label.setText(i18n("Available actions")) 0040 0041 for action in self.manager.actions: 0042 item = QtWidgets.QListWidgetItem(self.ui.listWidget) 0043 item.setText(action.title) 0044 item.setIcon(action.icon) 0045 item.setData(QtCore.Qt.UserRole, action.id) 0046 item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) 0047 item.setCheckState(QtCore.Qt.Unchecked if action.id in self.manager.disabledActions else QtCore.Qt.Checked) 0048 self.ui.listWidget.addItem(item) 0049 0050 self.ui.buttonBox.accepted.connect(self.accept) 0051 self.ui.buttonBox.rejected.connect(self.reject) 0052 0053 def accept(self): 0054 disabled = [] 0055 for i in range(self.ui.listWidget.count()): 0056 item = self.ui.listWidget.item(i) 0057 if item.checkState() == QtCore.Qt.Unchecked: 0058 disabled.append(item.data(QtCore.Qt.UserRole)) 0059 self.manager.disabledActions = disabled 0060 super().accept()