1c296474c5
Shared: Require an argument to initialize the each singleton, if it is called uninitialized, raise a RuntimeError InstallDialog: Use QCheckBox label for the information text and remove the layout LaunchDialog: Minor code clarity improvements Console: add a Dialog with the process's environment variables GameUtils: Inherit the system's environment and not a clean one ImportGroup: Add the ability to automatically import all games in a folder RareStyle: Use rgb values, remove hex codes and rgba values IndicatorLineEdit/PathEdit: Infer object names from class name, don't override layout method Models: Type fields as Optional (`Union[<something>, None]`) Paths: Use pathlib for everything Signed-off-by: Stelios Tsampas <loathingkernel@gmail.com>
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from argparse import Namespace
|
|
from typing import Optional
|
|
|
|
from legendary.core import LegendaryCore
|
|
|
|
from rare.utils.models import ApiResults, GlobalSignals
|
|
|
|
_legendary_core_singleton: Optional[LegendaryCore] = None
|
|
_global_signals_singleton: Optional[GlobalSignals] = None
|
|
_arguments_singleton: Optional[Namespace] = None
|
|
_api_results_singleton: Optional[ApiResults] = None
|
|
|
|
|
|
def LegendaryCoreSingleton(init: bool = False) -> LegendaryCore:
|
|
global _legendary_core_singleton
|
|
if _legendary_core_singleton is None and not init:
|
|
raise RuntimeError("Uninitialized use of LegendaryCoreSingleton")
|
|
if _legendary_core_singleton is None:
|
|
_legendary_core_singleton = LegendaryCore()
|
|
return _legendary_core_singleton
|
|
|
|
|
|
def GlobalSignalsSingleton(init: bool = False) -> GlobalSignals:
|
|
global _global_signals_singleton
|
|
if _global_signals_singleton is None and not init:
|
|
raise RuntimeError("Uninitialized use of GlobalSignalsSingleton")
|
|
if _global_signals_singleton is None:
|
|
_global_signals_singleton = GlobalSignals()
|
|
return _global_signals_singleton
|
|
|
|
|
|
def ArgumentsSingleton(args: Namespace = None) -> Optional[Namespace]:
|
|
global _arguments_singleton
|
|
if _arguments_singleton is None and args is None:
|
|
raise RuntimeError("Uninitialized use of ArgumentsSingleton")
|
|
if _arguments_singleton is None:
|
|
_arguments_singleton = args
|
|
return _arguments_singleton
|
|
|
|
|
|
def ApiResultsSingleton(res: ApiResults = None) -> Optional[ApiResults]:
|
|
global _api_results_singleton
|
|
if _api_results_singleton is None and res is None:
|
|
raise RuntimeError("Uninitialized use of ApiResultsSingleton")
|
|
if _api_results_singleton is None:
|
|
_api_results_singleton = res
|
|
return _api_results_singleton
|
|
|