Add download progress dialog and some mod loader parse function.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
from PySide6.QtCore import QObject
|
||||
|
||||
|
||||
class RocketLauncher(QObject):
|
||||
pass
|
||||
@@ -0,0 +1,129 @@
|
||||
"""
|
||||
IMPORTANT: Still under construction!
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
from datetime import datetime
|
||||
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
from core_lib.common.exception import ProfileException
|
||||
from core_lib.game.profile import read_profile_file
|
||||
|
||||
DEFAuLT_PROFILE_RELATIVE_PATH = Path("launcher_profiles.json")
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ProfileSummary:
|
||||
id: str
|
||||
name: str
|
||||
version_id: str
|
||||
version_type: str
|
||||
icon: str
|
||||
last_used: datetime | None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ProfileDetail(ProfileSummary):
|
||||
game_dir: Path | None
|
||||
java_args: str
|
||||
resolution: tuple[int, int] | None
|
||||
created: datetime
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CreateProfileRequest:
|
||||
name: str
|
||||
version_id: str
|
||||
version_type: str = "custom"
|
||||
game_dir: Path | None = None
|
||||
java_args: str = ""
|
||||
icon: str = ""
|
||||
resolution: tuple[int, int] | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class UpdateProfileRequest:
|
||||
name: str | None = None
|
||||
version_id: str | None = None
|
||||
version_type: str | None = None
|
||||
game_dir: Path | None = None
|
||||
java_args: str | None = None
|
||||
icon: str | None = None
|
||||
resolution: tuple[int, int] | None = None
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class LaunchProfile:
|
||||
pass
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ValidationResult:
|
||||
pass
|
||||
|
||||
class ProfileManager(QObject):
|
||||
profiles_changed = Signal()
|
||||
profile_created = Signal(str)
|
||||
profile_updated = Signal(str)
|
||||
profile_removed = Signal(str)
|
||||
current_profile_changed = Signal(object) # str | None
|
||||
error_occurred = Signal(str, str) # error_code, message
|
||||
replace_relative_path = Signal(str)
|
||||
|
||||
def __init__(self, app):
|
||||
QObject.__init__(self, app)
|
||||
self.app = app
|
||||
self.profiles = []
|
||||
|
||||
@property
|
||||
def profile_path(self):
|
||||
return Path(self.app.work_dir, DEFAuLT_PROFILE_RELATIVE_PATH)
|
||||
|
||||
# File lifetime
|
||||
def load(self, path: Path=None, return_value=False) -> None | dict:
|
||||
if path is None:
|
||||
path = self.profile_path
|
||||
|
||||
try:
|
||||
result = read_profile_file(path)
|
||||
except ProfileException:
|
||||
pass
|
||||
|
||||
|
||||
# def load(self, path: str | Path) -> None: ...
|
||||
def save(self) -> None: ...
|
||||
def save_as(self, path: str | Path) -> None: ...
|
||||
def reload(self) -> None: ...
|
||||
|
||||
# Profile search
|
||||
def list_profiles(self) -> list[ProfileSummary]: ...
|
||||
def get_profile(self, profile_id: str) -> ProfileDetail: ...
|
||||
def contains(self, profile_id: str) -> bool: ...
|
||||
|
||||
# CRUD
|
||||
def create_profile(self, request: CreateProfileRequest) -> str: ...
|
||||
def update_profile(
|
||||
self, profile_id: str, changes: UpdateProfileRequest
|
||||
) -> None: ...
|
||||
def remove_profile(self, profile_id: str) -> None: ...
|
||||
def duplicate_profile(
|
||||
self, profile_id: str, new_name: str | None = None
|
||||
) -> str: ...
|
||||
|
||||
# Profile switch
|
||||
def set_current_profile(self, profile_id: str | None) -> None: ...
|
||||
def get_current_profile_id(self) -> str | None: ...
|
||||
def get_launch_profile(self, profile_id: str) -> LaunchProfile: ...
|
||||
|
||||
# Validation
|
||||
def validate(self, request: CreateProfileRequest) -> ValidationResult: ...
|
||||
|
||||
# Property
|
||||
@property
|
||||
def path(self) -> Path | None: ...
|
||||
|
||||
@property
|
||||
def is_loaded(self) -> bool: ...
|
||||
|
||||
@property
|
||||
def is_dirty(self) -> bool: ...
|
||||
@@ -0,0 +1,60 @@
|
||||
import queue
|
||||
import threading
|
||||
|
||||
from PySide6.QtCore import QObject, Signal, Slot
|
||||
from PySide6.QtWidgets import QProgressDialog
|
||||
|
||||
from core_lib.qt import messagebox
|
||||
|
||||
|
||||
class AskForRequest:
|
||||
def __init__(self, title, message):
|
||||
self.title = title
|
||||
self.message = message
|
||||
self.result_queue = queue.Queue(maxsize=1)
|
||||
self.wait_event = threading.Event()
|
||||
|
||||
self.details = None # Set this if flag use_plain_text is enabled
|
||||
|
||||
# flags
|
||||
self.use_plain_text = True
|
||||
|
||||
def wait(self, timeout: int | None = 10):
|
||||
return self.wait_event.wait(timeout)
|
||||
|
||||
def result(self):
|
||||
try:
|
||||
return self.result_queue.get_nowait()
|
||||
except queue.Empty:
|
||||
return None
|
||||
|
||||
class SelectPathRequest(AskForRequest):
|
||||
def __init__(self, title, message, filter_raw=None):
|
||||
super().__init__(title, message)
|
||||
self.filter = filter_raw
|
||||
|
||||
|
||||
class WidgetManager(QObject):
|
||||
def __init__(self):
|
||||
super(WidgetManager, self).__init__()
|
||||
|
||||
self.signal = self.WidgetSignal(self)
|
||||
self.download_signal = self.DownloadSignal(self)
|
||||
|
||||
class DownloadSignal(QObject):
|
||||
started = Signal(str, str) # task_id, display_name
|
||||
progress = Signal(str, str, float) # task_id, status, percent
|
||||
finished = Signal(str) # task_id
|
||||
failed = Signal(str, str) # task_id, error
|
||||
removed = Signal(str) # task_id
|
||||
log = Signal(str)
|
||||
|
||||
class WidgetSignal(QObject):
|
||||
show_error_message = Signal(str)
|
||||
show_and_print_error_message = Signal(dict)
|
||||
show_warning_message = Signal(str)
|
||||
show_info_message = Signal(str)
|
||||
enable_widget = Signal(object)
|
||||
disable_widget = Signal(object)
|
||||
askyesno = Signal(object)
|
||||
ask_for_path = Signal(object)
|
||||
Reference in New Issue
Block a user