QRC and GUI Test #4

This commit is contained in:
Linuxero committed 2026-11-15 17:06:22 +01:00
1 parent 828534c1f5
commit 15a716d107
11 files changed
+628 -6

No files matched your search

+59 -4
View File
@@ -1,9 +1,64 @@
# This Python file uses the following encoding: utf-8
"""Application entry point."""
from __future__ import annotations
import logging
import sys
from PySide6.QtWidgets import QApplication
from pathlib import Path
from PySide6.QtCore import QUrl
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
import mcc.resources_rc # noqa: F401 — registers the compiled Qt resources
from mcc.core.plugin_registry import PluginRegistry, RegistryEntry
from mcc.core.static_plugin_provider import StaticRegistryProvider
def load_plugins() -> list[dict[str, object]]:
"""Load explicitly registered plugins and convert them for QML."""
project_root = Path(__file__).resolve().parent
example_manifest = project_root / "plugins" / "example-readonly" / "plugin.json"
provider = StaticRegistryProvider(
registered_entries=(
RegistryEntry(
plugin_id="org.mageia.mcc.example",
manifest_path=str(example_manifest),
),
)
)
result = PluginRegistry(provider).load()
for error in result.errors:
logging.warning("Could not load plugin %s: %s", error.plugin_id, error.message)
logging.info("Loaded %d plugin(s).", len(result.plugins))
return [
{
"pluginId": plugin.plugin_id,
"name": plugin.name,
"description": plugin.description,
"category": plugin.category,
"subcategory": plugin.subcategory,
"frontends": list(plugin.frontends),
"capabilities": list(plugin.capabilities),
}
for plugin in result.plugins
]
if __name__ == "__main__":
app = QApplication(sys.argv)
# ...
logging.basicConfig(level=logging.INFO)
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.rootContext().setContextProperty("registeredPlugins", load_plugins())
engine.load(QUrl("qrc:/qml/Main.qml"))
if not engine.rootObjects():
sys.exit(1)
sys.exit(app.exec())
+1 -1
View File
@@ -1,6 +1,6 @@
{
"schema_version": 1,
"id": "org.mageia.mcc.example-readonly",
"id": "org.mageia.mcc.example",
"api_version": "1",
"name": "Example",
"description": "An example read-only control-center plugin.",
+1 -1
View File
@@ -11,7 +11,7 @@ requires = ["uv_build>=0.13.8,<0.14"]
build-backend = "uv_build"
[tool.pyside6-project]
files = ["Doxyfile", "README.md", "docs/CONTRIBUTING.md", "docs/architecture.md", "main.py", "plugins/example-readonly/plugin.json", "src/mcc/__init__.py", "src/mcc/core/__init__.py", "src/mcc/core/plugin_manifest.py", "src/mcc/core/plugin_registry.py", "tests/test_plugin_registry.py"]
files = ["Doxyfile", "README.md", "docs/CONTRIBUTING.md", "docs/architecture.md", "main.py", "plugins/example-readonly/plugin.json", "qml/Main.qml", "qml/PluginCard.qml", "qml/PluginList.qml", "resources.qrc", "src/mcc/__init__.py", "src/mcc/core/__init__.py", "src/mcc/core/plugin_manifest.py", "src/mcc/core/plugin_registry.py", "src/mcc/core/static_plugin_provider.py", "tests/test_plugin_registry.py"]
[tool.uv.build-backend]
module-name = "mcc"
+17
View File
@@ -0,0 +1,17 @@
import QtQuick
import QtQuick.Controls
ApplicationWindow {
visible: true
width: 760
height: 560
minimumWidth: 480
minimumHeight: 360
title: "Mageia Control Center"
PluginList {
anchors.fill: parent
anchors.margins: 16
plugins: registeredPlugins
}
}
+41
View File
@@ -0,0 +1,41 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Frame {
id: root
required property var plugin
implicitHeight: content.implicitHeight + topPadding + bottomPadding
padding: 14
ColumnLayout {
id: content
width: parent.width
spacing: 6
Label {
Layout.fillWidth: true
text: root.plugin.name
font.pixelSize: 18
font.bold: true
wrapMode: Text.Wrap
}
Label {
Layout.fillWidth: true
text: root.plugin.description
wrapMode: Text.Wrap
}
Label {
Layout.fillWidth: true
text: root.plugin.category + " / " + root.plugin.subcategory
color: palette.placeholderText
font.pixelSize: 12
wrapMode: Text.Wrap
}
}
}
+52
View File
@@ -0,0 +1,52 @@
import QtQuick
import QtQuick.Controls
Column {
id: root
property var plugins: []
spacing: 12
Label {
width: parent.width
text: "Available tools"
font.pixelSize: 24
font.bold: true
}
Label {
width: parent.width
text: root.plugins.length === 1
? "1 tool"
: root.plugins.length + " tools"
color: palette.placeholderText
}
ListView {
id: pluginView
width: parent.width
height: Math.max(0, root.height - y)
clip: true
spacing: 10
model: root.plugins
boundsBehavior: Flickable.StopAtBounds
delegate: PluginCard {
required property var modelData
width: pluginView.width
plugin: modelData
}
ScrollBar.vertical: ScrollBar {}
}
Label {
anchors.centerIn: parent
visible: root.plugins.length === 0
text: "No tools are currently available."
color: palette.placeholderText
}
}
+196
View File
@@ -0,0 +1,196 @@
# Resource object code (Python 3)
# Created by: object code
# Created by: The Resource Compiler for Qt version 6.12.0
# WARNING! All changes made in this file will be lost!
from PySide6 import QtCore
qt_resource_data = b"\
\x00\x00\x013\
i\
mport QtQuick\x0aim\
port QtQuick.Con\
trols\x0a\x0aApplicati\
onWindow {\x0a v\
isible: true\x0a \
width: 760\x0a \
height: 560\x0a \
minimumWidth: 48\
0\x0a minimumHei\
ght: 360\x0a tit\
le: \x22Mageia Cont\
rol Center\x22\x0a\x0a \
PluginList {\x0a \
anchors.fi\
ll: parent\x0a \
anchors.margi\
ns: 16\x0a p\
lugins: register\
edPlugins\x0a }\x0a\
}\x0a\
\x00\x00\x03d\
i\
mport QtQuick\x0aim\
port QtQuick.Con\
trols\x0aimport QtQ\
uick.Layouts\x0a\x0aFr\
ame {\x0a id: ro\
ot\x0a\x0a required\
property var pl\
ugin\x0a\x0a implic\
itHeight: conten\
t.implicitHeight\
+ topPadding + \
bottomPadding\x0a \
padding: 14\x0a\x0a \
ColumnLayout \
{\x0a id: co\
ntent\x0a\x0a w\
idth: parent.wid\
th\x0a spaci\
ng: 6\x0a\x0a L\
abel {\x0a \
Layout.fillWi\
dth: true\x0a \
text: root\
.plugin.name\x0a \
font.pi\
xelSize: 18\x0a \
font.bol\
d: true\x0a \
wrapMode: Te\
xt.Wrap\x0a \
}\x0a\x0a Label\
{\x0a L\
ayout.fillWidth:\
true\x0a \
text: root.plu\
gin.description\x0a\
wrap\
Mode: Text.Wrap\x0a\
}\x0a\x0a \
Label {\x0a \
Layout.fi\
llWidth: true\x0a \
text: \
root.plugin.cate\
gory + \x22 / \x22 + r\
oot.plugin.subca\
tegory\x0a \
color: palett\
e.placeholderTex\
t\x0a fo\
nt.pixelSize: 12\
\x0a wra\
pMode: Text.Wrap\
\x0a }\x0a }\
\x0a}\x0a\
\x00\x00\x04\x1b\
i\
mport QtQuick\x0aim\
port QtQuick.Con\
trols\x0a\x0aColumn {\x0a\
id: root\x0a\x0a \
property var p\
lugins: []\x0a\x0a \
spacing: 12\x0a\x0a \
Label {\x0a \
width: parent.w\
idth\x0a tex\
t: \x22Available to\
ols\x22\x0a fon\
t.pixelSize: 24\x0a\
font.bol\
d: true\x0a }\x0a\x0a \
Label {\x0a \
width: parent\
.width\x0a t\
ext: root.plugin\
s.length === 1\x0a \
? \x22\
1 tool\x22\x0a \
: root.plu\
gins.length + \x22 \
tools\x22\x0a c\
olor: palette.pl\
aceholderText\x0a \
}\x0a\x0a ListVie\
w {\x0a id: \
pluginView\x0a\x0a \
width: paren\
t.width\x0a \
height: Math.max\
(0, root.height \
- y)\x0a cli\
p: true\x0a \
spacing: 10\x0a \
model: root.\
plugins\x0a \
boundsBehavior: \
Flickable.StopAt\
Bounds\x0a\x0a \
delegate: Plugin\
Card {\x0a \
required prop\
erty var modelDa\
ta\x0a\x0a \
width: pluginVie\
w.width\x0a \
plugin: mode\
lData\x0a }\x0a\
\x0a ScrollB\
ar.vertical: Scr\
ollBar {}\x0a }\x0a\
\x0a Label {\x0a \
anchors.cen\
terIn: parent\x0a \
visible: r\
oot.plugins.leng\
th === 0\x0a \
text: \x22No tools\
are currently a\
vailable.\x22\x0a \
color: palett\
e.placeholderTex\
t\x0a }\x0a}\x0a\
"
qt_resource_name = b"\
\x00\x03\
\x00\x00x<\
\x00q\
\x00m\x00l\
\x00\x08\
\x08\x01^\x5c\
\x00M\
\x00a\x00i\x00n\x00.\x00q\x00m\x00l\
\x00\x0e\
\x0f\xfbH\xdc\
\x00P\
\x00l\x00u\x00g\x00i\x00n\x00C\x00a\x00r\x00d\x00.\x00q\x00m\x00l\
\x00\x0e\
\x07\xdbG\x9c\
\x00P\
\x00l\x00u\x00g\x00i\x00n\x00L\x00i\x00s\x00t\x00.\x00q\x00m\x00l\
"
qt_resource_struct = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00D\x00\x00\x00\x00\x00\x01\x00\x00\x04\x9f\
\x00\x00\x01\xa1\xdf\xe8\xbe\xe8\
\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\xa1\xdf\xe8\xbe\xd8\
\x00\x00\x00\x22\x00\x00\x00\x00\x00\x01\x00\x00\x017\
\x00\x00\x01\xa1\xdf\xe8\xbe\xe6\
"
def qInitResources():
QtCore.qRegisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data)
def qCleanupResources():
QtCore.qUnregisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data)
qInitResources()
+7
View File
@@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/qml">
<file alias="Main.qml">qml/Main.qml</file>
<file alias="PluginList.qml">qml/PluginList.qml</file>
<file alias="PluginCard.qml">qml/PluginCard.qml</file>
</qresource>
</RCC>
+23
View File
@@ -0,0 +1,23 @@
"""Static plugin registry provider."""
from __future__ import annotations
from dataclasses import dataclass
from mcc.core.plugin_registry import RegistryEntry
@dataclass(frozen=True)
class StaticRegistryProvider:
"""Provides plugin entries declared explicitly in application code.
This is the initial metadata source. It does not discover plugins by
scanning directories; a later package-installed provider can implement
the same RegistryProvider interface.
"""
registered_entries: tuple[RegistryEntry, ...]
def entries(self) -> list[RegistryEntry]:
"""Return the explicitly configured plugin entries."""
return list(self.registered_entries)
+196
View File
@@ -0,0 +1,196 @@
# Resource object code (Python 3)
# Created by: object code
# Created by: The Resource Compiler for Qt version 6.12.0
# WARNING! All changes made in this file will be lost!
from PySide6 import QtCore
qt_resource_data = b"\
\x00\x00\x013\
i\
mport QtQuick\x0aim\
port QtQuick.Con\
trols\x0a\x0aApplicati\
onWindow {\x0a v\
isible: true\x0a \
width: 760\x0a \
height: 560\x0a \
minimumWidth: 48\
0\x0a minimumHei\
ght: 360\x0a tit\
le: \x22Mageia Cont\
rol Center\x22\x0a\x0a \
PluginList {\x0a \
anchors.fi\
ll: parent\x0a \
anchors.margi\
ns: 16\x0a p\
lugins: register\
edPlugins\x0a }\x0a\
}\x0a\
\x00\x00\x03d\
i\
mport QtQuick\x0aim\
port QtQuick.Con\
trols\x0aimport QtQ\
uick.Layouts\x0a\x0aFr\
ame {\x0a id: ro\
ot\x0a\x0a required\
property var pl\
ugin\x0a\x0a implic\
itHeight: conten\
t.implicitHeight\
+ topPadding + \
bottomPadding\x0a \
padding: 14\x0a\x0a \
ColumnLayout \
{\x0a id: co\
ntent\x0a\x0a w\
idth: parent.wid\
th\x0a spaci\
ng: 6\x0a\x0a L\
abel {\x0a \
Layout.fillWi\
dth: true\x0a \
text: root\
.plugin.name\x0a \
font.pi\
xelSize: 18\x0a \
font.bol\
d: true\x0a \
wrapMode: Te\
xt.Wrap\x0a \
}\x0a\x0a Label\
{\x0a L\
ayout.fillWidth:\
true\x0a \
text: root.plu\
gin.description\x0a\
wrap\
Mode: Text.Wrap\x0a\
}\x0a\x0a \
Label {\x0a \
Layout.fi\
llWidth: true\x0a \
text: \
root.plugin.cate\
gory + \x22 / \x22 + r\
oot.plugin.subca\
tegory\x0a \
color: palett\
e.placeholderTex\
t\x0a fo\
nt.pixelSize: 12\
\x0a wra\
pMode: Text.Wrap\
\x0a }\x0a }\
\x0a}\x0a\
\x00\x00\x04\x1b\
i\
mport QtQuick\x0aim\
port QtQuick.Con\
trols\x0a\x0aColumn {\x0a\
id: root\x0a\x0a \
property var p\
lugins: []\x0a\x0a \
spacing: 12\x0a\x0a \
Label {\x0a \
width: parent.w\
idth\x0a tex\
t: \x22Available to\
ols\x22\x0a fon\
t.pixelSize: 24\x0a\
font.bol\
d: true\x0a }\x0a\x0a \
Label {\x0a \
width: parent\
.width\x0a t\
ext: root.plugin\
s.length === 1\x0a \
? \x22\
1 tool\x22\x0a \
: root.plu\
gins.length + \x22 \
tools\x22\x0a c\
olor: palette.pl\
aceholderText\x0a \
}\x0a\x0a ListVie\
w {\x0a id: \
pluginView\x0a\x0a \
width: paren\
t.width\x0a \
height: Math.max\
(0, root.height \
- y)\x0a cli\
p: true\x0a \
spacing: 10\x0a \
model: root.\
plugins\x0a \
boundsBehavior: \
Flickable.StopAt\
Bounds\x0a\x0a \
delegate: Plugin\
Card {\x0a \
required prop\
erty var modelDa\
ta\x0a\x0a \
width: pluginVie\
w.width\x0a \
plugin: mode\
lData\x0a }\x0a\
\x0a ScrollB\
ar.vertical: Scr\
ollBar {}\x0a }\x0a\
\x0a Label {\x0a \
anchors.cen\
terIn: parent\x0a \
visible: r\
oot.plugins.leng\
th === 0\x0a \
text: \x22No tools\
are currently a\
vailable.\x22\x0a \
color: palett\
e.placeholderTex\
t\x0a }\x0a}\x0a\
"
qt_resource_name = b"\
\x00\x03\
\x00\x00x<\
\x00q\
\x00m\x00l\
\x00\x08\
\x08\x01^\x5c\
\x00M\
\x00a\x00i\x00n\x00.\x00q\x00m\x00l\
\x00\x0e\
\x0f\xfbH\xdc\
\x00P\
\x00l\x00u\x00g\x00i\x00n\x00C\x00a\x00r\x00d\x00.\x00q\x00m\x00l\
\x00\x0e\
\x07\xdbG\x9c\
\x00P\
\x00l\x00u\x00g\x00i\x00n\x00L\x00i\x00s\x00t\x00.\x00q\x00m\x00l\
"
qt_resource_struct = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00D\x00\x00\x00\x00\x00\x01\x00\x00\x04\x9f\
\x00\x00\x01\xa1\xdf\xe8\xbe\xe8\
\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\xa1\xdf\xe8\xbe\xd8\
\x00\x00\x00\x22\x00\x00\x00\x00\x00\x01\x00\x00\x017\
\x00\x00\x01\xa1\xdf\xe8\xbe\xe6\
"
def qInitResources():
QtCore.qRegisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data)
def qCleanupResources():
QtCore.qUnregisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data)
qInitResources()
+35
View File
@@ -8,6 +8,41 @@ from mcc.core.plugin_registry import (
RegistryEntry,
)
from mcc.core.static_plugin_provider import StaticRegistryProvider
def test_static_provider_returns_configured_entries() -> None:
"""The static provider returns only the entries configured in code."""
entries = (
RegistryEntry(
plugin_id="org.mageia.mcc.example",
manifest_path="/plugins/example-readonly/plugin.json",
),
)
provider = StaticRegistryProvider(registered_entries=entries)
assert provider.entries() == list(entries)
def test_registry_loads_plugin_from_static_provider(tmp_path: Path) -> None:
"""The registry can load a manifest supplied by the static provider."""
plugin_id = "org.mageia.mcc.example"
manifest_path = tmp_path / "plugin.json"
write_manifest(manifest_path, plugin_id)
provider = StaticRegistryProvider(
registered_entries=(
RegistryEntry(
plugin_id=plugin_id,
manifest_path=str(manifest_path),
),
)
)
result = PluginRegistry(provider).load()
assert [plugin.plugin_id for plugin in result.plugins] == [plugin_id]
assert result.errors == ()
class FakeProvider:
"""Test provider that returns a fixed list of registered entries."""