1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# SPDX-License-Identifier: LGPL-2.1-only
import typing
from PyQt6 import QtWidgets
import setools
from .checkboxset import CheckboxSetWidget
# Checked by default:
DEFAULT_CHECKED: typing.Final[tuple[str, ...]] = ("default_user", "default_role",
"default_type", "default_range")
__all__ = ('DefaultRuleType',)
class DefaultRuleType(CheckboxSetWidget):
"""
Criteria selection widget presenting default_* rule types as a series
of checkboxes. The selected checkboxes are then merged into a single Python
list consisting of object names (default ruletypes) and stored in the query's
specified attribute.
"""
def __init__(self, title: str, query: setools.PolicyQuery, attrname: str = "ruletype",
parent: QtWidgets.QWidget | None = None) -> None:
super().__init__(title, query, attrname, (rt.name for rt in setools.DefaultRuletype),
num_cols=2, parent=parent)
for name, widget in self.criteria.items():
widget.setChecked(name in DEFAULT_CHECKED)
widget.setToolTip(f"Match {name} rules.")
widget.setWhatsThis(
f"""
<p><b>Match {name} rules</b></p>
<p>If a rule has the {name} rule type, it will be returned.</p>
""")
if __name__ == '__main__':
import sys
import warnings
import pprint
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s|%(levelname)s|%(name)s|%(message)s')
warnings.simplefilter("default")
q = setools.DefaultQuery(setools.SELinuxPolicy())
app = QtWidgets.QApplication(sys.argv)
mw = QtWidgets.QMainWindow()
w = DefaultRuleType("Test default ruletypes", q, parent=mw)
w.setToolTip("test tooltip")
w.setWhatsThis("test what's this")
mw.setCentralWidget(w)
mw.resize(w.size())
whatsthis = QtWidgets.QWhatsThis.createAction(mw)
mw.menuBar().addAction(whatsthis) # type: ignore[union-attr]
mw.show()
rc = app.exec()
print("Ruletypes set in query:")
pprint.pprint(q.ruletype)
sys.exit(rc)
|