QModInstaller: add install slot

Install is done in a separate thread so that the UI can keep updating
This commit is contained in:
Toast 2025-06-06 17:14:13 +02:00
parent e7d487c180
commit 9ed941b37e

View file

@ -1,10 +1,15 @@
import time
from pathlib import Path from pathlib import Path
from urllib.parse import urlparse from urllib.parse import urlparse
from PySide6.QtCore import Property, QObject, Signal from PySide6.QtCore import Property, QObject, QRunnable, QThreadPool, Signal, Slot
from PySide6.QtQml import QmlElement, QmlSingleton from PySide6.QtQml import QmlElement, QmlSingleton
from leek.mod_installer import ModInstaller, UnsupportedArchiveTypeError, NoModExceptionError from leek.mod_installer import (
ModInstaller,
NoModExceptionError,
UnsupportedArchiveTypeError,
)
QML_IMPORT_NAME = "Leek.QModInstaller" QML_IMPORT_NAME = "Leek.QModInstaller"
QML_IMPORT_MAJOR_VERSION = 1 QML_IMPORT_MAJOR_VERSION = 1
@ -58,3 +63,31 @@ class QModInstaller(QObject):
@Property(str, notify=status_changed) @Property(str, notify=status_changed)
def status(self) -> str: def status(self) -> str:
return self.__status return self.__status
finished_install = Signal(name="finishedInstall")
@Slot()
def install(self) -> None:
worker = InstallWorker(InstallWorkerSignals())
# worker.signals.installed.connect(self.mod_finished_installing)
worker.signals.installed.connect(self.finished_install)
QThreadPool.globalInstance().start(worker)
class InstallWorker(QRunnable):
def __init__(self, signals) -> None:
super().__init__()
self.signals = signals
# @Slot()
def run(self) -> None:
# Fake installing for now
time.sleep(4)
self.signals.installed.emit()
class InstallWorkerSignals(QObject):
def __init__(self):
super().__init__()
installed = Signal()