Lgndr: Move generic function implementations to api_monkeys
This commit is contained in:
parent
3501741c03
commit
c388f99c46
|
@ -1,8 +1,7 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Callable, List, Optional
|
||||
from typing_extensions import Protocol
|
||||
|
||||
from .api_monkeys import LgndrIndirectStatus
|
||||
from .api_monkeys import LgndrIndirectStatus, GetBooleanChoiceProtocol, get_boolean_choice, verify_stdout
|
||||
|
||||
"""
|
||||
@dataclass(kw_only=True)
|
||||
|
@ -15,19 +14,6 @@ class LgndrCommonArgs:
|
|||
"""
|
||||
|
||||
|
||||
class _GetBooleanChoiceP(Protocol):
|
||||
def __call__(self, prompt: str, default: bool = ...) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
def _get_boolean_choice(prompt: str, default: bool = True) -> bool:
|
||||
return default
|
||||
|
||||
|
||||
def _verify_stdout(a0: int, a1: int, a2: float, a3: float) -> None:
|
||||
print(f"Verification progress: {a0}/{a1} ({a2:.01f}%) [{a3:.1f} MiB/s]\t\r")
|
||||
|
||||
|
||||
@dataclass
|
||||
class LgndrImportGameArgs:
|
||||
app_path: str
|
||||
|
@ -39,7 +25,7 @@ class LgndrImportGameArgs:
|
|||
yes: bool = False
|
||||
# Rare: Extra arguments
|
||||
indirect_status: LgndrIndirectStatus = LgndrIndirectStatus()
|
||||
get_boolean_choice: _GetBooleanChoiceP = _get_boolean_choice
|
||||
get_boolean_choice: GetBooleanChoiceProtocol = get_boolean_choice
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -49,7 +35,7 @@ class LgndrUninstallGameArgs:
|
|||
yes: bool = False
|
||||
# Rare: Extra arguments
|
||||
indirect_status: LgndrIndirectStatus = LgndrIndirectStatus()
|
||||
get_boolean_choice: _GetBooleanChoiceP = _get_boolean_choice
|
||||
get_boolean_choice: GetBooleanChoiceProtocol = get_boolean_choice
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -57,7 +43,7 @@ class LgndrVerifyGameArgs:
|
|||
app_name: str
|
||||
# Rare: Extra arguments
|
||||
indirect_status: LgndrIndirectStatus = LgndrIndirectStatus()
|
||||
verify_stdout: Callable[[int, int, float, float], None] = _verify_stdout
|
||||
verify_stdout: Callable[[int, int, float, float], None] = verify_stdout
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -93,9 +79,9 @@ class LgndrInstallGameArgs:
|
|||
yes: bool = True
|
||||
# Rare: Extra arguments
|
||||
indirect_status: LgndrIndirectStatus = LgndrIndirectStatus()
|
||||
get_boolean_choice: _GetBooleanChoiceP = _get_boolean_choice
|
||||
get_boolean_choice: GetBooleanChoiceProtocol = get_boolean_choice
|
||||
sdl_prompt: Callable[[str, str], List[str]] = lambda app_name, title: [""]
|
||||
verify_stdout: Callable[[int, int, float, float], None] = _verify_stdout
|
||||
verify_stdout: Callable[[int, int, float, float], None] = verify_stdout
|
||||
|
||||
# def __post_init__(self):
|
||||
# if self.sdl_prompt is None:
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
from PyQt5.QtWidgets import QMessageBox, QLabel
|
||||
from PyQt5.QtWidgets import QLabel
|
||||
from typing_extensions import Protocol
|
||||
|
||||
|
||||
def get_boolean_choice(prompt, default=True):
|
||||
choice = QMessageBox.question(
|
||||
None, "Import DLCs?", prompt,
|
||||
defaultButton=QMessageBox.Yes if default else QMessageBox.No
|
||||
)
|
||||
return True if choice == QMessageBox.StandardButton.Yes else False
|
||||
class GetBooleanChoiceProtocol(Protocol):
|
||||
def __call__(self, prompt: str, default: bool = ...) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
def return_exit(__status):
|
||||
return __status
|
||||
def get_boolean_choice(prompt: str, default: bool = True) -> bool:
|
||||
return default
|
||||
|
||||
|
||||
def verify_stdout(a0: int, a1: int, a2: float, a3: float) -> None:
|
||||
print(f"Verification progress: {a0}/{a1} ({a2:.01f}%) [{a3:.1f} MiB/s]\t\r")
|
||||
|
||||
|
||||
class UILogHandler(logging.Handler):
|
||||
|
@ -55,7 +57,9 @@ class LgndrIndirectStatus:
|
|||
|
||||
|
||||
class LgndrIndirectLogger:
|
||||
def __init__(self, status: LgndrIndirectStatus, logger: logging.Logger = None, level: int = logging.ERROR):
|
||||
def __init__(
|
||||
self, status: LgndrIndirectStatus, logger: logging.Logger = None, level: int = logging.ERROR
|
||||
):
|
||||
self.logger = logger
|
||||
self.level = level
|
||||
self.status = status
|
||||
|
|
Loading…
Reference in a new issue