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,160 @@
|
|
|
1
|
+
"""About dialog."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from email.utils import getaddresses
|
|
7
|
+
from importlib.metadata import metadata
|
|
8
|
+
|
|
9
|
+
from PySide6 import __version__ as _pyside_version
|
|
10
|
+
from PySide6.QtCore import Qt
|
|
11
|
+
from PySide6.QtWidgets import (
|
|
12
|
+
QApplication,
|
|
13
|
+
QDialog,
|
|
14
|
+
QDialogButtonBox,
|
|
15
|
+
QFormLayout,
|
|
16
|
+
QFrame,
|
|
17
|
+
QHBoxLayout,
|
|
18
|
+
QLabel,
|
|
19
|
+
QSizePolicy,
|
|
20
|
+
QSpacerItem,
|
|
21
|
+
QVBoxLayout,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from pb_kitty_config_studio import __version__
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class AboutDialog(QDialog):
|
|
28
|
+
"""Application About dialog."""
|
|
29
|
+
|
|
30
|
+
def __init__(self, parent=None) -> None:
|
|
31
|
+
super().__init__(parent)
|
|
32
|
+
self.setMinimumWidth(600)
|
|
33
|
+
self.resize(600, 320)
|
|
34
|
+
self.setWindowTitle(_("About PBKittyConfigStudio"))
|
|
35
|
+
|
|
36
|
+
layout = QVBoxLayout(self)
|
|
37
|
+
content = QHBoxLayout()
|
|
38
|
+
|
|
39
|
+
icon_col = QVBoxLayout()
|
|
40
|
+
icon_label = QLabel(self)
|
|
41
|
+
icon_label.setFixedSize(64, 64)
|
|
42
|
+
icon_label.setAlignment(
|
|
43
|
+
Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop
|
|
44
|
+
)
|
|
45
|
+
icon_label.setScaledContents(True)
|
|
46
|
+
icon = QApplication.windowIcon()
|
|
47
|
+
if not icon.isNull():
|
|
48
|
+
icon_label.setPixmap(icon.pixmap(64, 64))
|
|
49
|
+
icon_col.addWidget(icon_label)
|
|
50
|
+
icon_col.addItem(
|
|
51
|
+
QSpacerItem(
|
|
52
|
+
20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
content.addLayout(icon_col)
|
|
56
|
+
|
|
57
|
+
frame = QFrame(self)
|
|
58
|
+
frame.setFrameShape(QFrame.Shape.Panel)
|
|
59
|
+
frame.setFrameShadow(QFrame.Shadow.Raised)
|
|
60
|
+
frame.setLineWidth(3)
|
|
61
|
+
frame_layout = QVBoxLayout(frame)
|
|
62
|
+
|
|
63
|
+
frame_layout.addItem(
|
|
64
|
+
QSpacerItem(
|
|
65
|
+
20, 20, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
app_name_label = QLabel(
|
|
70
|
+
'<b style="font-size: 14pt;">PBKittyConfigStudio</b>', frame
|
|
71
|
+
)
|
|
72
|
+
app_name_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
73
|
+
frame_layout.addWidget(app_name_label)
|
|
74
|
+
|
|
75
|
+
version_label = QLabel(__version__, frame)
|
|
76
|
+
version_label.setToolTip(_("Application version"))
|
|
77
|
+
version_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
78
|
+
frame_layout.addWidget(version_label)
|
|
79
|
+
|
|
80
|
+
authors_label = QLabel(_authors_html(), frame)
|
|
81
|
+
authors_label.setTextFormat(Qt.TextFormat.RichText)
|
|
82
|
+
authors_label.setOpenExternalLinks(True)
|
|
83
|
+
authors_label.setWordWrap(True)
|
|
84
|
+
authors_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
85
|
+
frame_layout.addWidget(authors_label)
|
|
86
|
+
|
|
87
|
+
description_label = QLabel(
|
|
88
|
+
_("A desktop GUI for configuring the kitty terminal."), frame
|
|
89
|
+
)
|
|
90
|
+
description_label.setWordWrap(True)
|
|
91
|
+
description_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
92
|
+
frame_layout.addWidget(description_label)
|
|
93
|
+
|
|
94
|
+
thanks_label = QLabel(
|
|
95
|
+
_(
|
|
96
|
+
"Many thanks to Kovid Goyal and the kitty development team for"
|
|
97
|
+
' the <a href="https://github.com/kovidgoyal/kitty">kitty</a>'
|
|
98
|
+
" terminal this app configures."
|
|
99
|
+
),
|
|
100
|
+
frame,
|
|
101
|
+
)
|
|
102
|
+
thanks_label.setTextFormat(Qt.TextFormat.RichText)
|
|
103
|
+
thanks_label.setOpenExternalLinks(True)
|
|
104
|
+
thanks_label.setWordWrap(True)
|
|
105
|
+
thanks_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
106
|
+
frame_layout.addWidget(thanks_label)
|
|
107
|
+
|
|
108
|
+
form = QFormLayout()
|
|
109
|
+
form.setLabelAlignment(
|
|
110
|
+
Qt.AlignmentFlag.AlignRight
|
|
111
|
+
| Qt.AlignmentFlag.AlignTrailing
|
|
112
|
+
| Qt.AlignmentFlag.AlignVCenter
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
license_label = QLabel("GPL-3.0-or-later", frame)
|
|
116
|
+
form.addRow(_("License:"), license_label)
|
|
117
|
+
|
|
118
|
+
python_version = sys.version_info
|
|
119
|
+
python_version_label = QLabel(
|
|
120
|
+
f"{python_version.major}.{python_version.minor}.{python_version.micro}",
|
|
121
|
+
frame,
|
|
122
|
+
)
|
|
123
|
+
form.addRow(_("Python version:"), python_version_label)
|
|
124
|
+
|
|
125
|
+
pyside_version_label = QLabel(_pyside_version, frame)
|
|
126
|
+
form.addRow(_("PySide6 version:"), pyside_version_label)
|
|
127
|
+
|
|
128
|
+
frame_layout.addLayout(form)
|
|
129
|
+
|
|
130
|
+
frame_layout.addItem(
|
|
131
|
+
QSpacerItem(
|
|
132
|
+
20, 20, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
content.addWidget(frame)
|
|
137
|
+
layout.addLayout(content)
|
|
138
|
+
|
|
139
|
+
button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Close, self)
|
|
140
|
+
button_box.setCenterButtons(True)
|
|
141
|
+
button_box.rejected.connect(self.reject)
|
|
142
|
+
layout.addWidget(button_box)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _authors_html() -> str:
|
|
146
|
+
try:
|
|
147
|
+
meta = metadata("PBKittyConfigStudio")
|
|
148
|
+
raw = meta.get_all("Author-email") or []
|
|
149
|
+
pairs = getaddresses(raw)
|
|
150
|
+
except Exception: # noqa: BLE001
|
|
151
|
+
pairs = []
|
|
152
|
+
|
|
153
|
+
parts = []
|
|
154
|
+
for name, addr in pairs:
|
|
155
|
+
label = name or addr
|
|
156
|
+
if addr:
|
|
157
|
+
parts.append(f'<a href="mailto:{addr}">{label}</a>')
|
|
158
|
+
else:
|
|
159
|
+
parts.append(label)
|
|
160
|
+
return ", ".join(parts)
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
"""The application's single window: a category sidebar plus a settings form."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import subprocess
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from PySide6.QtCore import QSize, Qt, QUrl
|
|
11
|
+
from PySide6.QtGui import QAction, QActionGroup, QDesktopServices, QIcon, QKeySequence
|
|
12
|
+
from PySide6.QtWidgets import (
|
|
13
|
+
QFileDialog,
|
|
14
|
+
QFrame,
|
|
15
|
+
QGroupBox,
|
|
16
|
+
QHBoxLayout,
|
|
17
|
+
QLabel,
|
|
18
|
+
QLineEdit,
|
|
19
|
+
QListWidget,
|
|
20
|
+
QListWidgetItem,
|
|
21
|
+
QMainWindow,
|
|
22
|
+
QMenu,
|
|
23
|
+
QMessageBox,
|
|
24
|
+
QScrollArea,
|
|
25
|
+
QStackedWidget,
|
|
26
|
+
QStatusBar,
|
|
27
|
+
QToolButton,
|
|
28
|
+
QVBoxLayout,
|
|
29
|
+
QWidget,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
from pb_kitty_config_studio import i18n
|
|
33
|
+
from pb_kitty_config_studio.config import SchemaNotCuratedError, load_schema
|
|
34
|
+
from pb_kitty_config_studio.core import kitty_conf
|
|
35
|
+
from pb_kitty_config_studio.resources import (
|
|
36
|
+
cancel_icon_path,
|
|
37
|
+
clear_config_icon_path,
|
|
38
|
+
help_about_icon_path,
|
|
39
|
+
quit_icon_path,
|
|
40
|
+
refresh_icon_path,
|
|
41
|
+
save_as_icon_path,
|
|
42
|
+
save_icon_path,
|
|
43
|
+
)
|
|
44
|
+
from pb_kitty_config_studio.ui.about_dialog import AboutDialog
|
|
45
|
+
from pb_kitty_config_studio.ui.widgets import build_setting_widget
|
|
46
|
+
|
|
47
|
+
_log = logging.getLogger(__name__)
|
|
48
|
+
|
|
49
|
+
_KITTY_DOCS_URL = "https://sw.kovidgoyal.net/kitty"
|
|
50
|
+
_KITTY_OPTIONS_URL = "https://sw.kovidgoyal.net/kitty/conf"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _has_options(group: dict[str, Any]) -> bool:
|
|
54
|
+
return bool(group["options"]) or any(_has_options(sg) for sg in group["subgroups"])
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _searchable_text(key: str, setting: dict[str, Any]) -> str:
|
|
58
|
+
return f"{key} {setting.get('label', '')}".lower()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class _SettingRow(QFrame):
|
|
62
|
+
"""One editable setting: label + key badge + status badge, input widget,
|
|
63
|
+
description.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
def __init__(self, key: str, setting: dict, parent: QWidget | None = None) -> None:
|
|
67
|
+
super().__init__(parent)
|
|
68
|
+
self.setObjectName("settingRow")
|
|
69
|
+
self.setFrameShape(QFrame.Shape.StyledPanel)
|
|
70
|
+
self._setting = setting
|
|
71
|
+
self._search_text = _searchable_text(key, setting)
|
|
72
|
+
|
|
73
|
+
header = QHBoxLayout()
|
|
74
|
+
# Indirected through a local var: pybabel's Python extractor is a
|
|
75
|
+
# naive token scanner, not AST-aware — `_(setting["label"])` makes
|
|
76
|
+
# it wrongly extract the literal "label" as a msgid. The real label
|
|
77
|
+
# text is extracted from schema.json itself (see
|
|
78
|
+
# config/_babel_extractor.py); `_()` here only needs to *look up*
|
|
79
|
+
# the already-known string at runtime.
|
|
80
|
+
label_text = setting["label"]
|
|
81
|
+
label = QLabel(_(label_text))
|
|
82
|
+
label.setStyleSheet("font-weight: 600;")
|
|
83
|
+
badge = QLabel(key)
|
|
84
|
+
badge.setStyleSheet(
|
|
85
|
+
"font-family: monospace; font-size: 10px; color: #c7d2fe;"
|
|
86
|
+
" background: #1e1b4b; padding: 1px 6px; border-radius: 3px;"
|
|
87
|
+
)
|
|
88
|
+
self._status_badge = QLabel()
|
|
89
|
+
self._status_badge.setStyleSheet("font-size: 10px; padding: 1px 6px;")
|
|
90
|
+
|
|
91
|
+
self._reset_button = QToolButton()
|
|
92
|
+
self._reset_button.setAutoRaise(True)
|
|
93
|
+
self._reset_button.setToolTip(_("Reset to default"))
|
|
94
|
+
self._reset_button.setIconSize(QSize(14, 14))
|
|
95
|
+
icon_path = cancel_icon_path()
|
|
96
|
+
if icon_path is not None:
|
|
97
|
+
self._reset_button.setIcon(QIcon(str(icon_path)))
|
|
98
|
+
self._reset_button.clicked.connect(self._reset_to_default)
|
|
99
|
+
self._reset_button.setVisible(False)
|
|
100
|
+
|
|
101
|
+
header.addWidget(label)
|
|
102
|
+
header.addStretch(1)
|
|
103
|
+
header.addWidget(self._reset_button)
|
|
104
|
+
header.addWidget(self._status_badge)
|
|
105
|
+
header.addWidget(badge)
|
|
106
|
+
|
|
107
|
+
self.widget = build_setting_widget(setting)
|
|
108
|
+
self.widget.value_changed.connect(self._update_status_badge)
|
|
109
|
+
|
|
110
|
+
layout = QVBoxLayout(self)
|
|
111
|
+
layout.addLayout(header)
|
|
112
|
+
layout.addWidget(self.widget)
|
|
113
|
+
|
|
114
|
+
description = setting.get("description_html")
|
|
115
|
+
if description:
|
|
116
|
+
desc_label = QLabel(description)
|
|
117
|
+
desc_label.setTextFormat(Qt.TextFormat.RichText)
|
|
118
|
+
desc_label.setWordWrap(True)
|
|
119
|
+
desc_label.setOpenExternalLinks(True)
|
|
120
|
+
desc_label.setStyleSheet(
|
|
121
|
+
"color: #4338ca; font-size: 11px; font-style: italic;"
|
|
122
|
+
)
|
|
123
|
+
layout.addWidget(desc_label)
|
|
124
|
+
|
|
125
|
+
def matches_search(self, text: str) -> bool:
|
|
126
|
+
return text in self._search_text
|
|
127
|
+
|
|
128
|
+
def _update_status_badge(self) -> None:
|
|
129
|
+
is_default = kitty_conf.is_default_value(self.widget.value(), self._setting)
|
|
130
|
+
self._reset_button.setVisible(not is_default)
|
|
131
|
+
if is_default:
|
|
132
|
+
self._status_badge.setText(_("default"))
|
|
133
|
+
self._status_badge.setStyleSheet(
|
|
134
|
+
"font-size: 10px; padding: 1px 6px; color: #6b7280;"
|
|
135
|
+
)
|
|
136
|
+
else:
|
|
137
|
+
self._status_badge.setText(_("modified"))
|
|
138
|
+
self._status_badge.setStyleSheet(
|
|
139
|
+
"font-size: 10px; padding: 1px 6px; color: #b45309; font-weight: 600;"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def _reset_to_default(self) -> None:
|
|
143
|
+
self.set_value(kitty_conf.default_value(self._setting))
|
|
144
|
+
|
|
145
|
+
def set_value(self, value: str | list[str]) -> None:
|
|
146
|
+
self.widget.set_value(value)
|
|
147
|
+
self._update_status_badge()
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class MainWindow(QMainWindow):
|
|
151
|
+
def __init__(
|
|
152
|
+
self, config_path: Path | None = None, parent: QWidget | None = None
|
|
153
|
+
) -> None:
|
|
154
|
+
super().__init__(parent)
|
|
155
|
+
self._config_path = config_path or kitty_conf.default_config_path()
|
|
156
|
+
self._schema = load_schema()
|
|
157
|
+
self._rows: dict[str, _SettingRow] = {}
|
|
158
|
+
self._sidebar_categories: list[tuple[QListWidgetItem, dict]] = []
|
|
159
|
+
|
|
160
|
+
self.setWindowTitle(_("PBKittyConfigStudio"))
|
|
161
|
+
self.resize(1200, 800)
|
|
162
|
+
|
|
163
|
+
self._build_ui()
|
|
164
|
+
self._build_menu()
|
|
165
|
+
self._load_config()
|
|
166
|
+
|
|
167
|
+
# -- UI construction ----------------------------------------------------
|
|
168
|
+
|
|
169
|
+
def _build_ui(self) -> None:
|
|
170
|
+
central = QWidget()
|
|
171
|
+
self.setCentralWidget(central)
|
|
172
|
+
root = QVBoxLayout(central)
|
|
173
|
+
|
|
174
|
+
body = QHBoxLayout()
|
|
175
|
+
root.addLayout(body, 1)
|
|
176
|
+
|
|
177
|
+
sidebar_box = QVBoxLayout()
|
|
178
|
+
self._search_edit = QLineEdit()
|
|
179
|
+
self._search_edit.setPlaceholderText(_("Search settings…"))
|
|
180
|
+
self._search_edit.textChanged.connect(self._on_search_changed)
|
|
181
|
+
sidebar_box.addWidget(self._search_edit)
|
|
182
|
+
|
|
183
|
+
self._sidebar = QListWidget()
|
|
184
|
+
self._sidebar.setFixedWidth(240)
|
|
185
|
+
self._sidebar.currentRowChanged.connect(self._on_category_changed)
|
|
186
|
+
sidebar_box.addWidget(self._sidebar, 1)
|
|
187
|
+
body.addLayout(sidebar_box)
|
|
188
|
+
|
|
189
|
+
self._pages = QStackedWidget()
|
|
190
|
+
body.addWidget(self._pages, 1)
|
|
191
|
+
|
|
192
|
+
for group in self._schema["groups"]:
|
|
193
|
+
title_text = group["title"]
|
|
194
|
+
item = QListWidgetItem(f"{group.get('icon', '')} {_(title_text)}")
|
|
195
|
+
item.setData(Qt.ItemDataRole.UserRole, group)
|
|
196
|
+
self._sidebar.addItem(item)
|
|
197
|
+
self._sidebar_categories.append((item, group))
|
|
198
|
+
self._pages.addWidget(self._build_category_page(group))
|
|
199
|
+
|
|
200
|
+
if self._sidebar.count():
|
|
201
|
+
self._sidebar.setCurrentRow(0)
|
|
202
|
+
|
|
203
|
+
footer = QHBoxLayout()
|
|
204
|
+
self._count_label = QLabel()
|
|
205
|
+
footer.addWidget(self._count_label)
|
|
206
|
+
footer.addStretch(1)
|
|
207
|
+
self._file_path_label = QLabel()
|
|
208
|
+
self._file_path_label.setStyleSheet("color: #6b7280;")
|
|
209
|
+
footer.addWidget(self._file_path_label)
|
|
210
|
+
root.addLayout(footer)
|
|
211
|
+
|
|
212
|
+
self.setStatusBar(QStatusBar())
|
|
213
|
+
self._set_status(_("Ready"))
|
|
214
|
+
|
|
215
|
+
def _build_category_page(self, group: dict) -> QWidget:
|
|
216
|
+
scroll = QScrollArea()
|
|
217
|
+
scroll.setWidgetResizable(True)
|
|
218
|
+
|
|
219
|
+
content = QWidget()
|
|
220
|
+
layout = QVBoxLayout(content)
|
|
221
|
+
self._add_group_rows(layout, group)
|
|
222
|
+
layout.addStretch(1)
|
|
223
|
+
|
|
224
|
+
scroll.setWidget(content)
|
|
225
|
+
return scroll
|
|
226
|
+
|
|
227
|
+
def _add_group_rows(self, layout: QVBoxLayout, group: dict) -> None:
|
|
228
|
+
for setting in group["options"]:
|
|
229
|
+
row = _SettingRow(setting["name"], setting)
|
|
230
|
+
self._rows[setting["name"]] = row
|
|
231
|
+
layout.addWidget(row)
|
|
232
|
+
|
|
233
|
+
for subgroup in group["subgroups"]:
|
|
234
|
+
if not _has_options(subgroup):
|
|
235
|
+
continue
|
|
236
|
+
subgroup_title_text = subgroup["title"]
|
|
237
|
+
box = QGroupBox(_(subgroup_title_text))
|
|
238
|
+
box_layout = QVBoxLayout(box)
|
|
239
|
+
self._add_group_rows(box_layout, subgroup)
|
|
240
|
+
layout.addWidget(box)
|
|
241
|
+
|
|
242
|
+
def _build_menu(self) -> None:
|
|
243
|
+
file_menu = self.menuBar().addMenu(_("&File"))
|
|
244
|
+
|
|
245
|
+
save_action = self._add_action(
|
|
246
|
+
file_menu,
|
|
247
|
+
save_icon_path(),
|
|
248
|
+
_("&Save"),
|
|
249
|
+
QKeySequence.StandardKey.Save,
|
|
250
|
+
)
|
|
251
|
+
save_action.triggered.connect(self._on_save)
|
|
252
|
+
|
|
253
|
+
save_as_action = self._add_action(
|
|
254
|
+
file_menu,
|
|
255
|
+
save_as_icon_path(),
|
|
256
|
+
_("Save &As…"),
|
|
257
|
+
QKeySequence.StandardKey.SaveAs,
|
|
258
|
+
)
|
|
259
|
+
save_as_action.triggered.connect(self._on_save_as)
|
|
260
|
+
|
|
261
|
+
file_menu.addSeparator()
|
|
262
|
+
|
|
263
|
+
reload_action = self._add_action(
|
|
264
|
+
file_menu,
|
|
265
|
+
refresh_icon_path(),
|
|
266
|
+
_("&Reread File"),
|
|
267
|
+
QKeySequence.StandardKey.Refresh,
|
|
268
|
+
)
|
|
269
|
+
reload_action.triggered.connect(self._load_config)
|
|
270
|
+
|
|
271
|
+
file_menu.addSeparator()
|
|
272
|
+
|
|
273
|
+
restore_defaults_action = self._add_action(
|
|
274
|
+
file_menu,
|
|
275
|
+
clear_config_icon_path(),
|
|
276
|
+
_("Restore &Default Configuration…"),
|
|
277
|
+
)
|
|
278
|
+
restore_defaults_action.setEnabled(kitty_conf.kitty_available())
|
|
279
|
+
restore_defaults_action.triggered.connect(self._on_restore_defaults)
|
|
280
|
+
|
|
281
|
+
file_menu.addSeparator()
|
|
282
|
+
|
|
283
|
+
quit_action = self._add_action(
|
|
284
|
+
file_menu,
|
|
285
|
+
quit_icon_path(),
|
|
286
|
+
_("&Quit"),
|
|
287
|
+
QKeySequence.StandardKey.Quit,
|
|
288
|
+
)
|
|
289
|
+
quit_action.triggered.connect(self.close)
|
|
290
|
+
|
|
291
|
+
lang_menu = self.menuBar().addMenu(_("&Language"))
|
|
292
|
+
self._build_language_menu(lang_menu)
|
|
293
|
+
|
|
294
|
+
help_menu = self.menuBar().addMenu(_("&Help"))
|
|
295
|
+
|
|
296
|
+
docs_action = help_menu.addAction(_("kitty &Documentation"))
|
|
297
|
+
docs_action.triggered.connect(lambda: self._open_url(_KITTY_DOCS_URL))
|
|
298
|
+
|
|
299
|
+
options_action = help_menu.addAction(_("kitty &Options Reference"))
|
|
300
|
+
options_action.triggered.connect(lambda: self._open_url(_KITTY_OPTIONS_URL))
|
|
301
|
+
|
|
302
|
+
help_menu.addSeparator()
|
|
303
|
+
|
|
304
|
+
about_action = self._add_action(help_menu, help_about_icon_path(), _("&About"))
|
|
305
|
+
about_action.triggered.connect(self._on_about)
|
|
306
|
+
|
|
307
|
+
def _add_action(
|
|
308
|
+
self,
|
|
309
|
+
menu: QMenu,
|
|
310
|
+
icon_path: Path | None,
|
|
311
|
+
text: str,
|
|
312
|
+
shortcut: QKeySequence.StandardKey | None = None,
|
|
313
|
+
) -> QAction:
|
|
314
|
+
action = QAction(QIcon(str(icon_path)) if icon_path else QIcon(), text, self)
|
|
315
|
+
if shortcut is not None:
|
|
316
|
+
action.setShortcut(QKeySequence(shortcut))
|
|
317
|
+
menu.addAction(action)
|
|
318
|
+
return action
|
|
319
|
+
|
|
320
|
+
def _build_language_menu(self, menu: QMenu) -> None:
|
|
321
|
+
current = i18n.get_language_override()
|
|
322
|
+
|
|
323
|
+
def make_setter(code: str):
|
|
324
|
+
def _set() -> None:
|
|
325
|
+
i18n.set_language_override(code)
|
|
326
|
+
QMessageBox.information(
|
|
327
|
+
self,
|
|
328
|
+
_("Language changed"),
|
|
329
|
+
_(
|
|
330
|
+
"Restart PBKittyConfigStudio for the new language to take"
|
|
331
|
+
" effect."
|
|
332
|
+
),
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
return _set
|
|
336
|
+
|
|
337
|
+
group = QActionGroup(menu)
|
|
338
|
+
group.setExclusive(True)
|
|
339
|
+
|
|
340
|
+
system_action = menu.addAction(_("System default"))
|
|
341
|
+
system_action.setCheckable(True)
|
|
342
|
+
system_action.setChecked(current == "")
|
|
343
|
+
system_action.triggered.connect(make_setter(""))
|
|
344
|
+
group.addAction(system_action)
|
|
345
|
+
|
|
346
|
+
menu.addSeparator()
|
|
347
|
+
for code, name in i18n.available_languages():
|
|
348
|
+
action = menu.addAction(name)
|
|
349
|
+
action.setCheckable(True)
|
|
350
|
+
action.setChecked(current == code)
|
|
351
|
+
action.triggered.connect(make_setter(code))
|
|
352
|
+
group.addAction(action)
|
|
353
|
+
|
|
354
|
+
# -- Search ---------------------------------------------------------------
|
|
355
|
+
|
|
356
|
+
def _on_search_changed(self, text: str) -> None:
|
|
357
|
+
needle = text.strip().lower()
|
|
358
|
+
for item, group in self._sidebar_categories:
|
|
359
|
+
category_has_match = False
|
|
360
|
+
for setting in self._iter_group_settings(group):
|
|
361
|
+
row = self._rows[setting["name"]]
|
|
362
|
+
visible = not needle or row.matches_search(needle)
|
|
363
|
+
row.setVisible(visible)
|
|
364
|
+
category_has_match = category_has_match or visible
|
|
365
|
+
item.setHidden(not category_has_match)
|
|
366
|
+
|
|
367
|
+
current = self._sidebar.currentItem()
|
|
368
|
+
if current is None or current.isHidden():
|
|
369
|
+
for row in range(self._sidebar.count()):
|
|
370
|
+
if not self._sidebar.item(row).isHidden():
|
|
371
|
+
self._sidebar.setCurrentRow(row)
|
|
372
|
+
break
|
|
373
|
+
|
|
374
|
+
@staticmethod
|
|
375
|
+
def _iter_group_settings(group: dict):
|
|
376
|
+
yield from group["options"]
|
|
377
|
+
for subgroup in group["subgroups"]:
|
|
378
|
+
yield from MainWindow._iter_group_settings(subgroup)
|
|
379
|
+
|
|
380
|
+
# -- Config I/O -----------------------------------------------------------
|
|
381
|
+
|
|
382
|
+
def _load_config(self) -> None:
|
|
383
|
+
raw = kitty_conf.read_raw(self._config_path)
|
|
384
|
+
values = kitty_conf.parse_config(raw, self._schema)
|
|
385
|
+
for key, row in self._rows.items():
|
|
386
|
+
row.set_value(values.get(key, ""))
|
|
387
|
+
self._count_label.setText(
|
|
388
|
+
_("{count} settings loaded").format(count=len(self._rows))
|
|
389
|
+
)
|
|
390
|
+
self._file_path_label.setText(str(self._config_path))
|
|
391
|
+
self._set_status(_("Ready"))
|
|
392
|
+
|
|
393
|
+
def _on_save(self) -> None:
|
|
394
|
+
self._save_to(self._config_path)
|
|
395
|
+
|
|
396
|
+
def _on_save_as(self) -> None:
|
|
397
|
+
path_str, _filter = QFileDialog.getSaveFileName(
|
|
398
|
+
self, _("Save As"), str(self._config_path)
|
|
399
|
+
)
|
|
400
|
+
if not path_str:
|
|
401
|
+
return
|
|
402
|
+
path = Path(path_str)
|
|
403
|
+
self._save_to(path)
|
|
404
|
+
self._config_path = path
|
|
405
|
+
self._file_path_label.setText(str(self._config_path))
|
|
406
|
+
|
|
407
|
+
def _save_to(self, path: Path) -> None:
|
|
408
|
+
self._set_status(_("Synchronizing…"))
|
|
409
|
+
try:
|
|
410
|
+
settings = {
|
|
411
|
+
key: self._current_value(row) for key, row in self._rows.items()
|
|
412
|
+
}
|
|
413
|
+
kitty_conf.backup(path)
|
|
414
|
+
raw = kitty_conf.read_raw(path)
|
|
415
|
+
new_text = kitty_conf.apply_settings(raw, settings, self._schema)
|
|
416
|
+
kitty_conf.write_config(path, new_text)
|
|
417
|
+
reloaded = kitty_conf.reload_kitty()
|
|
418
|
+
except OSError as exc:
|
|
419
|
+
_log.exception("Failed to save kitty.conf")
|
|
420
|
+
self._set_status(_("Save failed: {error}").format(error=exc))
|
|
421
|
+
QMessageBox.critical(self, _("Save failed"), str(exc))
|
|
422
|
+
return
|
|
423
|
+
|
|
424
|
+
self._set_status(
|
|
425
|
+
_("Config saved and reloaded")
|
|
426
|
+
if reloaded
|
|
427
|
+
else _("Config saved (reload kitty manually)")
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
def _on_restore_defaults(self) -> None:
|
|
431
|
+
answer = QMessageBox.warning(
|
|
432
|
+
self,
|
|
433
|
+
_("Restore Default Configuration"),
|
|
434
|
+
_(
|
|
435
|
+
"This will overwrite {path} with kitty's own pristine,"
|
|
436
|
+
" fully-commented example configuration, discarding every"
|
|
437
|
+
" setting currently in this file. A timestamped backup is"
|
|
438
|
+
" made first, but this cannot be undone from within"
|
|
439
|
+
" PBKittyConfigStudio.\n\nContinue?"
|
|
440
|
+
).format(path=self._config_path),
|
|
441
|
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
|
442
|
+
QMessageBox.StandardButton.No,
|
|
443
|
+
)
|
|
444
|
+
if answer != QMessageBox.StandardButton.Yes:
|
|
445
|
+
return
|
|
446
|
+
|
|
447
|
+
self._set_status(_("Generating default configuration…"))
|
|
448
|
+
try:
|
|
449
|
+
default_text = kitty_conf.generate_default_config()
|
|
450
|
+
kitty_conf.backup(self._config_path)
|
|
451
|
+
kitty_conf.write_config(self._config_path, default_text)
|
|
452
|
+
except (OSError, subprocess.SubprocessError, RuntimeError) as exc:
|
|
453
|
+
_log.exception("Failed to restore default kitty.conf")
|
|
454
|
+
self._set_status(_("Restore failed: {error}").format(error=exc))
|
|
455
|
+
QMessageBox.critical(self, _("Restore failed"), str(exc))
|
|
456
|
+
return
|
|
457
|
+
|
|
458
|
+
self._load_config()
|
|
459
|
+
self._set_status(_("Default configuration restored"))
|
|
460
|
+
|
|
461
|
+
@staticmethod
|
|
462
|
+
def _current_value(row: _SettingRow) -> str | list[str]:
|
|
463
|
+
return row.widget.value()
|
|
464
|
+
|
|
465
|
+
def _set_status(self, text: str) -> None:
|
|
466
|
+
self.statusBar().showMessage(text)
|
|
467
|
+
|
|
468
|
+
def _on_about(self) -> None:
|
|
469
|
+
AboutDialog(self).exec()
|
|
470
|
+
|
|
471
|
+
@staticmethod
|
|
472
|
+
def _open_url(url: str) -> None:
|
|
473
|
+
QDesktopServices.openUrl(QUrl(url))
|
|
474
|
+
|
|
475
|
+
def _on_category_changed(self, row: int) -> None:
|
|
476
|
+
if row >= 0:
|
|
477
|
+
self._pages.setCurrentIndex(row)
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def try_load_main_window(config_path: Path | None = None) -> MainWindow:
|
|
481
|
+
"""Build the ``MainWindow``, turning a not-yet-curated schema into a
|
|
482
|
+
clear, actionable startup error instead of a stack trace.
|
|
483
|
+
"""
|
|
484
|
+
try:
|
|
485
|
+
return MainWindow(config_path=config_path)
|
|
486
|
+
except SchemaNotCuratedError as exc:
|
|
487
|
+
import sys
|
|
488
|
+
|
|
489
|
+
print(str(exc), file=sys.stderr)
|
|
490
|
+
QMessageBox.critical(None, _("Schema not curated"), str(exc))
|
|
491
|
+
raise SystemExit(1) from exc
|