Add QModInstaller class
This commit is contained in:
parent
b0cebe12a0
commit
035c333dcf
1 changed files with 57 additions and 0 deletions
57
src/leek/qmod_installer.py
Normal file
57
src/leek/qmod_installer.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from PySide6.QtCore import Property, QObject, Signal
|
||||
from PySide6.QtQml import QmlElement, QmlSingleton
|
||||
|
||||
from leek.mod_installer import ModInstaller, UnsupportedArchiveTypeError
|
||||
|
||||
QML_IMPORT_NAME = "Leek.QModInstaller"
|
||||
QML_IMPORT_MAJOR_VERSION = 1
|
||||
|
||||
|
||||
# Qt follows C++ naming conventions
|
||||
# ruff: noqa: N802
|
||||
@QmlElement
|
||||
@QmlSingleton
|
||||
class QModInstaller(QObject):
|
||||
"""
|
||||
Qt Wrapper around the ModInstaller() class
|
||||
"""
|
||||
|
||||
__mod_installer: ModInstaller
|
||||
__status: str
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent=parent)
|
||||
self.__status = "uninitialized"
|
||||
|
||||
mod_path_changed = Signal(name="modPathChanged")
|
||||
|
||||
@Property(str, notify=mod_path_changed)
|
||||
def modPath(self) -> str:
|
||||
return self.test
|
||||
|
||||
@modPath.setter # type: ignore[no-redef]
|
||||
def modPath(self, value: str) -> None:
|
||||
try:
|
||||
# In python 3.13 pathlib gained a from_uri() method which would be very useful
|
||||
parsed_path: str = urlparse(value, "file").path
|
||||
self.__mod_installer = ModInstaller(Path(parsed_path))
|
||||
self.__status = "initialized"
|
||||
self.status_changed.emit()
|
||||
except UnsupportedArchiveTypeError:
|
||||
self.__status = "UnsupportedArchiveTypeError"
|
||||
self.status_changed.emit()
|
||||
|
||||
install_status_changed = Signal(name="installStatusChanged")
|
||||
|
||||
@Property(bool, notify=install_status_changed)
|
||||
def installed(self) -> bool:
|
||||
return self.__mod_installer.is_installed
|
||||
|
||||
status_changed = Signal(name="statusChanged")
|
||||
|
||||
@Property(str, notify=status_changed)
|
||||
def status(self) -> str:
|
||||
return self.__status
|
||||
Loading…
Add table
Add a link
Reference in a new issue