PBKittyConfigStudio 0.1.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.
- pb_kitty_config_studio/__init__.py +3 -0
- pb_kitty_config_studio/__main__.py +153 -0
- pb_kitty_config_studio/argparse_qt.py +99 -0
- pb_kitty_config_studio/config/__init__.py +81 -0
- pb_kitty_config_studio/config/_babel_extractor.py +35 -0
- pb_kitty_config_studio/config/schema.json +3654 -0
- pb_kitty_config_studio/core/__init__.py +0 -0
- pb_kitty_config_studio/core/kitty_conf.py +316 -0
- pb_kitty_config_studio/i18n.py +115 -0
- pb_kitty_config_studio/locale/en/LC_MESSAGES/pb_kitty_config_studio.mo +0 -0
- pb_kitty_config_studio/locale/en/LC_MESSAGES/pb_kitty_config_studio.po +978 -0
- pb_kitty_config_studio/locale/fr/LC_MESSAGES/pb_kitty_config_studio.mo +0 -0
- pb_kitty_config_studio/locale/fr/LC_MESSAGES/pb_kitty_config_studio.po +983 -0
- pb_kitty_config_studio/platform/__init__.py +1 -0
- pb_kitty_config_studio/platform/auto_update.py +267 -0
- pb_kitty_config_studio/platform/desktop.py +174 -0
- pb_kitty_config_studio/resources/__init__.py +54 -0
- pb_kitty_config_studio/resources/cancel.svg +1 -0
- pb_kitty_config_studio/resources/clear-all-data.svg +1 -0
- pb_kitty_config_studio/resources/help-about.svg +1 -0
- pb_kitty_config_studio/resources/pbkittyconfigstudio.icns +0 -0
- pb_kitty_config_studio/resources/pbkittyconfigstudio.ico +0 -0
- pb_kitty_config_studio/resources/pbkittyconfigstudio.png +0 -0
- pb_kitty_config_studio/resources/quit.svg +1 -0
- pb_kitty_config_studio/resources/refresh.svg +1 -0
- pb_kitty_config_studio/resources/save-as.svg +1 -0
- pb_kitty_config_studio/resources/save.svg +1 -0
- pb_kitty_config_studio/ui/__init__.py +0 -0
- pb_kitty_config_studio/ui/about_dialog.py +160 -0
- pb_kitty_config_studio/ui/main_window.py +491 -0
- pb_kitty_config_studio/ui/widgets.py +363 -0
- pbkittyconfigstudio-0.1.0.dist-info/METADATA +161 -0
- pbkittyconfigstudio-0.1.0.dist-info/RECORD +36 -0
- pbkittyconfigstudio-0.1.0.dist-info/WHEEL +4 -0
- pbkittyconfigstudio-0.1.0.dist-info/entry_points.txt +2 -0
- pbkittyconfigstudio-0.1.0.dist-info/licenses/LICENSE +674 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Entry point — run as `python -m pb_kitty_config_studio` or `PBKittyConfigStudio`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import logging
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from pb_kitty_config_studio.argparse_qt import add_qt_arguments
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
14
|
+
from pb_kitty_config_studio import __version__
|
|
15
|
+
|
|
16
|
+
parser = argparse.ArgumentParser(
|
|
17
|
+
prog="PBKittyConfigStudio",
|
|
18
|
+
description=(
|
|
19
|
+
"PBKittyConfigStudio — a desktop GUI for configuring the kitty terminal."
|
|
20
|
+
),
|
|
21
|
+
epilog=("Qt platform options (--style, --platform, …) are forwarded to Qt."),
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
"-V", "--version", action="version", version=f"%(prog)s {__version__}"
|
|
25
|
+
)
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--kitty-conf",
|
|
28
|
+
metavar="PATH",
|
|
29
|
+
default=None,
|
|
30
|
+
help="Path to kitty.conf to edit (default: kitty's own config location)",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# ── Desktop integration (Linux) ──────────────────────────────────────────
|
|
34
|
+
desktop_group = parser.add_argument_group(
|
|
35
|
+
"desktop integration",
|
|
36
|
+
"Install a .desktop menu entry + icon for the current user and exit "
|
|
37
|
+
"(Linux only — pip installs have no post-install hook to do this "
|
|
38
|
+
"automatically).",
|
|
39
|
+
)
|
|
40
|
+
desktop_target = desktop_group.add_mutually_exclusive_group()
|
|
41
|
+
desktop_target.add_argument(
|
|
42
|
+
"--install-desktop-entry",
|
|
43
|
+
action="store_true",
|
|
44
|
+
default=False,
|
|
45
|
+
help="Install a desktop menu entry + icon for the current user",
|
|
46
|
+
)
|
|
47
|
+
desktop_target.add_argument(
|
|
48
|
+
"--uninstall-desktop-entry",
|
|
49
|
+
action="store_true",
|
|
50
|
+
default=False,
|
|
51
|
+
help="Remove the desktop menu entry + icon installed by "
|
|
52
|
+
"--install-desktop-entry",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# ── Self-update (PyInstaller executables only) ───────────────────────────
|
|
56
|
+
update_group = parser.add_argument_group(
|
|
57
|
+
"self-update",
|
|
58
|
+
"Available only in PyInstaller-built executables — a source or "
|
|
59
|
+
"pip/PyPI install has no single running binary to replace.",
|
|
60
|
+
)
|
|
61
|
+
update_group.add_argument(
|
|
62
|
+
"--auto-update",
|
|
63
|
+
action="store_true",
|
|
64
|
+
default=False,
|
|
65
|
+
help=(
|
|
66
|
+
"Download the latest release from GitHub and replace the "
|
|
67
|
+
"running executable, then exit"
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
level_group = parser.add_mutually_exclusive_group()
|
|
72
|
+
level_group.add_argument(
|
|
73
|
+
"-d", "--debug", action="store_const", const="DEBUG", dest="log_level"
|
|
74
|
+
)
|
|
75
|
+
level_group.add_argument(
|
|
76
|
+
"-v", "--verbose", action="store_const", const="INFO", dest="log_level"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
add_qt_arguments(parser)
|
|
80
|
+
|
|
81
|
+
return parser
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def main() -> None:
|
|
85
|
+
logging.basicConfig(
|
|
86
|
+
format="%(asctime)s %(levelname)-8s %(name)s: %(message)s",
|
|
87
|
+
datefmt="%H:%M:%S",
|
|
88
|
+
level=logging.WARNING,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
parser = _build_parser()
|
|
92
|
+
ns = parser.parse_args()
|
|
93
|
+
if ns.log_level:
|
|
94
|
+
logging.getLogger().setLevel(ns.log_level)
|
|
95
|
+
|
|
96
|
+
if ns.auto_update:
|
|
97
|
+
from pb_kitty_config_studio.platform.auto_update import perform_auto_update
|
|
98
|
+
|
|
99
|
+
ok, message = perform_auto_update()
|
|
100
|
+
if ok:
|
|
101
|
+
print(message)
|
|
102
|
+
else:
|
|
103
|
+
print(message, file=sys.stderr)
|
|
104
|
+
sys.exit(0 if ok else 1)
|
|
105
|
+
|
|
106
|
+
if ns.install_desktop_entry or ns.uninstall_desktop_entry:
|
|
107
|
+
if ns.install_desktop_entry:
|
|
108
|
+
from pb_kitty_config_studio.platform.desktop import (
|
|
109
|
+
install_desktop_entry as _action,
|
|
110
|
+
)
|
|
111
|
+
else:
|
|
112
|
+
from pb_kitty_config_studio.platform.desktop import (
|
|
113
|
+
uninstall_desktop_entry as _action,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
ok, message = _action()
|
|
117
|
+
if ok:
|
|
118
|
+
print(message)
|
|
119
|
+
else:
|
|
120
|
+
print(message, file=sys.stderr)
|
|
121
|
+
sys.exit(0 if ok else 1)
|
|
122
|
+
|
|
123
|
+
from PySide6.QtGui import QIcon
|
|
124
|
+
from PySide6.QtWidgets import QApplication
|
|
125
|
+
|
|
126
|
+
from pb_kitty_config_studio import __version__, i18n
|
|
127
|
+
from pb_kitty_config_studio.resources import icon_path
|
|
128
|
+
|
|
129
|
+
# Only argv[0] plus the explicitly-declared, argparse-validated Qt
|
|
130
|
+
# options (ns.qt_args) are forwarded to Qt — never the raw sys.argv,
|
|
131
|
+
# which would let Qt's own permissive C++ parser silently absorb or
|
|
132
|
+
# ignore anything argparse didn't already recognize above.
|
|
133
|
+
app = QApplication([sys.argv[0]] + ns.qt_args)
|
|
134
|
+
app.setApplicationName("PBKittyConfigStudio")
|
|
135
|
+
app.setApplicationVersion(__version__)
|
|
136
|
+
app.setOrganizationName("cardolan")
|
|
137
|
+
icon = icon_path()
|
|
138
|
+
if icon is not None:
|
|
139
|
+
app.setWindowIcon(QIcon(str(icon)))
|
|
140
|
+
|
|
141
|
+
# i18n must be set up before the window is created.
|
|
142
|
+
i18n.setup(app)
|
|
143
|
+
|
|
144
|
+
from pb_kitty_config_studio.ui.main_window import try_load_main_window
|
|
145
|
+
|
|
146
|
+
config_path = Path(ns.kitty_conf).expanduser() if ns.kitty_conf else None
|
|
147
|
+
window = try_load_main_window(config_path=config_path)
|
|
148
|
+
window.show()
|
|
149
|
+
sys.exit(app.exec())
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if __name__ == "__main__":
|
|
153
|
+
main()
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""argparse helpers for passing Qt command-line options."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class _QtArgAction(argparse.Action):
|
|
7
|
+
"""Accumulate Qt flags into ``args.qt_args`` as single-dash tokens.
|
|
8
|
+
|
|
9
|
+
``--style fusion`` appends ``["-style", "fusion"]``;
|
|
10
|
+
``--reverse`` appends ``["-reverse"]``.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
14
|
+
current = list(getattr(namespace, self.dest) or [])
|
|
15
|
+
current.append("-" + option_string.lstrip("-"))
|
|
16
|
+
if isinstance(values, str):
|
|
17
|
+
current.append(values)
|
|
18
|
+
setattr(namespace, self.dest, current)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def add_qt_arguments(parser: argparse.ArgumentParser) -> None:
|
|
22
|
+
"""Add Qt command-line options to *parser*, collected in ``args.qt_args``.
|
|
23
|
+
|
|
24
|
+
Each ``--option [value]`` is stored as ``["-option"]`` or
|
|
25
|
+
``["-option", "value"]`` and appended to ``args.qt_args``, ready to be
|
|
26
|
+
passed directly to ``QApplication``.
|
|
27
|
+
|
|
28
|
+
Declaring every Qt option explicitly — rather than handing the whole raw
|
|
29
|
+
``sys.argv`` to ``QApplication`` — means our own ``argparse`` stays the
|
|
30
|
+
sole authority on what is a valid command line: an unknown flag is
|
|
31
|
+
rejected with a normal argparse error instead of being silently
|
|
32
|
+
forwarded to (and permissively absorbed or ignored by) Qt's own C++
|
|
33
|
+
argument parser.
|
|
34
|
+
|
|
35
|
+
Qt options are hidden from the ``usage:`` line to reduce noise; they still
|
|
36
|
+
appear in the "Qt options" section of the full ``--help`` output.
|
|
37
|
+
"""
|
|
38
|
+
parser.set_defaults(qt_args=[])
|
|
39
|
+
|
|
40
|
+
base_formatter = parser.formatter_class
|
|
41
|
+
|
|
42
|
+
class _Formatter(base_formatter):
|
|
43
|
+
def add_usage(self, usage, actions, groups, prefix=None):
|
|
44
|
+
super().add_usage(
|
|
45
|
+
usage,
|
|
46
|
+
[a for a in actions if not isinstance(a, _QtArgAction)],
|
|
47
|
+
groups,
|
|
48
|
+
prefix,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
parser.formatter_class = _Formatter
|
|
52
|
+
group = parser.add_argument_group(
|
|
53
|
+
"Qt options",
|
|
54
|
+
"Passed through to the Qt framework (see Qt documentation for details).",
|
|
55
|
+
)
|
|
56
|
+
for flag, metavar, help_text in [
|
|
57
|
+
("style", "STYLE", "Qt widget style (e.g. fusion, windows)"),
|
|
58
|
+
("stylesheet", "FILE", "Qt stylesheet"),
|
|
59
|
+
("platform", "PLUGIN", "Qt platform plugin"),
|
|
60
|
+
("platformpluginpath", "PATH", "Qt platform plugin search path"),
|
|
61
|
+
("platformtheme", "THEME", "Qt platform theme"),
|
|
62
|
+
("plugin", "PLUGIN", "Qt plugin to load"),
|
|
63
|
+
("qmljsdebugger", "VALUE", "Qt QML/JS debugger options"),
|
|
64
|
+
("display", "DISPLAY", "X11 display name"),
|
|
65
|
+
("geometry", "GEOMETRY", "X11 window geometry"),
|
|
66
|
+
("fn", "FONT", "X11 font name (short form)"),
|
|
67
|
+
("font", "FONT", "X11 font name"),
|
|
68
|
+
("bg", "COLOR", "X11 background colour"),
|
|
69
|
+
("background", "COLOR", "X11 background colour"),
|
|
70
|
+
("fg", "COLOR", "X11 foreground colour"),
|
|
71
|
+
("foreground", "COLOR", "X11 foreground colour"),
|
|
72
|
+
("btn", "COLOR", "X11 button colour"),
|
|
73
|
+
("button", "COLOR", "X11 button colour"),
|
|
74
|
+
("name", "NAME", "X11 application name"),
|
|
75
|
+
("title", "TITLE", "X11 window title"),
|
|
76
|
+
("visual", "VISUAL", "X11 visual type"),
|
|
77
|
+
("ncols", "N", "X11 colour cube size"),
|
|
78
|
+
("im", "INPUTMETHOD", "X11 input method"),
|
|
79
|
+
("inputstyle", "STYLE", "X11 input style"),
|
|
80
|
+
]:
|
|
81
|
+
group.add_argument(
|
|
82
|
+
f"--{flag}",
|
|
83
|
+
dest="qt_args",
|
|
84
|
+
metavar=metavar,
|
|
85
|
+
action=_QtArgAction,
|
|
86
|
+
help=help_text,
|
|
87
|
+
)
|
|
88
|
+
for flag, help_text in [
|
|
89
|
+
("widgetcount", "Print widget count on exit"),
|
|
90
|
+
("reverse", "Right-to-left layout direction"),
|
|
91
|
+
("cmap", "Use private colour map on 8-bit display"),
|
|
92
|
+
]:
|
|
93
|
+
group.add_argument(
|
|
94
|
+
f"--{flag}",
|
|
95
|
+
dest="qt_args",
|
|
96
|
+
nargs=0,
|
|
97
|
+
action=_QtArgAction,
|
|
98
|
+
help=help_text,
|
|
99
|
+
)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Loader for the settings schema (``config/schema.json``).
|
|
2
|
+
|
|
3
|
+
The schema is generated by ``schema_builder/build_schema.py`` directly from
|
|
4
|
+
kitty's own option definitions, then curated by hand (see ``CODING.md``):
|
|
5
|
+
two fields kitty has no equivalent for — a group's ``icon`` and an option's
|
|
6
|
+
``app_type``/``label`` — start out as the literal string ``"UNKNOWN"`` and
|
|
7
|
+
must be filled in by a programmer before the app will start.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
_SCHEMA_PATH = Path(__file__).parent / "schema.json"
|
|
17
|
+
_UNKNOWN = "UNKNOWN"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SchemaNotCuratedError(Exception):
|
|
21
|
+
"""Raised when ``schema.json`` still has one or more ``UNKNOWN`` fields.
|
|
22
|
+
|
|
23
|
+
This means ``schema_builder/build_schema.py`` was run against a newer
|
|
24
|
+
kitty and introduced groups/options a programmer hasn't curated yet
|
|
25
|
+
(set a real ``icon``/``app_type``/``label`` for) — see ``CODING.md``.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, paths: list[str]) -> None:
|
|
29
|
+
self.paths = paths
|
|
30
|
+
listing = "\n".join(f" - {p}" for p in paths)
|
|
31
|
+
super().__init__(
|
|
32
|
+
f"config/schema.json has {len(paths)} field(s) still set to"
|
|
33
|
+
f' "UNKNOWN":\n{listing}\n\n'
|
|
34
|
+
"A programmer must replace them with real values before the"
|
|
35
|
+
" app can start — see CODING.md."
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _find_unknown(value: Any, path: str) -> list[str]:
|
|
40
|
+
if isinstance(value, dict):
|
|
41
|
+
found = []
|
|
42
|
+
for key, sub in value.items():
|
|
43
|
+
found += _find_unknown(sub, f"{path} > {key}" if path else key)
|
|
44
|
+
return found
|
|
45
|
+
if isinstance(value, list):
|
|
46
|
+
found = []
|
|
47
|
+
for i, sub in enumerate(value):
|
|
48
|
+
found += _find_unknown(sub, f"{path}[{i}]")
|
|
49
|
+
return found
|
|
50
|
+
if value == _UNKNOWN:
|
|
51
|
+
return [path]
|
|
52
|
+
return []
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def load_schema() -> dict[str, Any]:
|
|
56
|
+
"""Return the settings schema, or raise ``SchemaNotCuratedError``."""
|
|
57
|
+
schema = json.loads(_SCHEMA_PATH.read_text(encoding="utf-8"))
|
|
58
|
+
unknown = _find_unknown(schema, "")
|
|
59
|
+
if unknown:
|
|
60
|
+
raise SchemaNotCuratedError(unknown)
|
|
61
|
+
return schema
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def iter_settings(schema: dict[str, Any]):
|
|
65
|
+
"""Yield ``(group_path, group, key, setting)`` for every leaf setting.
|
|
66
|
+
|
|
67
|
+
``group_path`` is the list of groups from the top-level category down to
|
|
68
|
+
the (sub)group the setting directly belongs to — e.g. ``[colors,
|
|
69
|
+
colors.table]`` for a setting under the "The color table" subsection —
|
|
70
|
+
so the UI can render subgroups as labelled subsections.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
def _walk(group: dict[str, Any], path: list[dict[str, Any]]):
|
|
74
|
+
path = [*path, group]
|
|
75
|
+
for setting in group["options"]:
|
|
76
|
+
yield path, group, setting["name"], setting
|
|
77
|
+
for subgroup in group["subgroups"]:
|
|
78
|
+
yield from _walk(subgroup, path)
|
|
79
|
+
|
|
80
|
+
for category in schema["groups"]:
|
|
81
|
+
yield from _walk(category, [])
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Babel extraction method for ``config/schema.json``.
|
|
2
|
+
|
|
3
|
+
Registered in ``babel.cfg`` — ``schema.json`` isn't Python source (it holds
|
|
4
|
+
no ``_()`` calls, unlike the old ``schema.py``), so pybabel's default
|
|
5
|
+
extractor can't find its translatable strings on its own. This one walks
|
|
6
|
+
the schema and yields each group's ``title`` and each option's ``label`` as
|
|
7
|
+
a message to translate.
|
|
8
|
+
|
|
9
|
+
Kitty's long ``description_html`` prose is deliberately *not* extracted:
|
|
10
|
+
it's English-only, straight from kitty's own docs, and too much volume to
|
|
11
|
+
translate reliably (see ``CODING.md``).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
from collections.abc import Iterable
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
_Message = tuple[int, "str | None", str, list[str]]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def extract_schema_json(
|
|
24
|
+
fileobj: Any, keywords: Any, comment_tags: Any, options: Any
|
|
25
|
+
) -> Iterable[_Message]:
|
|
26
|
+
data = json.load(fileobj)
|
|
27
|
+
|
|
28
|
+
def walk(groups: list[dict[str, Any]]) -> Iterable[_Message]:
|
|
29
|
+
for group in groups:
|
|
30
|
+
yield 1, None, group["title"], []
|
|
31
|
+
for option in group["options"]:
|
|
32
|
+
yield 1, None, option["label"], []
|
|
33
|
+
yield from walk(group["subgroups"])
|
|
34
|
+
|
|
35
|
+
yield from walk(data["groups"])
|