ludex-gui 0.62.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ludex_gui/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """Qt desktop frontend of ludex."""
ludex_gui/app.py ADDED
@@ -0,0 +1,88 @@
1
+ """The ludex desktop launcher (Qt Quick): a sidebar, a cover-art library grid, game pages, search, jobs, settings
2
+ and one sidebar page per plugin view.
3
+
4
+ Like the TUI it only collects input, calls the core and shows results. ``backend.py`` bridges the core to QML;
5
+ the screens are the files under ``qml/``.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import os
10
+ import sys
11
+ from collections.abc import Callable, Mapping
12
+ from dataclasses import dataclass
13
+ from pathlib import Path
14
+ import sqlite3
15
+
16
+ from PySide6.QtCore import QObject, QUrl
17
+ from PySide6.QtGui import QGuiApplication
18
+ from PySide6.QtQml import QQmlApplicationEngine
19
+ from PySide6.QtQuickControls2 import QQuickStyle
20
+
21
+ from ludex.accounts import get_account
22
+ from ludex.installed import installed_keys
23
+ from ludex.loader import load_providers
24
+ from ludex.paths import StatePaths, state_paths
25
+ from ludex.playtime import Played, play_stats
26
+ from ludex.plugins import Provider
27
+
28
+ from .backend import Backend
29
+
30
+ QML_DIR = Path(__file__).with_name("qml")
31
+
32
+
33
+ @dataclass(frozen=True, slots=True)
34
+ class Launcher:
35
+ """A loaded launcher: the engine, its backend and the QML warnings seen while loading."""
36
+
37
+ engine: QQmlApplicationEngine
38
+ backend: Backend
39
+ warnings: list[str]
40
+
41
+ @property
42
+ def window(self) -> QObject | None:
43
+ roots = self.engine.rootObjects()
44
+ return roots[0] if roots else None
45
+
46
+
47
+ def build_engine(
48
+ paths: StatePaths,
49
+ sources: Mapping[str, Provider],
50
+ installed: Callable[[], set[tuple[str, str]]],
51
+ config_for: Callable[[str, str], Mapping[str, str]],
52
+ played: Callable[[sqlite3.Connection], Mapping[int, Played]],
53
+ prefix_root: Path,
54
+ ) -> Launcher:
55
+ """Build the backend and load the window without running the event loop."""
56
+ QQuickStyle.setStyle("Basic")
57
+ backend = Backend(paths, sources, installed, config_for, played, prefix_root)
58
+ engine = QQmlApplicationEngine()
59
+ warnings: list[str] = []
60
+ engine.warnings.connect(lambda found: warnings.extend(w.toString() for w in found))
61
+ engine.rootContext().setContextProperty("backend", backend)
62
+ engine.load(QUrl.fromLocalFile(str(QML_DIR / "Main.qml")))
63
+ backend.reload()
64
+ return Launcher(engine, backend, warnings)
65
+
66
+
67
+ def main() -> int:
68
+ """Run the launcher on the user's library; ``ludex gui`` and the ``ludex-gui`` script land here."""
69
+ sources, _ = load_providers()
70
+ paths = state_paths()
71
+ previous_umask = os.umask(0o077)
72
+ try:
73
+ app = QGuiApplication.instance() or QGuiApplication(sys.argv[:1])
74
+ app.setApplicationName("ludex")
75
+ launcher = build_engine(
76
+ paths, sources, lambda: installed_keys(paths, sources)[0],
77
+ lambda store, account: get_account(paths, f"{store}:{account}").config,
78
+ lambda conn: play_stats(paths, sources, conn)[0],
79
+ paths.root / "prefixes",
80
+ )
81
+ if launcher.window is None:
82
+ return 1
83
+ launcher.backend.autoRefresh()
84
+ code = app.exec()
85
+ launcher.backend.closeDown()
86
+ finally:
87
+ os.umask(previous_umask)
88
+ return code