64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
from pathlib import Path
|
|
|
|
from PySide6.QtCore import Property, QObject, Signal, Slot
|
|
from PySide6.QtQml import QmlElement, QmlUncreatable
|
|
|
|
from leek.mod import Mod
|
|
|
|
QML_IMPORT_NAME = "Leek"
|
|
QML_IMPORT_MAJOR_VERSION = 1
|
|
|
|
|
|
# Qt follows C++ naming conventions
|
|
# ruff: noqa: N802
|
|
@QmlElement
|
|
@QmlUncreatable("QMod is intended to be returned by a QModListModel")
|
|
class QMod(QObject):
|
|
"""
|
|
Qt wrapper around the Mod() class
|
|
"""
|
|
|
|
__mod: Mod
|
|
|
|
def __init__(self, mod_path: Path, parent=None) -> None:
|
|
QObject.__init__(self, parent)
|
|
try:
|
|
self.__mod = Mod(mod_path)
|
|
except:
|
|
# Pass though all exceptions
|
|
raise
|
|
|
|
@property
|
|
def pathlib_path(self) -> Path:
|
|
return self.__mod.path
|
|
|
|
@Property(str, constant=True)
|
|
def path(self) -> str:
|
|
return str(self.__mod.path)
|
|
|
|
@Property(str, constant=True)
|
|
def name(self) -> str | None:
|
|
return self.__mod.name
|
|
|
|
@Property(str, constant=True)
|
|
def description(self) -> str | None:
|
|
return self.__mod.description
|
|
|
|
@Property(str, constant=True)
|
|
def longDescription(self) -> str | None:
|
|
return self.__mod.long_description
|
|
|
|
@Property(list, constant=True)
|
|
def authors(self) -> list[str] | None:
|
|
return self.__mod.authors
|
|
|
|
mod_enabled = Signal(name="enabled")
|
|
|
|
@Property(bool, notify=mod_enabled)
|
|
def enabled(self) -> bool:
|
|
return self.__mod.enabled
|
|
|
|
@enabled.setter # type: ignore[no-redef]
|
|
def enabled(self, value: bool) -> None:
|
|
self.__mod.enabled = value
|
|
self.mod_enabled.emit()
|