dynamic-settings-widget 2.0.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.
- dynamic_settings_widget/__init__.py +56 -0
- dynamic_settings_widget/adapters/__init__.py +42 -0
- dynamic_settings_widget/adapters/base.py +179 -0
- dynamic_settings_widget/adapters/memory.py +201 -0
- dynamic_settings_widget/adapters/runner.py +63 -0
- dynamic_settings_widget/core/__init__.py +1 -0
- dynamic_settings_widget/core/catalog.py +201 -0
- dynamic_settings_widget/core/common.py +214 -0
- dynamic_settings_widget/core/conditions.py +146 -0
- dynamic_settings_widget/core/datatypes.py +414 -0
- dynamic_settings_widget/core/diagnostics.py +69 -0
- dynamic_settings_widget/core/loader.py +101 -0
- dynamic_settings_widget/core/model.py +245 -0
- dynamic_settings_widget/core/overrides.py +353 -0
- dynamic_settings_widget/core/parser.py +552 -0
- dynamic_settings_widget/core/presentation.py +68 -0
- dynamic_settings_widget/core/registry.py +258 -0
- dynamic_settings_widget/core/state.py +314 -0
- dynamic_settings_widget/data/example_catalog.json +23 -0
- dynamic_settings_widget/data/example_layout.json +23 -0
- dynamic_settings_widget/data/settings_catalog.schema.json +388 -0
- dynamic_settings_widget/data/settings_definition.schema.json +1041 -0
- dynamic_settings_widget/data/settings_layout.schema.json +701 -0
- dynamic_settings_widget/data/settings_override.schema.json +406 -0
- dynamic_settings_widget/py.typed +0 -0
- dynamic_settings_widget/session.py +1537 -0
- dynamic_settings_widget/standalone/__init__.py +67 -0
- dynamic_settings_widget/standalone/action_button.py +200 -0
- dynamic_settings_widget/standalone/auth_widget.py +377 -0
- dynamic_settings_widget/standalone/check_box_editor.py +233 -0
- dynamic_settings_widget/standalone/choice_buttons_editor.py +394 -0
- dynamic_settings_widget/standalone/color_editor.py +316 -0
- dynamic_settings_widget/standalone/dropdown_editor.py +356 -0
- dynamic_settings_widget/standalone/editable_label.py +428 -0
- dynamic_settings_widget/standalone/float_spin_box.py +621 -0
- dynamic_settings_widget/standalone/font_editor.py +348 -0
- dynamic_settings_widget/standalone/hotkey_editor.py +681 -0
- dynamic_settings_widget/standalone/info_label.py +190 -0
- dynamic_settings_widget/standalone/int_spin_box.py +627 -0
- dynamic_settings_widget/standalone/multi_choice_editor.py +428 -0
- dynamic_settings_widget/standalone/password_editor.py +348 -0
- dynamic_settings_widget/standalone/path_editor.py +615 -0
- dynamic_settings_widget/standalone/protected_group_box.py +287 -0
- dynamic_settings_widget/standalone/server_connection_editor.py +642 -0
- dynamic_settings_widget/standalone/slider_spin_box.py +840 -0
- dynamic_settings_widget/standalone/sound_selection_widget.py +710 -0
- dynamic_settings_widget/standalone/status_label.py +148 -0
- dynamic_settings_widget/standalone/switch_editor.py +293 -0
- dynamic_settings_widget/standalone/text_editor.py +265 -0
- dynamic_settings_widget/testlab/__init__.py +1 -0
- dynamic_settings_widget/testlab/__main__.py +5 -0
- dynamic_settings_widget/testlab/app.py +699 -0
- dynamic_settings_widget/testlab/assets/extra_sounds/Signal.wav +0 -0
- dynamic_settings_widget/testlab/assets/sounds/Benachrichtigung.wav +0 -0
- dynamic_settings_widget/testlab/assets/sounds/feedback/Signal.wav +0 -0
- dynamic_settings_widget/testlab/definitions/broken_base.json +25 -0
- dynamic_settings_widget/testlab/definitions/demo.json +634 -0
- dynamic_settings_widget/testlab/definitions/gallery.json +255 -0
- dynamic_settings_widget/testlab/definitions/override_example.json +41 -0
- dynamic_settings_widget/testlab/definitions/override_invalid.json +11 -0
- dynamic_settings_widget/testlab/definitions/override_syntax_error.json +5 -0
- dynamic_settings_widget/testlab/definitions/override_weaken.json +10 -0
- dynamic_settings_widget/testlab/definitions/voice_v2/01_left_top.json +1190 -0
- dynamic_settings_widget/testlab/definitions/voice_v2/catalog.json +1930 -0
- dynamic_settings_widget/testlab/definitions/voice_v2/models.json +141 -0
- dynamic_settings_widget/testlab/definitions/voice_v2/wakewords.json +161 -0
- dynamic_settings_widget/testlab/dummy.py +353 -0
- dynamic_settings_widget/testlab/extensions.py +149 -0
- dynamic_settings_widget/testlab/gallery.py +223 -0
- dynamic_settings_widget/testlab/http_adapter.py +430 -0
- dynamic_settings_widget/testlab/http_server.py +493 -0
- dynamic_settings_widget/testlab/voice_v2.py +251 -0
- dynamic_settings_widget/ui/__init__.py +23 -0
- dynamic_settings_widget/ui/base.py +63 -0
- dynamic_settings_widget/ui/builders.py +226 -0
- dynamic_settings_widget/ui/containers.py +441 -0
- dynamic_settings_widget/ui/dialog.py +231 -0
- dynamic_settings_widget/ui/editing.py +51 -0
- dynamic_settings_widget/ui/row.py +810 -0
- dynamic_settings_widget/ui/view.py +248 -0
- dynamic_settings_widget/widgets/__init__.py +74 -0
- dynamic_settings_widget/widgets/base.py +145 -0
- dynamic_settings_widget/widgets/bridge.py +222 -0
- dynamic_settings_widget/widgets/theme.py +107 -0
- dynamic_settings_widget-2.0.0.dist-info/METADATA +237 -0
- dynamic_settings_widget-2.0.0.dist-info/RECORD +90 -0
- dynamic_settings_widget-2.0.0.dist-info/WHEEL +5 -0
- dynamic_settings_widget-2.0.0.dist-info/entry_points.txt +5 -0
- dynamic_settings_widget-2.0.0.dist-info/licenses/LICENSE +21 -0
- dynamic_settings_widget-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"""Renderer: erzeugt aus einer Sitzung die vollständige Oberfläche."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import replace
|
|
6
|
+
|
|
7
|
+
from PySide6.QtCore import QTimer, Qt, Signal
|
|
8
|
+
from PySide6.QtWidgets import QApplication, QMessageBox, QScrollArea, QVBoxLayout, QWidget
|
|
9
|
+
|
|
10
|
+
from ..core.model import Element
|
|
11
|
+
from ..core.presentation import MODES, resolve_presentation
|
|
12
|
+
from ..core.registry import TypeRegistry
|
|
13
|
+
from ..core.state import Status
|
|
14
|
+
from ..session import SettingsSession
|
|
15
|
+
from .base import BuildContext, ContainerWidget, ElementWidget
|
|
16
|
+
from .editing import EditCoordinator
|
|
17
|
+
from .row import SettingRow
|
|
18
|
+
|
|
19
|
+
_PROBLEMS = (Status.INVALID, Status.REJECTED, Status.CONFLICT, Status.UNKNOWN)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SettingsView(QWidget):
|
|
23
|
+
"""Rendert den Elementbaum. Der Renderer kennt keine konkreten Typen, nur das Register."""
|
|
24
|
+
|
|
25
|
+
element_built = Signal(str)
|
|
26
|
+
|
|
27
|
+
def __init__(self, session: SettingsSession, registry: TypeRegistry, parent: QWidget | None = None) -> None:
|
|
28
|
+
super().__init__(parent)
|
|
29
|
+
self.session = session
|
|
30
|
+
self.registry = registry
|
|
31
|
+
self.widgets: dict[str, QWidget] = {}
|
|
32
|
+
self._containers: dict[str, ContainerWidget] = {}
|
|
33
|
+
self.edit_coordinator = EditCoordinator()
|
|
34
|
+
self._presentation_mode = None
|
|
35
|
+
missing = [
|
|
36
|
+
t.name
|
|
37
|
+
for t in (registry.elements[e.type] for e in session.tree.walk())
|
|
38
|
+
if t.builder is None
|
|
39
|
+
]
|
|
40
|
+
if missing:
|
|
41
|
+
raise ValueError(f"Keine Bauvorschrift für: {', '.join(sorted(set(missing)))}")
|
|
42
|
+
layout = QVBoxLayout(self)
|
|
43
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
44
|
+
self.root_widget = self._build(session.tree.root)
|
|
45
|
+
layout.addWidget(self.root_widget)
|
|
46
|
+
for element in session.tree.walk():
|
|
47
|
+
self._apply_access(element)
|
|
48
|
+
self._badge_timer = QTimer(self)
|
|
49
|
+
self._badge_timer.setSingleShot(True)
|
|
50
|
+
self._badge_timer.timeout.connect(self._update_badges)
|
|
51
|
+
|
|
52
|
+
session.state_changed.connect(self._on_state)
|
|
53
|
+
session.access_changed.connect(self._on_access)
|
|
54
|
+
session.choices_changed.connect(self._on_choices)
|
|
55
|
+
session.constraints_changed.connect(self._on_constraints)
|
|
56
|
+
session.structure_changed.connect(self._on_structure)
|
|
57
|
+
session.auth_changed.connect(self._on_auth)
|
|
58
|
+
session.adapter_status_changed.connect(self._on_adapter_status)
|
|
59
|
+
session.action_changed.connect(self._on_action)
|
|
60
|
+
QApplication.instance().focusChanged.connect(self._on_focus_changed)
|
|
61
|
+
self._update_badges()
|
|
62
|
+
|
|
63
|
+
def _on_focus_changed(self, old: QWidget | None, new: QWidget | None) -> None:
|
|
64
|
+
rows = set()
|
|
65
|
+
for widget in (old, new):
|
|
66
|
+
while widget is not None and not isinstance(widget, SettingRow):
|
|
67
|
+
widget = widget.parentWidget()
|
|
68
|
+
if isinstance(widget, SettingRow) and widget.context.view is self:
|
|
69
|
+
rows.add(widget)
|
|
70
|
+
for row in rows:
|
|
71
|
+
row.update_description()
|
|
72
|
+
|
|
73
|
+
# -- Aufbau ----------------------------------------------------------------------------
|
|
74
|
+
def _build(self, element: Element) -> QWidget:
|
|
75
|
+
element_type = self.registry.elements[element.type]
|
|
76
|
+
widget = element_type.builder(BuildContext(self, element))
|
|
77
|
+
self.widgets[element.id] = widget
|
|
78
|
+
widget.setObjectName(element.id)
|
|
79
|
+
if element.is_container:
|
|
80
|
+
if not isinstance(widget, ContainerWidget):
|
|
81
|
+
raise TypeError(f"Bauvorschrift für Container {element.type!r} muss ein ContainerWidget liefern")
|
|
82
|
+
self._containers[element.id] = widget
|
|
83
|
+
for child in element.children:
|
|
84
|
+
widget.add_child(child, self._build(child))
|
|
85
|
+
self.element_built.emit(element.id)
|
|
86
|
+
return widget
|
|
87
|
+
|
|
88
|
+
def _forget(self, element_id: str) -> None:
|
|
89
|
+
widget = self.widgets.pop(element_id, None)
|
|
90
|
+
self._containers.pop(element_id, None)
|
|
91
|
+
if isinstance(widget, SettingRow):
|
|
92
|
+
widget.abort_edit()
|
|
93
|
+
if widget is not None:
|
|
94
|
+
widget.deleteLater()
|
|
95
|
+
|
|
96
|
+
def presentation_for(self, element: Element):
|
|
97
|
+
presentation = resolve_presentation(self.session.tree, element)
|
|
98
|
+
if self._presentation_mode is not None:
|
|
99
|
+
return replace(presentation, editor_mode=self._presentation_mode, show_edit_button=True)
|
|
100
|
+
return presentation
|
|
101
|
+
|
|
102
|
+
def set_presentation_mode(self, mode: str | None) -> None:
|
|
103
|
+
"""Vergleicht alle Zeilen der Ansicht in einem Modus. None nutzt die Definition."""
|
|
104
|
+
if mode is not None and mode not in MODES:
|
|
105
|
+
raise ValueError(f"Unbekannter Darstellungsmodus {mode!r}")
|
|
106
|
+
self._presentation_mode = mode
|
|
107
|
+
for row in self.widgets.values():
|
|
108
|
+
if isinstance(row, SettingRow):
|
|
109
|
+
row.set_presentation(self.presentation_for(row.element))
|
|
110
|
+
|
|
111
|
+
def _on_structure(self, container_id: str) -> None:
|
|
112
|
+
"""Erneuert die aus Metadaten erzeugten Kinder einer Auffanggruppe."""
|
|
113
|
+
container = self._containers.get(container_id)
|
|
114
|
+
if container is None:
|
|
115
|
+
return
|
|
116
|
+
element = self.session.tree.by_id[container_id]
|
|
117
|
+
auto = {c.id: c for c in element.children if c.origin == "metadata"}
|
|
118
|
+
for element_id in [i for i in self.widgets if i.startswith("auto.")]:
|
|
119
|
+
widget = self.widgets[element_id]
|
|
120
|
+
if getattr(widget, "element", None) is not None and widget.element.parent is element:
|
|
121
|
+
container.remove_child(element_id, widget)
|
|
122
|
+
self._forget(element_id)
|
|
123
|
+
for child in auto.values():
|
|
124
|
+
container.add_child(child, self._build(child))
|
|
125
|
+
self._apply_access(child)
|
|
126
|
+
self._update_badges()
|
|
127
|
+
|
|
128
|
+
# -- Signale der Sitzung -----------------------------------------------------------------
|
|
129
|
+
def _on_state(self, element_id: str) -> None:
|
|
130
|
+
widget = self.widgets.get(element_id)
|
|
131
|
+
if isinstance(widget, ElementWidget):
|
|
132
|
+
widget.refresh()
|
|
133
|
+
self._badge_timer.start(0)
|
|
134
|
+
|
|
135
|
+
def _apply_access(self, element: Element) -> None:
|
|
136
|
+
widget = self.widgets.get(element.id)
|
|
137
|
+
if widget is None:
|
|
138
|
+
return
|
|
139
|
+
access = self.session.access(element)
|
|
140
|
+
if isinstance(widget, ElementWidget):
|
|
141
|
+
widget.apply_access(access)
|
|
142
|
+
elif not element.is_container:
|
|
143
|
+
widget.setEnabled(access.editable)
|
|
144
|
+
if element.parent is not None:
|
|
145
|
+
parent = self._containers.get(element.parent.id)
|
|
146
|
+
if parent is not None:
|
|
147
|
+
parent.set_child_visible(element.id, widget, access.visible)
|
|
148
|
+
else:
|
|
149
|
+
widget.setVisible(access.visible)
|
|
150
|
+
|
|
151
|
+
def _on_access(self, element_id: str) -> None:
|
|
152
|
+
element = self.session.tree.by_id.get(element_id)
|
|
153
|
+
if element is not None:
|
|
154
|
+
self._apply_access(element)
|
|
155
|
+
for target in self.session.tree.walk():
|
|
156
|
+
if target.source and target.source.get("action_result") == element_id:
|
|
157
|
+
self.widgets[target.id].refresh()
|
|
158
|
+
self._badge_timer.start(0)
|
|
159
|
+
|
|
160
|
+
def _on_choices(self, element_id: str) -> None:
|
|
161
|
+
widget = self.widgets.get(element_id)
|
|
162
|
+
if isinstance(widget, SettingRow):
|
|
163
|
+
widget.update_choices()
|
|
164
|
+
widget.refresh()
|
|
165
|
+
|
|
166
|
+
def _on_constraints(self, element_id: str) -> None:
|
|
167
|
+
widget = self.widgets.get(element_id)
|
|
168
|
+
if isinstance(widget, SettingRow):
|
|
169
|
+
widget.update_constraints()
|
|
170
|
+
widget.refresh()
|
|
171
|
+
|
|
172
|
+
def _on_auth(self, adapter: str, scope: str) -> None:
|
|
173
|
+
# Auch verschachtelte Authentifizierungsbereiche hängen von äußeren Sperren ab.
|
|
174
|
+
for element in self.session.tree.walk():
|
|
175
|
+
widget = self.widgets.get(element.id)
|
|
176
|
+
if element.auth is not None and isinstance(widget, ElementWidget):
|
|
177
|
+
widget.refresh()
|
|
178
|
+
|
|
179
|
+
def _on_adapter_status(self, adapter: str) -> None:
|
|
180
|
+
for element in self.session.tree.walk():
|
|
181
|
+
if element.source and element.source.get("adapter_status") == adapter:
|
|
182
|
+
widget = self.widgets.get(element.id)
|
|
183
|
+
if isinstance(widget, ElementWidget):
|
|
184
|
+
widget.refresh()
|
|
185
|
+
|
|
186
|
+
def _on_action(self, element_id: str) -> None:
|
|
187
|
+
widget = self.widgets.get(element_id)
|
|
188
|
+
if widget is not None and hasattr(widget, "action_changed"):
|
|
189
|
+
widget.action_changed()
|
|
190
|
+
for element in self.session.tree.walk():
|
|
191
|
+
if element.source and element.source.get("action_result") == element_id:
|
|
192
|
+
target = self.widgets.get(element.id)
|
|
193
|
+
if isinstance(target, ElementWidget):
|
|
194
|
+
target.refresh()
|
|
195
|
+
|
|
196
|
+
# -- Marken und Navigation -------------------------------------------------------------------
|
|
197
|
+
def badge(self, element: Element) -> str:
|
|
198
|
+
"""Textmarke für Register: ⚠ bei Problemen, ● bei Änderungen."""
|
|
199
|
+
changed = False
|
|
200
|
+
for child in element.walk():
|
|
201
|
+
if not child.is_setting or not self.session.access(child).visible:
|
|
202
|
+
continue
|
|
203
|
+
state = self.session.state(child)
|
|
204
|
+
if state.status in _PROBLEMS:
|
|
205
|
+
return " ⚠"
|
|
206
|
+
changed = changed or state.has_draft
|
|
207
|
+
return " ●" if changed else ""
|
|
208
|
+
|
|
209
|
+
def _update_badges(self) -> None:
|
|
210
|
+
for container in self._containers.values():
|
|
211
|
+
container.update_badges()
|
|
212
|
+
|
|
213
|
+
def navigate_to(self, reference: str) -> bool:
|
|
214
|
+
"""Zeigt ein Element (ID oder Layoutpfad), öffnet dazu Register und Gruppen."""
|
|
215
|
+
element = self.session.tree.find(reference)
|
|
216
|
+
if element is None or element.id not in self.widgets or not self.session.access(element).visible:
|
|
217
|
+
return False
|
|
218
|
+
chain = [element, *element.ancestors()]
|
|
219
|
+
for child, parent in zip(chain, chain[1:]):
|
|
220
|
+
container = self._containers.get(parent.id)
|
|
221
|
+
if container is not None:
|
|
222
|
+
container.reveal_child(child.id)
|
|
223
|
+
widget = self.widgets[element.id]
|
|
224
|
+
node = widget.parentWidget()
|
|
225
|
+
while node is not None and node is not self:
|
|
226
|
+
if isinstance(node, QScrollArea):
|
|
227
|
+
node.ensureWidgetVisible(widget, 20, 40)
|
|
228
|
+
node = node.parentWidget()
|
|
229
|
+
if isinstance(widget, ElementWidget) and not element.is_container:
|
|
230
|
+
widget.focus_editor()
|
|
231
|
+
return True
|
|
232
|
+
|
|
233
|
+
def commit_editors(self) -> list[str]:
|
|
234
|
+
"""Schließt angefangene Texteingaben ab (vor Übernehmen)."""
|
|
235
|
+
invalid = []
|
|
236
|
+
for widget in self.widgets.values():
|
|
237
|
+
if isinstance(widget, SettingRow):
|
|
238
|
+
widget.commit()
|
|
239
|
+
if widget.blocks_submit():
|
|
240
|
+
invalid.append(widget.element.id)
|
|
241
|
+
return invalid
|
|
242
|
+
|
|
243
|
+
def confirm(self, text: str) -> bool:
|
|
244
|
+
box = QMessageBox(QMessageBox.Icon.Question, "Bestätigung", text, parent=self)
|
|
245
|
+
box.setTextFormat(Qt.TextFormat.PlainText)
|
|
246
|
+
box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
|
|
247
|
+
box.setDefaultButton(QMessageBox.StandardButton.No)
|
|
248
|
+
return box.exec() == QMessageBox.StandardButton.Yes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Widgets des Frameworks.
|
|
2
|
+
|
|
3
|
+
Die eigentlichen Implementierungen sind die autarken Einzeldateien in
|
|
4
|
+
``dynamic_settings_widget/standalone`` (je Datei ein Widget, nur Standardbibliothek und
|
|
5
|
+
PySide6). Hier stehen dieselben Klassen unter ihren bisherigen Namen bereit; die
|
|
6
|
+
Editoren sind um die Framework-Typen (``Constraints``, ``Option``, ``SECRET_SET``)
|
|
7
|
+
ergänzt – siehe :mod:`dynamic_settings_widget.widgets.bridge`.
|
|
8
|
+
|
|
9
|
+
``ValueEditor`` ist die Basisklasse für eigene Editoren (Erweiterungsvertrag).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from ..standalone.action_button import ActionButton
|
|
13
|
+
from ..standalone.auth_widget import AuthWidget
|
|
14
|
+
from ..standalone.choice_buttons_editor import FlowLayout
|
|
15
|
+
from ..standalone.hotkey_editor import has_modifier, normalize
|
|
16
|
+
from ..standalone.info_label import InfoLabel
|
|
17
|
+
from ..standalone.path_editor import check_path
|
|
18
|
+
from ..standalone.protected_group_box import ProtectedGroupBox
|
|
19
|
+
from ..standalone.server_connection_editor import ConnectionInputError, compose_url
|
|
20
|
+
from ..standalone.status_label import StatusLabel
|
|
21
|
+
from .base import ValueEditor
|
|
22
|
+
from .bridge import (
|
|
23
|
+
CheckBoxEditor,
|
|
24
|
+
ChoiceButtonsEditor,
|
|
25
|
+
ColorEditor,
|
|
26
|
+
DropdownEditor,
|
|
27
|
+
EditableLabel,
|
|
28
|
+
FloatSpinBox,
|
|
29
|
+
FontEditor,
|
|
30
|
+
FrameworkEditor,
|
|
31
|
+
HotkeyEditor,
|
|
32
|
+
IntSpinBox,
|
|
33
|
+
MultiChoiceEditor,
|
|
34
|
+
PasswordEditor,
|
|
35
|
+
PathEditor,
|
|
36
|
+
ServerConnectionEditor,
|
|
37
|
+
SliderSpinBox,
|
|
38
|
+
SoundSelectionWidget,
|
|
39
|
+
SwitchEditor,
|
|
40
|
+
TextEditor,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
"ActionButton",
|
|
45
|
+
"AuthWidget",
|
|
46
|
+
"CheckBoxEditor",
|
|
47
|
+
"ChoiceButtonsEditor",
|
|
48
|
+
"ColorEditor",
|
|
49
|
+
"ConnectionInputError",
|
|
50
|
+
"DropdownEditor",
|
|
51
|
+
"EditableLabel",
|
|
52
|
+
"FloatSpinBox",
|
|
53
|
+
"FlowLayout",
|
|
54
|
+
"FontEditor",
|
|
55
|
+
"FrameworkEditor",
|
|
56
|
+
"HotkeyEditor",
|
|
57
|
+
"InfoLabel",
|
|
58
|
+
"IntSpinBox",
|
|
59
|
+
"MultiChoiceEditor",
|
|
60
|
+
"PasswordEditor",
|
|
61
|
+
"PathEditor",
|
|
62
|
+
"ProtectedGroupBox",
|
|
63
|
+
"ServerConnectionEditor",
|
|
64
|
+
"SliderSpinBox",
|
|
65
|
+
"SoundSelectionWidget",
|
|
66
|
+
"StatusLabel",
|
|
67
|
+
"SwitchEditor",
|
|
68
|
+
"TextEditor",
|
|
69
|
+
"ValueEditor",
|
|
70
|
+
"check_path",
|
|
71
|
+
"compose_url",
|
|
72
|
+
"has_modifier",
|
|
73
|
+
"normalize",
|
|
74
|
+
]
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Basisklasse für eigene Editoren (Erweiterungsvertrag des Frameworks).
|
|
2
|
+
|
|
3
|
+
Die eingebauten Editoren sind autarke Einzeldateien (``dynamic_settings_widget/standalone``)
|
|
4
|
+
und erfüllen denselben Vertrag strukturell; ``StatusLabel`` wird von dort übernommen.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections.abc import Iterable
|
|
10
|
+
from contextlib import contextmanager
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from PySide6.QtCore import QEvent, QObject, Qt, Signal
|
|
14
|
+
from PySide6.QtWidgets import QWidget
|
|
15
|
+
|
|
16
|
+
from ..core.datatypes import Constraints, Option, same
|
|
17
|
+
from ..standalone.status_label import StatusLabel
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ValueEditor(QWidget):
|
|
21
|
+
"""Basisklasse: ein bearbeitbarer Wert, unabhängig von Dialog und Adapter.
|
|
22
|
+
|
|
23
|
+
* ``value()`` / ``set_value()`` – lesen und setzen; ``None`` bedeutet „nicht gesetzt“.
|
|
24
|
+
* ``value_changed`` – bei jeder Wertänderung (auch programmatisch).
|
|
25
|
+
* ``value_edited`` – nur bei Änderung durch den Benutzer.
|
|
26
|
+
* ``set_read_only()``, ``set_constraints()``, ``set_choices()`` – Konfiguration.
|
|
27
|
+
* ``input_error()`` – Grund, falls die aktuelle Eingabe keinen Wert ergibt.
|
|
28
|
+
|
|
29
|
+
``set_value`` wandelt nie still um: Ein Wert falschen Typs löst ``ValueError``
|
|
30
|
+
aus. Werte außerhalb der Grenzen werden unverändert dargestellt.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
value_changed = Signal(object)
|
|
34
|
+
value_edited = Signal(object)
|
|
35
|
+
input_error_changed = Signal(str)
|
|
36
|
+
|
|
37
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
38
|
+
super().__init__(parent)
|
|
39
|
+
self._constraints = Constraints()
|
|
40
|
+
self._read_only = False
|
|
41
|
+
self._silent = 0
|
|
42
|
+
self._last_error = ""
|
|
43
|
+
|
|
44
|
+
# -- von Unterklassen zu implementieren ----------------------------------------------
|
|
45
|
+
def value(self) -> Any:
|
|
46
|
+
raise NotImplementedError
|
|
47
|
+
|
|
48
|
+
def _apply_value(self, value: Any) -> None:
|
|
49
|
+
raise NotImplementedError
|
|
50
|
+
|
|
51
|
+
def _apply_constraints(self, constraints: Constraints) -> None:
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
def _apply_choices(self, choices: list[Option]) -> None:
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
def _apply_read_only(self, read_only: bool) -> None:
|
|
58
|
+
self.setEnabled(not read_only)
|
|
59
|
+
|
|
60
|
+
def input_error(self) -> str:
|
|
61
|
+
return ""
|
|
62
|
+
|
|
63
|
+
def commit(self) -> None:
|
|
64
|
+
"""Übernimmt eine noch nicht abgeschlossene Texteingabe."""
|
|
65
|
+
|
|
66
|
+
# -- öffentliche Schnittstelle -------------------------------------------------------
|
|
67
|
+
def set_value(self, value: Any) -> None:
|
|
68
|
+
old = self.value()
|
|
69
|
+
with self._programmatic():
|
|
70
|
+
self._apply_value(value)
|
|
71
|
+
new = self.value()
|
|
72
|
+
if not same(old, new):
|
|
73
|
+
self.value_changed.emit(new)
|
|
74
|
+
self._check_error()
|
|
75
|
+
|
|
76
|
+
def set_constraints(self, constraints: Constraints) -> None:
|
|
77
|
+
self._constraints = constraints
|
|
78
|
+
with self._programmatic():
|
|
79
|
+
self._apply_constraints(constraints)
|
|
80
|
+
if constraints.choices is not None:
|
|
81
|
+
self._apply_choices(list(constraints.choices))
|
|
82
|
+
|
|
83
|
+
def constraints(self) -> Constraints:
|
|
84
|
+
return self._constraints
|
|
85
|
+
|
|
86
|
+
def set_choices(self, choices: Iterable[Any]) -> None:
|
|
87
|
+
options = [Option.parse(c) for c in choices]
|
|
88
|
+
self._constraints = self._constraints.merged(choices=tuple(options))
|
|
89
|
+
with self._programmatic():
|
|
90
|
+
self._apply_choices(options)
|
|
91
|
+
|
|
92
|
+
def set_read_only(self, read_only: bool) -> None:
|
|
93
|
+
self._read_only = read_only
|
|
94
|
+
self._apply_read_only(read_only)
|
|
95
|
+
|
|
96
|
+
def is_read_only(self) -> bool:
|
|
97
|
+
return self._read_only
|
|
98
|
+
|
|
99
|
+
# -- Hilfen für Unterklassen ------------------------------------------------------------
|
|
100
|
+
@contextmanager
|
|
101
|
+
def _programmatic(self):
|
|
102
|
+
self._silent += 1
|
|
103
|
+
try:
|
|
104
|
+
yield
|
|
105
|
+
finally:
|
|
106
|
+
self._silent -= 1
|
|
107
|
+
|
|
108
|
+
def _user_changed(self, *_: Any) -> None:
|
|
109
|
+
"""Von Unterklassen bei Benutzereingaben aufzurufen."""
|
|
110
|
+
if self._silent:
|
|
111
|
+
return
|
|
112
|
+
value = self.value()
|
|
113
|
+
self._check_error()
|
|
114
|
+
self.value_changed.emit(value)
|
|
115
|
+
self.value_edited.emit(value)
|
|
116
|
+
|
|
117
|
+
def _check_error(self) -> None:
|
|
118
|
+
error = self.input_error()
|
|
119
|
+
if error != self._last_error:
|
|
120
|
+
self._last_error = error
|
|
121
|
+
self.input_error_changed.emit(error)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class _WheelGuard(QObject):
|
|
125
|
+
"""Verhindert versehentliche Wertänderungen beim Scrollen einer Seite."""
|
|
126
|
+
|
|
127
|
+
def eventFilter(self, obj: QObject, event: QEvent) -> bool:
|
|
128
|
+
if event.type() == QEvent.Type.Wheel and isinstance(obj, QWidget) and not obj.hasFocus():
|
|
129
|
+
event.ignore()
|
|
130
|
+
return True
|
|
131
|
+
return False
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
_guard: _WheelGuard | None = None
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def guard_wheel(widget: QWidget) -> None:
|
|
138
|
+
global _guard
|
|
139
|
+
if _guard is None:
|
|
140
|
+
_guard = _WheelGuard()
|
|
141
|
+
widget.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
|
142
|
+
widget.installEventFilter(_guard)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
__all__ = ["StatusLabel", "ValueEditor", "guard_wheel"]
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"""Framework-Anbindung der autarken Einzeldatei-Widgets.
|
|
2
|
+
|
|
3
|
+
Die Klassen hier sind schlanke Unterklassen der Dateien in ``dynamic_settings_widget/standalone``
|
|
4
|
+
– dieselbe Implementierung, keine zweite. Sie übersetzen ausschließlich an der Grenze
|
|
5
|
+
zwischen Framework und Widget:
|
|
6
|
+
|
|
7
|
+
* ``Constraints`` → ``configure(...)`` des Widgets (``min`` → ``minimum`` usw.),
|
|
8
|
+
* ``Option`` → Auswahlliste (das Widget liest ``value``/``label``/``description``),
|
|
9
|
+
* ``SECRET_SET`` / ``SecretValue`` ↔ Passwortfeld.
|
|
10
|
+
|
|
11
|
+
Fachliche Prüfungen (Grenzen, Muster, Pflichtangaben, Berechtigungen) bleiben in
|
|
12
|
+
Sitzung und Zustandsmodell; die Widgets melden nur Eingabefehler, die sie selbst
|
|
13
|
+
erkennen (z. B. unvollständige Farbe).
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from collections.abc import Iterable
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from PySide6.QtCore import QEvent, Qt
|
|
22
|
+
|
|
23
|
+
from ..core.common import SECRET_SET, UNSET, SecretValue
|
|
24
|
+
from ..core.datatypes import Constraints, Option
|
|
25
|
+
from ..standalone import check_box_editor as _check_box
|
|
26
|
+
from ..standalone import choice_buttons_editor as _choice_buttons
|
|
27
|
+
from ..standalone import color_editor as _color
|
|
28
|
+
from ..standalone import dropdown_editor as _dropdown
|
|
29
|
+
from ..standalone import editable_label as _editable_label
|
|
30
|
+
from ..standalone import float_spin_box as _float_spin
|
|
31
|
+
from ..standalone import font_editor as _font
|
|
32
|
+
from ..standalone import hotkey_editor as _hotkey
|
|
33
|
+
from ..standalone import int_spin_box as _int_spin
|
|
34
|
+
from ..standalone import multi_choice_editor as _multi_choice
|
|
35
|
+
from ..standalone import password_editor as _password
|
|
36
|
+
from ..standalone import path_editor as _path
|
|
37
|
+
from ..standalone import server_connection_editor as _connection
|
|
38
|
+
from ..standalone import slider_spin_box as _slider
|
|
39
|
+
from ..standalone import sound_selection_widget as _sound
|
|
40
|
+
from ..standalone import switch_editor as _switch
|
|
41
|
+
from ..standalone import text_editor as _text
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class FrameworkEditor:
|
|
45
|
+
"""Mischklasse: ``set_constraints()``/``constraints()``/``set_choices()`` mit Framework-Typen.
|
|
46
|
+
|
|
47
|
+
``CONSTRAINT_OPTIONS`` ordnet Felder von ``Constraints`` den ``configure``-Schlüsseln des
|
|
48
|
+
Widgets zu; ``optional`` gilt immer.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
CONSTRAINT_OPTIONS: dict[str, str] = {}
|
|
52
|
+
|
|
53
|
+
def set_constraints(self, constraints: Constraints) -> None:
|
|
54
|
+
self._framework_constraints = constraints
|
|
55
|
+
options: dict[str, Any] = {"optional": constraints.optional}
|
|
56
|
+
for field, key in self.CONSTRAINT_OPTIONS.items():
|
|
57
|
+
options[key] = getattr(constraints, field)
|
|
58
|
+
self.configure(**options) # type: ignore[attr-defined]
|
|
59
|
+
if constraints.choices is not None:
|
|
60
|
+
self.set_choices(constraints.choices)
|
|
61
|
+
|
|
62
|
+
def constraints(self) -> Constraints:
|
|
63
|
+
current = getattr(self, "_framework_constraints", None)
|
|
64
|
+
return current if current is not None else Constraints(optional=self.is_optional()) # type: ignore[attr-defined]
|
|
65
|
+
|
|
66
|
+
def set_choices(self, choices: Iterable[Any]) -> None:
|
|
67
|
+
options = [Option.parse(c) for c in choices]
|
|
68
|
+
self._framework_constraints = self.constraints().merged(choices=tuple(options))
|
|
69
|
+
apply = getattr(super(), "set_choices", None)
|
|
70
|
+
if apply is not None:
|
|
71
|
+
apply(options)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
_NUMBER_OPTIONS = {"min": "minimum", "max": "maximum", "step": "step", "precision": "precision", "unit": "unit"}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class TextEditor(FrameworkEditor, _text.TextEditor):
|
|
78
|
+
"""Text (``text``)."""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class PasswordEditor(FrameworkEditor, _password.PasswordEditor):
|
|
82
|
+
"""Geheimwert (``password``); ``SECRET_SET`` kennzeichnet einen hinterlegten Wert."""
|
|
83
|
+
|
|
84
|
+
STORED = SECRET_SET
|
|
85
|
+
|
|
86
|
+
def set_value(self, value: Any) -> None:
|
|
87
|
+
super().set_value(value.reveal() if isinstance(value, SecretValue) else value)
|
|
88
|
+
|
|
89
|
+
cancel_activity = _password.PasswordEditor.hide_text
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class _NumberBridge(FrameworkEditor):
|
|
93
|
+
CONSTRAINT_OPTIONS = _NUMBER_OPTIONS
|
|
94
|
+
|
|
95
|
+
def __init__(self, *args, **kwargs):
|
|
96
|
+
self._unfinished = None
|
|
97
|
+
super().__init__(*args, **kwargs)
|
|
98
|
+
self.spin_box.lineEdit().textEdited.connect(self._check_number_text)
|
|
99
|
+
self.spin_box.installEventFilter(self)
|
|
100
|
+
|
|
101
|
+
def _check_number_text(self, text):
|
|
102
|
+
self._unfinished = None if self.spin_box.hasAcceptableInput() or self.spin_box.is_null() else text
|
|
103
|
+
self._check_error()
|
|
104
|
+
|
|
105
|
+
def input_error(self) -> str:
|
|
106
|
+
return "Zahleneingabe ist unvollständig" if self._unfinished is not None else super().input_error()
|
|
107
|
+
|
|
108
|
+
def set_value(self, value):
|
|
109
|
+
self._unfinished = None
|
|
110
|
+
super().set_value(value)
|
|
111
|
+
|
|
112
|
+
def commit(self):
|
|
113
|
+
if not self.is_read_only() and not self.input_error():
|
|
114
|
+
super().commit()
|
|
115
|
+
|
|
116
|
+
def eventFilter(self, obj, event):
|
|
117
|
+
spin = getattr(self, "_spin", None)
|
|
118
|
+
if obj is spin and self._unfinished is not None:
|
|
119
|
+
if event.type() == QEvent.Type.FocusIn:
|
|
120
|
+
spin.lineEdit().setText(self._unfinished)
|
|
121
|
+
elif event.type() == QEvent.Type.KeyPress and event.key() in (Qt.Key.Key_Return, Qt.Key.Key_Enter):
|
|
122
|
+
return True
|
|
123
|
+
return super().eventFilter(obj, event)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class IntSpinBox(_NumberBridge, _int_spin.IntSpinBox):
|
|
127
|
+
"""Ganzzahl (``int_spin``)."""
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class FloatSpinBox(_NumberBridge, _float_spin.FloatSpinBox):
|
|
132
|
+
"""Dezimalzahl (``float_spin``)."""
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class SliderSpinBox(_NumberBridge, _slider.SliderSpinBox):
|
|
137
|
+
"""Zahl mit Slider (``slider_spin``)."""
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class HotkeyEditor(FrameworkEditor, _hotkey.HotkeyEditor):
|
|
141
|
+
"""Tastenkombination (``hotkey``)."""
|
|
142
|
+
|
|
143
|
+
cancel_activity = _hotkey.HotkeyEditor.stop_capture
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class CheckBoxEditor(FrameworkEditor, _check_box.CheckBoxEditor):
|
|
147
|
+
"""Wahrheitswert (``checkbox``)."""
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class SwitchEditor(FrameworkEditor, _switch.SwitchEditor):
|
|
151
|
+
"""Wahrheitswert (``switch``)."""
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class DropdownEditor(FrameworkEditor, _dropdown.DropdownEditor):
|
|
155
|
+
"""Auswahl (``dropdown``)."""
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class ChoiceButtonsEditor(FrameworkEditor, _choice_buttons.ChoiceButtonsEditor):
|
|
159
|
+
"""Auswahl (``choice_buttons``)."""
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class MultiChoiceEditor(FrameworkEditor, _multi_choice.MultiChoiceEditor):
|
|
163
|
+
"""Mehrfachauswahl (``multi_choice``)."""
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class ColorEditor(FrameworkEditor, _color.ColorEditor):
|
|
167
|
+
"""Farbe (``color``)."""
|
|
168
|
+
|
|
169
|
+
CONSTRAINT_OPTIONS = {"alpha": "alpha"}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class FontEditor(FrameworkEditor, _font.FontEditor):
|
|
173
|
+
"""Schriftart (``font``)."""
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class PathEditor(FrameworkEditor, _path.PathEditor):
|
|
177
|
+
"""Pfad (``path``)."""
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class ServerConnectionEditor(FrameworkEditor, _connection.ServerConnectionEditor):
|
|
181
|
+
"""Verbindung (``server_connection``); Endpunkte kommen als Auswahl."""
|
|
182
|
+
|
|
183
|
+
def cancel_activity(self) -> None:
|
|
184
|
+
self._busy_value = None
|
|
185
|
+
if self._busy:
|
|
186
|
+
self._result.show_message("")
|
|
187
|
+
self.set_busy("")
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class EditableLabel(FrameworkEditor, _editable_label.EditableLabel):
|
|
191
|
+
"""Text als direkt bearbeitbare Beschriftung (``editable_label``)."""
|
|
192
|
+
|
|
193
|
+
has_uncommitted_input = _editable_label.EditableLabel.is_editing
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class SoundSelectionWidget(FrameworkEditor, _sound.SoundSelectionWidget):
|
|
197
|
+
"""Lokale Soundreferenz mit separater Darstellung für unbekannte Werte."""
|
|
198
|
+
|
|
199
|
+
_default_root = None
|
|
200
|
+
_initial_value = _sound._UNSELECTED
|
|
201
|
+
|
|
202
|
+
def configure(self, **options: Any) -> None:
|
|
203
|
+
constraints = getattr(self, "_framework_constraints", None)
|
|
204
|
+
if constraints is not None:
|
|
205
|
+
options["optional"] = constraints.optional
|
|
206
|
+
super().configure(**options)
|
|
207
|
+
|
|
208
|
+
def value(self) -> Any:
|
|
209
|
+
return UNSET if self._current is _sound._UNSELECTED else super().value()
|
|
210
|
+
|
|
211
|
+
def set_value(self, value: Any) -> None:
|
|
212
|
+
if value is UNSET:
|
|
213
|
+
self._set_current(_sound._UNSELECTED)
|
|
214
|
+
else:
|
|
215
|
+
super().set_value(value)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
__all__ = [
|
|
219
|
+
"CheckBoxEditor", "ChoiceButtonsEditor", "ColorEditor", "DropdownEditor", "EditableLabel", "FloatSpinBox",
|
|
220
|
+
"FontEditor", "FrameworkEditor", "HotkeyEditor", "IntSpinBox", "MultiChoiceEditor", "PasswordEditor", "PathEditor",
|
|
221
|
+
"ServerConnectionEditor", "SliderSpinBox", "SoundSelectionWidget", "SwitchEditor", "TextEditor",
|
|
222
|
+
] # fmt: skip
|