#!/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 Results(Property): def __init__(self, properties): total = properties["TESTS"] time = properties["TIME"] failed = properties["FAILURES"] skipped = properties["SKIPPED"] passed = int(total) - (int(skipped) + int(failed)) 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 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 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 Stack(Gtk.Stack): def __init__(self): Gtk.Stack.__init__(self, transition_type=Gtk.StackTransitionType.OVER_LEFT_RIGHT) common.SizeGroup.add_widget(self) def clear(self): 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) def show_properties(self, results): for version in results.versions: window = Gtk.ScrolledWindow(vscrollbar_policy=Gtk.PolicyType.NEVER, child=View(results.properties[version])) self.add_titled(window, version, version)