#!/usr/bin/python from . import common from gi.repository import GObject from gi.repository import Gio from gi.repository import Gtk PROPERTIES = [ "PLATFORM", "TIMESTAMP", "FSTYP", "MOUNT_OPTIONS", "CHECK_OPTIONS", "TEST_DIR", "TEST_DEV", "SCRATCH_DEV", "SCRATCH_MNT" ] #, "RESULTS" ] class Property(GObject.GObject): def __init__(self, key, value): GObject.GObject.__init__(self) self.key = key self.value = value class NotRun(GObject.GObject): def __init__(self, message): GObject.GObject.__init__(self) self.message = message def __lt__(self, rhs): return self.message < rhs.message class Results(Property): def __init__(self, properties): time = properties["TIME"] passed = properties["PASSED"] failed = properties["FAILURES"] skipped = properties["SKIPPED"] total = int(passed) + int(failed) + int(skipped) Property.__init__(self, "RESULTS", f"Ran {total} tests in {time} seconds: " \ f"{passed} passed, {failed} failed, {skipped} skipped") class Model(GObject.GObject, Gio.ListModel): def __init__(self, properties): GObject.GObject.__init__(self) self.properties = [ Property(p, properties[p]) for p in PROPERTIES ] self.properties.append(Results(properties)) def do_get_item_type(self): return GObject.TYPE_PYOBJECT def do_get_n_items(self): return len(self.properties) def do_get_item(self, i): return self.properties[i] class NotRunModel(GObject.GObject, Gio.ListModel): def __init__(self, notrun): GObject.GObject.__init__(self) self.notrun = [ NotRun(m) for m in notrun ] self.notrun.sort() def do_get_item_type(self): return GObject.TYPE_PYOBJECT def do_get_n_items(self): return len(self.notrun) def do_get_item(self, i): return self.notrun[i] class Factory(Gtk.SignalListItemFactory): def __init__(self, column): Gtk.SignalListItemFactory.__init__(self) self.column = column self.connect("setup", self.on_setup) self.connect("bind", self.on_bind) self.connect("unbind", self.on_unbind) self.connect("teardown", self.on_teardown) def on_setup(self, factory, listitem): listitem.set_child(Gtk.Label(xalign=0)) def on_bind(self, factory, listitem): label = listitem.get_child() match self.column: case "Property": label.set_text(listitem.get_item().key) case "Value": label.set_text(listitem.get_item().value) case _: label.set_text("=") def on_unbind(self, factory, listitem): listitem.get_child().set_text("") def on_teardown(self, factory, listitem): listitem.set_child(None) class NotRunFactory(Gtk.SignalListItemFactory): def __init__(self): Gtk.SignalListItemFactory.__init__(self) self.connect("setup", self.on_setup) self.connect("bind", self.on_bind) self.connect("unbind", self.on_unbind) self.connect("teardown", self.on_teardown) def on_setup(self, factory, listitem): listitem.set_child(Gtk.Label(xalign=0)) def on_bind(self, factory, listitem): listitem.get_child().set_text(listitem.get_item().message) def on_unbind(self, factory, listitem): listitem.get_child().set_text("") def on_teardown(self, factory, listitem): listitem.set_child(None) class View(Gtk.ColumnView): def __init__(self, properties): self.selection = Gtk.NoSelection.new(Model(properties)) Gtk.ColumnView.__init__(self, model=self.selection) self.add_css_class("data-table") for title in [ "Property", "=", "Value" ]: self.append_column(Gtk.ColumnViewColumn.new(title, Factory(title))) class NotRunView(Gtk.ListView): def __init__(self, notrun): self.selection = Gtk.NoSelection.new(NotRunModel(notrun)) Gtk.ListView.__init__(self, model=self.selection, factory=NotRunFactory()) self.add_css_class("data-table") class Stack(Gtk.Stack): def __init__(self): Gtk.Stack.__init__(self) common.SizeGroup.add_widget(self) def clear(self): current = self.get_visible_child_name() pages = self.get_pages() children = [ pages.get_item(i).get_child() for i in range(pages.get_n_items()) ] for child in children: self.remove(child) return current def show_properties(self, results, current): self.set_transition_type(Gtk.StackTransitionType.NONE) for version in results.versions: self.add_page(View(results.properties[version]), version, Gtk.PolicyType.NEVER, current) self.add_page(NotRunView(results.skipped), "[not run]", Gtk.PolicyType.AUTOMATIC, current) self.set_transition_type(Gtk.StackTransitionType.OVER_LEFT_RIGHT) def add_page(self, child, name, policy, current): window = Gtk.ScrolledWindow(vscrollbar_policy=policy, child=child) self.add_titled(window, name, name) if current == name: self.set_visible_child(window)