xfstestsdb/xfstestsdb/gtk/view.py

105 lines
3.8 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""A view widget used to display our TestCaseModel."""
from gi.repository import GObject
from gi.repository import Gtk
from .model import TestCaseList
from .model import TestCaseFilter
from . import button
from . import row
class FilterButtons(Gtk.Box):
"""Buttons for controlling the TestCaseFilter."""
passed = GObject.Property(type=bool, default=False)
skipped = GObject.Property(type=bool, default=False)
failure = GObject.Property(type=bool, default=True)
def __init__(self):
"""Initialize the FilterButtons."""
super().__init__()
self.add_css_class("linked")
self._passed = button.StatusToggle("test-pass", "passed")
self._skipped = button.StatusToggle("test-skip", "skipped")
self._failure = button.StatusToggle("test-fail", "failure",
active=True)
self._passed.bind_property("active", self, "passed")
self._skipped.bind_property("active", self, "skipped")
self._failure.bind_property("active", self, "failure")
self.append(self._passed)
self.append(self._skipped)
self.append(self._failure)
class TestCaseView(Gtk.ScrolledWindow):
"""Displays our TestCaseList model to the user."""
filterbuttons = GObject.Property(type=FilterButtons)
def __init__(self):
"""Initialize a TestCaseView."""
super().__init__(child=Gtk.ColumnView(model=Gtk.NoSelection(),
show_row_separators=True,
show_column_separators=True,
hexpand=True, vexpand=True),
filterbuttons=FilterButtons())
self._testcase = Gtk.ColumnViewColumn(title="testcase",
factory=row.LabelFactory("name"))
self._testfilter = TestCaseFilter()
self._filtermodel = Gtk.FilterListModel(filter=self._testfilter)
for prop in ["passed", "skipped", "failure"]:
self.filterbuttons.bind_property(prop, self._testfilter, prop)
self.props.child.get_model().set_model(self._filtermodel)
self.add_css_class("card")
def __xunit_column(self, xunit: str) -> None:
return Gtk.ColumnViewColumn(title=xunit, expand=True,
factory=row.ResultFactory(xunit))
def make_buttons(self) -> FilterButtons:
"""Make a new FilterButtons instance connected to this View."""
return FilterButtons()
@GObject.Property(type=TestCaseList)
def model(self) -> TestCaseList:
"""Get the TestCaseList shown by the View."""
return self._filtermodel.props.model
@model.setter
def model(self, new: TestCaseList) -> None:
for col in [col for col in self.props.child.get_columns()]:
self.props.child.remove_column(col)
self._filtermodel.props.model = new
if new is not None:
self.props.child.append_column(self._testcase)
for xunit in new.get_xunits():
self.props.child.append_column(self.__xunit_column(xunit))
class XfstestsView(Gtk.Box):
"""A widget to display the results of an Xfstests runs."""
model = GObject.Property(type=TestCaseList)
def __init__(self):
"""Initialize an XfstestsView."""
super().__init__(orientation=Gtk.Orientation.VERTICAL)
self._testcaseview = TestCaseView()
self.bind_property("model", self._testcaseview, "model")
self.append(self._testcaseview)
@GObject.Property(type=FilterButtons)
def filterbuttons(self) -> FilterButtons:
"""Get the FilterButtons attached to the child TestCaseView."""
return self._testcaseview.filterbuttons