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
|
# SPDX-License-Identifier: LGPL-2.1-only
from PyQt6 import QtWidgets
import setools
from .checkboxset import CheckboxSetWidget
DEFAULT_CHECKED = ("range_transition",)
__all__ = ('MLSRuleType',)
class MLSRuleType(CheckboxSetWidget):
"""
Criteria selection widget presenting type enforcement rule types as a series
of checkboxes. The selected checkboxes are then merged into a single Python
list consisting of object names (TE 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.MLSRuletype),
num_cols=1, 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 logging
import pprint
import warnings
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s|%(levelname)s|%(name)s|%(message)s')
warnings.simplefilter("default")
q = setools.MLSRuleQuery(setools.SELinuxPolicy())
app = QtWidgets.QApplication(sys.argv)
mw = QtWidgets.QMainWindow()
w = MLSRuleType("Test MLS 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)
print("range_trans enabled?", w.criteria["range_transition"].isEnabled())
sys.exit(rc)
|