struct2ui 0.4.1__tar.gz → 0.4.3__tar.gz
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.
- {struct2ui-0.4.1/src/struct2ui.egg-info → struct2ui-0.4.3}/PKG-INFO +26 -2
- {struct2ui-0.4.1 → struct2ui-0.4.3}/README.md +25 -1
- {struct2ui-0.4.1 → struct2ui-0.4.3}/pyproject.toml +42 -42
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/__init__.py +4 -4
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/editor.py +211 -69
- {struct2ui-0.4.1 → struct2ui-0.4.3/src/struct2ui.egg-info}/PKG-INFO +26 -2
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_c_parser.py +1 -1
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_editor.py +5 -3
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_json_format.py +1 -1
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_save.py +1 -1
- {struct2ui-0.4.1 → struct2ui-0.4.3}/LICENSE +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/setup.cfg +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/exporters/__init__.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/exporters/bin_emitter.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/exporters/c_emitter.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/exporters/c_parser.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/exporters/elf_verifier.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/exporters/json_format.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/c2j.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/elf.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/export_notes_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/flowchart_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/refresh_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/report_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/save_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/save_as_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/settings_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/icons/widgets_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/schema.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/ui/__init__.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/ui/renderers.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/ui/tables.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui/ui/widgets.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui.egg-info/SOURCES.txt +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui.egg-info/dependency_links.txt +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui.egg-info/requires.txt +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/src/struct2ui.egg-info/top_level.txt +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_bin_emitter.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_c_emitter.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_choices.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_elf_verifier.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_float_precision.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_int_checkbox.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_load_report.py +0 -0
- {struct2ui-0.4.1 → struct2ui-0.4.3}/tests/test_value_readback.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: struct2ui
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
4
4
|
Summary: Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin
|
|
5
5
|
Author: Jay
|
|
6
6
|
License: MIT License
|
|
@@ -286,9 +286,33 @@ editor.set_sources(
|
|
|
286
286
|
| `elf_file` | Path to an ELF for `.bin` layout verification; setting it enables verification (toggle later via the Settings checkbox, which keeps the path) |
|
|
287
287
|
| `elf_enabled` | Override whether ELF verification runs, independent of whether a path is set |
|
|
288
288
|
| `reload` | Rebuild schema / flow / UI from the new sources, defaults to `True` |
|
|
289
|
+
| `async_load` | Run that reload on a background thread (defaults to `False`). See [Async Loading](#async-loading) |
|
|
289
290
|
|
|
290
291
|
Toolbar orientation is set with `set_flow_orientation('horizontal' | 'vertical')`.
|
|
291
292
|
|
|
293
|
+
#### Async Loading
|
|
294
|
+
|
|
295
|
+
Parsing the modules, validating the pipeline and (optionally) reading the ELF
|
|
296
|
+
all happen during the reload. For large module sets or ELFs this can take a
|
|
297
|
+
while, and by default it runs synchronously — `set_sources()` blocks until the
|
|
298
|
+
editor is fully built, which is what programmatic callers and tests want.
|
|
299
|
+
|
|
300
|
+
A GUI host can avoid the startup freeze by passing `async_load=True` *after*
|
|
301
|
+
`show()`: the window appears immediately and shows a `Loading...` placeholder
|
|
302
|
+
while the heavy parsing runs on a worker thread, then swaps in the real content
|
|
303
|
+
when it is ready. Reloads triggered while one is already running supersede the
|
|
304
|
+
older one.
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
editor.show()
|
|
308
|
+
editor.set_sources(
|
|
309
|
+
cfg_dir="cfg_t",
|
|
310
|
+
flow_file="abc.json",
|
|
311
|
+
elf_file="fw.elf",
|
|
312
|
+
async_load=True, # parse off the GUI thread; window stays responsive
|
|
313
|
+
)
|
|
314
|
+
```
|
|
315
|
+
|
|
292
316
|
## Custom Toolbar Buttons
|
|
293
317
|
|
|
294
318
|
Host applications can add their own buttons to the top path bar via
|
|
@@ -328,7 +352,7 @@ from code (e.g. wired to a custom button):
|
|
|
328
352
|
|
|
329
353
|
| Method | Description |
|
|
330
354
|
| --- | --- |
|
|
331
|
-
| `set_sources(cfg_dir=None, flow_file=None, elf_file=None, elf_enabled=None, reload=True)` | Point the editor at its source files after construction. See [Setting Sources](#setting-sources). |
|
|
355
|
+
| `set_sources(cfg_dir=None, flow_file=None, elf_file=None, elf_enabled=None, reload=True, async_load=False)` | Point the editor at its source files after construction. See [Setting Sources](#setting-sources). |
|
|
332
356
|
| `set_flow_orientation(orientation)` | Switch the flow-button strip between `'horizontal'` (top, default) and `'vertical'` (left). Rebuilds the strip and keeps the active stage selected. |
|
|
333
357
|
| `show_section(label) -> None` | Open the stage/section named `label` in the content area (the same as clicking its flow button). Paints the error panel instead when that stage has pipeline errors; clears the content when the label is unknown. |
|
|
334
358
|
| `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
|
|
@@ -233,9 +233,33 @@ editor.set_sources(
|
|
|
233
233
|
| `elf_file` | Path to an ELF for `.bin` layout verification; setting it enables verification (toggle later via the Settings checkbox, which keeps the path) |
|
|
234
234
|
| `elf_enabled` | Override whether ELF verification runs, independent of whether a path is set |
|
|
235
235
|
| `reload` | Rebuild schema / flow / UI from the new sources, defaults to `True` |
|
|
236
|
+
| `async_load` | Run that reload on a background thread (defaults to `False`). See [Async Loading](#async-loading) |
|
|
236
237
|
|
|
237
238
|
Toolbar orientation is set with `set_flow_orientation('horizontal' | 'vertical')`.
|
|
238
239
|
|
|
240
|
+
#### Async Loading
|
|
241
|
+
|
|
242
|
+
Parsing the modules, validating the pipeline and (optionally) reading the ELF
|
|
243
|
+
all happen during the reload. For large module sets or ELFs this can take a
|
|
244
|
+
while, and by default it runs synchronously — `set_sources()` blocks until the
|
|
245
|
+
editor is fully built, which is what programmatic callers and tests want.
|
|
246
|
+
|
|
247
|
+
A GUI host can avoid the startup freeze by passing `async_load=True` *after*
|
|
248
|
+
`show()`: the window appears immediately and shows a `Loading...` placeholder
|
|
249
|
+
while the heavy parsing runs on a worker thread, then swaps in the real content
|
|
250
|
+
when it is ready. Reloads triggered while one is already running supersede the
|
|
251
|
+
older one.
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
editor.show()
|
|
255
|
+
editor.set_sources(
|
|
256
|
+
cfg_dir="cfg_t",
|
|
257
|
+
flow_file="abc.json",
|
|
258
|
+
elf_file="fw.elf",
|
|
259
|
+
async_load=True, # parse off the GUI thread; window stays responsive
|
|
260
|
+
)
|
|
261
|
+
```
|
|
262
|
+
|
|
239
263
|
## Custom Toolbar Buttons
|
|
240
264
|
|
|
241
265
|
Host applications can add their own buttons to the top path bar via
|
|
@@ -275,7 +299,7 @@ from code (e.g. wired to a custom button):
|
|
|
275
299
|
|
|
276
300
|
| Method | Description |
|
|
277
301
|
| --- | --- |
|
|
278
|
-
| `set_sources(cfg_dir=None, flow_file=None, elf_file=None, elf_enabled=None, reload=True)` | Point the editor at its source files after construction. See [Setting Sources](#setting-sources). |
|
|
302
|
+
| `set_sources(cfg_dir=None, flow_file=None, elf_file=None, elf_enabled=None, reload=True, async_load=False)` | Point the editor at its source files after construction. See [Setting Sources](#setting-sources). |
|
|
279
303
|
| `set_flow_orientation(orientation)` | Switch the flow-button strip between `'horizontal'` (top, default) and `'vertical'` (left). Rebuilds the strip and keeps the active stage selected. |
|
|
280
304
|
| `show_section(label) -> None` | Open the stage/section named `label` in the content area (the same as clicking its flow button). Paints the error panel instead when that stage has pipeline errors; clears the content when the label is unknown. |
|
|
281
305
|
| `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools>=68", "wheel"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "struct2ui"
|
|
7
|
-
version = "0.4.
|
|
8
|
-
description = "Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin"
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.9"
|
|
11
|
-
license = {file = "LICENSE"}
|
|
12
|
-
authors = [
|
|
13
|
-
{name = "Jay"},
|
|
14
|
-
]
|
|
15
|
-
keywords = ["qt", "pyside6", "gui", "c-struct", "json-schema", "code-generation", "parameter-tuning"]
|
|
16
|
-
classifiers = [
|
|
17
|
-
"Development Status :: 3 - Alpha",
|
|
18
|
-
"Intended Audience :: Developers",
|
|
19
|
-
"License :: OSI Approved :: MIT License",
|
|
20
|
-
"Programming Language :: Python :: 3",
|
|
21
|
-
"Programming Language :: Python :: 3.9",
|
|
22
|
-
"Programming Language :: Python :: 3.10",
|
|
23
|
-
"Programming Language :: Python :: 3.11",
|
|
24
|
-
"Programming Language :: Python :: 3.12",
|
|
25
|
-
"Topic :: Software Development :: Code Generators",
|
|
26
|
-
"Topic :: Software Development :: User Interfaces",
|
|
27
|
-
]
|
|
28
|
-
dependencies = [
|
|
29
|
-
"Qt.py>=1.3",
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
[project.optional-dependencies]
|
|
33
|
-
pyside6 = ["PySide6>=6.4"]
|
|
34
|
-
pyqt6 = ["PyQt6>=6.4"]
|
|
35
|
-
elf = ["pyelftools>=0.29"]
|
|
36
|
-
dev = ["pytest>=8", "pyelftools>=0.29"]
|
|
37
|
-
|
|
38
|
-
[tool.setuptools.packages.find]
|
|
39
|
-
where = ["src"]
|
|
40
|
-
|
|
41
|
-
[tool.setuptools.package-data]
|
|
42
|
-
struct2ui = ["icons/*.png"]
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "struct2ui"
|
|
7
|
+
version = "0.4.3"
|
|
8
|
+
description = "Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = {file = "LICENSE"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Jay"},
|
|
14
|
+
]
|
|
15
|
+
keywords = ["qt", "pyside6", "gui", "c-struct", "json-schema", "code-generation", "parameter-tuning"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Software Development :: Code Generators",
|
|
26
|
+
"Topic :: Software Development :: User Interfaces",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"Qt.py>=1.3",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
pyside6 = ["PySide6>=6.4"]
|
|
34
|
+
pyqt6 = ["PyQt6>=6.4"]
|
|
35
|
+
elf = ["pyelftools>=0.29"]
|
|
36
|
+
dev = ["pytest>=8", "pyelftools>=0.29"]
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.package-data]
|
|
42
|
+
struct2ui = ["icons/*.png"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .editor import StructEditor
|
|
2
|
-
|
|
3
|
-
__version__ = "0.4.
|
|
4
|
-
__all__ = ["StructEditor"]
|
|
1
|
+
from .editor import StructEditor
|
|
2
|
+
|
|
3
|
+
__version__ = "0.4.3"
|
|
4
|
+
__all__ = ["StructEditor"]
|
|
@@ -236,6 +236,134 @@ class _OverflowBar(QtWidgets.QWidget):
|
|
|
236
236
|
self.overflow_btn.setVisible(any_hidden)
|
|
237
237
|
|
|
238
238
|
|
|
239
|
+
class _LoadResult:
|
|
240
|
+
"""Plain data produced off the GUI thread by _LoadWorker.
|
|
241
|
+
|
|
242
|
+
Holds everything _reload's heavy steps compute (schema registry, parsed
|
|
243
|
+
flow, ELF report) so the GUI thread can apply it without touching disk or
|
|
244
|
+
re-parsing. ``token`` identifies the request so a stale result (the user
|
|
245
|
+
reloaded again meanwhile) can be discarded. ``error`` carries an
|
|
246
|
+
unexpected worker exception, if any.
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
def __init__(self, token):
|
|
250
|
+
self.token = token
|
|
251
|
+
self.registry = None
|
|
252
|
+
self.group_key = ''
|
|
253
|
+
self.flow = []
|
|
254
|
+
self.section_specs = {}
|
|
255
|
+
self.raw_data = {}
|
|
256
|
+
self.stage_errors = {}
|
|
257
|
+
self.elf_report = None
|
|
258
|
+
self.report_text = ''
|
|
259
|
+
self.error = None
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
class _LoadSignals(QtCore.QObject):
|
|
263
|
+
done = QtCore.Signal(object)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
class _LoadWorker(QtCore.QRunnable):
|
|
267
|
+
"""Runs _reload's heavy, GUI-free steps on a background thread.
|
|
268
|
+
|
|
269
|
+
Reads only the plain path snapshot passed in (never the live widget), so
|
|
270
|
+
it is safe to run while the GUI thread keeps painting. Emits ``done`` with
|
|
271
|
+
a _LoadResult when finished.
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
def __init__(self, token, struct_dir, pipeline_path, elf_path, elf_active):
|
|
275
|
+
super().__init__()
|
|
276
|
+
self.signals = _LoadSignals()
|
|
277
|
+
self._token = token
|
|
278
|
+
self._struct_dir = struct_dir
|
|
279
|
+
self._pipeline_path = pipeline_path
|
|
280
|
+
self._elf_path = elf_path
|
|
281
|
+
self._elf_active = elf_active
|
|
282
|
+
|
|
283
|
+
def run(self):
|
|
284
|
+
result = _LoadResult(self._token)
|
|
285
|
+
try:
|
|
286
|
+
self._compute(result)
|
|
287
|
+
except Exception as exc: # pragma: no cover - defensive
|
|
288
|
+
result.error = exc
|
|
289
|
+
self.signals.done.emit(result)
|
|
290
|
+
|
|
291
|
+
def _compute(self, result):
|
|
292
|
+
registry = SchemaRegistry(self._struct_dir)
|
|
293
|
+
flow_report = FlowValidator(registry, self._pipeline_path).validate()
|
|
294
|
+
registry.report.extend(flow_report)
|
|
295
|
+
result.registry = registry
|
|
296
|
+
|
|
297
|
+
group_key, flow, section_specs, raw_data = self._load_flow()
|
|
298
|
+
result.group_key = group_key
|
|
299
|
+
result.flow = flow
|
|
300
|
+
result.section_specs = section_specs
|
|
301
|
+
result.raw_data = raw_data
|
|
302
|
+
|
|
303
|
+
result.stage_errors = self._index_stage_errors(
|
|
304
|
+
registry, group_key, flow)
|
|
305
|
+
result.elf_report = self._verify_elf(
|
|
306
|
+
registry, flow, section_specs, raw_data)
|
|
307
|
+
|
|
308
|
+
lines = [registry.report.format()]
|
|
309
|
+
if result.elf_report is not None:
|
|
310
|
+
lines.append(result.elf_report.format())
|
|
311
|
+
result.report_text = ''.join(lines)
|
|
312
|
+
|
|
313
|
+
def _load_flow(self):
|
|
314
|
+
if not os.path.exists(self._pipeline_path):
|
|
315
|
+
return '', [], {}, {}
|
|
316
|
+
try:
|
|
317
|
+
with open(self._pipeline_path, 'r', encoding='utf-8') as f:
|
|
318
|
+
data = json.load(f)
|
|
319
|
+
except Exception:
|
|
320
|
+
return '', [], {}, {}
|
|
321
|
+
if not isinstance(data, dict) or not data:
|
|
322
|
+
return '', [], {}, {}
|
|
323
|
+
group_key = next(iter(data.keys()))
|
|
324
|
+
group = data.get(group_key, {})
|
|
325
|
+
if not isinstance(group, dict):
|
|
326
|
+
return '', [], {}, {}
|
|
327
|
+
flow = list(group.get('Flow', []) or [])
|
|
328
|
+
section_specs = {
|
|
329
|
+
label: spec for label, spec in group.items()
|
|
330
|
+
if label != 'Flow' and isinstance(spec, dict)
|
|
331
|
+
}
|
|
332
|
+
return group_key, flow, section_specs, data
|
|
333
|
+
|
|
334
|
+
def _index_stage_errors(self, registry, group_key, flow):
|
|
335
|
+
stage_errors = {label: [] for label in flow}
|
|
336
|
+
if not group_key:
|
|
337
|
+
return stage_errors
|
|
338
|
+
prefix = f'{group_key} -> '
|
|
339
|
+
for issue in registry.report.errors:
|
|
340
|
+
if issue.file != self._pipeline_path:
|
|
341
|
+
continue
|
|
342
|
+
if not issue.path.startswith(prefix):
|
|
343
|
+
continue
|
|
344
|
+
tail = issue.path[len(prefix):]
|
|
345
|
+
stage = tail.split(' -> ', 1)[0]
|
|
346
|
+
if stage in stage_errors:
|
|
347
|
+
stage_errors[stage].append(issue)
|
|
348
|
+
return stage_errors
|
|
349
|
+
|
|
350
|
+
def _verify_elf(self, registry, flow, section_specs, raw_data):
|
|
351
|
+
if not self._elf_active or registry is None:
|
|
352
|
+
return None
|
|
353
|
+
sections = []
|
|
354
|
+
for label in flow:
|
|
355
|
+
spec = section_specs.get(label)
|
|
356
|
+
if not isinstance(spec, dict):
|
|
357
|
+
continue
|
|
358
|
+
type_name = spec.get('type') or ''
|
|
359
|
+
if type_name:
|
|
360
|
+
sections.append((label, type_name, None))
|
|
361
|
+
if not sections:
|
|
362
|
+
return None
|
|
363
|
+
abi = merge_abi(raw_data.get('abi'))
|
|
364
|
+
return verify_sections(sections, registry, self._elf_path, abi)
|
|
365
|
+
|
|
366
|
+
|
|
239
367
|
class StructEditor(QtWidgets.QWidget):
|
|
240
368
|
|
|
241
369
|
# Button keys and their built-in defaults. Each entry: the fallback text
|
|
@@ -309,7 +437,7 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
309
437
|
# (edit, browse_btn) of the ELF row, toggled by its enable checkbox.
|
|
310
438
|
self._elf_row = None
|
|
311
439
|
|
|
312
|
-
# Flow data (populated by _reload via
|
|
440
|
+
# Flow data (populated by _reload via _apply_load).
|
|
313
441
|
self.registry: SchemaRegistry = None # type: ignore[assignment]
|
|
314
442
|
self._group_key: str = ''
|
|
315
443
|
self._flow: List[str] = []
|
|
@@ -330,6 +458,14 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
330
458
|
# mistakes, S1/S2/S4 declaration issues) stay console-only here.
|
|
331
459
|
self._stage_errors: Dict[str, List[Any]] = {}
|
|
332
460
|
|
|
461
|
+
# Background loading: _reload's heavy steps run on a worker thread so
|
|
462
|
+
# the window paints immediately. _reload_token rises on every reload;
|
|
463
|
+
# a finishing worker whose token is stale (the user reloaded again) is
|
|
464
|
+
# discarded. _loading guards against overlapping source edits.
|
|
465
|
+
self._thread_pool = QtCore.QThreadPool.globalInstance()
|
|
466
|
+
self._reload_token = 0
|
|
467
|
+
self._loading = False
|
|
468
|
+
|
|
333
469
|
# C2J tool state: last picked .c/.h path and the parse result it
|
|
334
470
|
# produced. Lives outside _reload() because the C->JSON converter is a
|
|
335
471
|
# standalone side tool that does not touch the pipeline/schema flow.
|
|
@@ -594,7 +730,7 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
594
730
|
|
|
595
731
|
def set_sources(self, cfg_dir: str = None, flow_file: str = None,
|
|
596
732
|
elf_file: str = None, elf_enabled: bool = None,
|
|
597
|
-
reload: bool = True) -> None:
|
|
733
|
+
reload: bool = True, async_load: bool = False) -> None:
|
|
598
734
|
"""Point the editor at its source files after construction.
|
|
599
735
|
|
|
600
736
|
Each path argument is applied only when given (pass ``None`` to leave
|
|
@@ -602,6 +738,13 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
602
738
|
default; pass ``elf_enabled`` to override that. With ``reload=True``
|
|
603
739
|
(the default) the schema, flow and UI are rebuilt from the new sources,
|
|
604
740
|
mirroring a click on the Reload button.
|
|
741
|
+
|
|
742
|
+
``async_load`` controls how that reload runs. The default (``False``)
|
|
743
|
+
loads synchronously: the call blocks until the editor is fully built,
|
|
744
|
+
which is what programmatic callers and tests want. Pass ``True`` from a
|
|
745
|
+
GUI host (after ``show()``) to run the heavy schema/flow/ELF parsing on
|
|
746
|
+
a background thread so the window paints immediately and shows a
|
|
747
|
+
"Loading..." placeholder until the data is ready.
|
|
605
748
|
"""
|
|
606
749
|
if cfg_dir is not None:
|
|
607
750
|
self.struct_dir = cfg_dir
|
|
@@ -615,7 +758,7 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
615
758
|
self._set_elf_enabled(elf_enabled)
|
|
616
759
|
self._refresh_path_tooltips()
|
|
617
760
|
if reload:
|
|
618
|
-
self._reload()
|
|
761
|
+
self._reload(async_load=async_load)
|
|
619
762
|
|
|
620
763
|
def current_paths(self) -> Dict[str, str]:
|
|
621
764
|
"""Return the current Modules / Pipeline / ELF file paths.
|
|
@@ -701,21 +844,65 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
701
844
|
self._reload()
|
|
702
845
|
|
|
703
846
|
# ---- reload (build schema + flow + UI from current paths) ----------- #
|
|
704
|
-
def _reload(self) -> None:
|
|
847
|
+
def _reload(self, async_load: bool = True) -> None:
|
|
705
848
|
# Nothing selected yet (e.g. first launch with no constructor paths):
|
|
706
849
|
# leave the content area blank and wait for the user to pick sources.
|
|
707
850
|
if not self.struct_dir and not self.pipeline_path:
|
|
708
851
|
self._set_content(QtWidgets.QWidget())
|
|
709
852
|
return
|
|
710
|
-
# Schema registry (loads cfg_t/*.json once).
|
|
711
|
-
self.registry = SchemaRegistry(self.struct_dir)
|
|
712
853
|
|
|
713
|
-
#
|
|
714
|
-
|
|
715
|
-
self.
|
|
854
|
+
# Bump the token so any worker still in flight is treated as stale.
|
|
855
|
+
self._reload_token += 1
|
|
856
|
+
token = self._reload_token
|
|
857
|
+
|
|
858
|
+
worker = _LoadWorker(token, self.struct_dir, self.pipeline_path,
|
|
859
|
+
self.elf_path, self._elf_active())
|
|
860
|
+
|
|
861
|
+
# Synchronous path: used by tests (and any caller that needs the load
|
|
862
|
+
# to finish before returning). Runs the heavy steps inline and applies
|
|
863
|
+
# the result immediately, preserving the original blocking behaviour.
|
|
864
|
+
if not async_load:
|
|
865
|
+
result = _LoadResult(token)
|
|
866
|
+
worker._compute(result)
|
|
867
|
+
self._apply_load(result)
|
|
868
|
+
return
|
|
869
|
+
|
|
870
|
+
# Async path: show a placeholder, then hand the heavy steps to the
|
|
871
|
+
# thread pool so the window keeps painting. The result comes back via
|
|
872
|
+
# _on_load_done on the GUI thread.
|
|
873
|
+
self._loading = True
|
|
874
|
+
self._set_content(self._make_loading_panel())
|
|
875
|
+
worker.signals.done.connect(self._on_load_done)
|
|
876
|
+
self._thread_pool.start(worker)
|
|
877
|
+
|
|
878
|
+
def _make_loading_panel(self) -> QtWidgets.QWidget:
|
|
879
|
+
panel = QtWidgets.QWidget()
|
|
880
|
+
layout = QtWidgets.QVBoxLayout(panel)
|
|
881
|
+
layout.setAlignment(QtCore.Qt.AlignCenter)
|
|
882
|
+
label = QtWidgets.QLabel('Loading...')
|
|
883
|
+
label.setAlignment(QtCore.Qt.AlignCenter)
|
|
884
|
+
layout.addWidget(label)
|
|
885
|
+
return panel
|
|
886
|
+
|
|
887
|
+
def _on_load_done(self, result) -> None:
|
|
888
|
+
# Drop results from a superseded reload (the user reloaded again or
|
|
889
|
+
# changed sources while this worker was running).
|
|
890
|
+
if result.token != self._reload_token:
|
|
891
|
+
return
|
|
892
|
+
self._loading = False
|
|
893
|
+
if result.error is not None:
|
|
894
|
+
raise result.error
|
|
895
|
+
self._apply_load(result)
|
|
896
|
+
|
|
897
|
+
def _apply_load(self, result) -> None:
|
|
898
|
+
"""Apply a finished load on the GUI thread: copy the worker's data in,
|
|
899
|
+
then rebuild the buttons and content. This is the only place the heavy
|
|
900
|
+
results touch self / Qt widgets.
|
|
901
|
+
"""
|
|
902
|
+
self.registry = result.registry
|
|
716
903
|
|
|
717
904
|
# Print load report to console (Step 1~3: console only).
|
|
718
|
-
print(
|
|
905
|
+
print(result.report_text, end='')
|
|
719
906
|
|
|
720
907
|
# Reset flow data and rebuild UI from the new sources. Clearing
|
|
721
908
|
# _active_label first is essential: the upcoming _on_button_clicked
|
|
@@ -724,17 +911,12 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
724
911
|
# freshly loaded document (overwriting same-named sections, so the
|
|
725
912
|
# new file appears not to load).
|
|
726
913
|
self._active_label = ''
|
|
727
|
-
self._group_key =
|
|
728
|
-
self._flow =
|
|
729
|
-
self._section_specs =
|
|
730
|
-
self._raw_data =
|
|
731
|
-
self._stage_errors =
|
|
732
|
-
self._elf_report =
|
|
733
|
-
self._load_flow()
|
|
734
|
-
self._index_stage_errors()
|
|
735
|
-
# Strictest ELF layout verification. Runs on every reload / pipeline
|
|
736
|
-
# change; skipped (left empty) when no ELF is selected.
|
|
737
|
-
self._verify_elf()
|
|
914
|
+
self._group_key = result.group_key
|
|
915
|
+
self._flow = result.flow
|
|
916
|
+
self._section_specs = result.section_specs
|
|
917
|
+
self._raw_data = result.raw_data
|
|
918
|
+
self._stage_errors = result.stage_errors
|
|
919
|
+
self._elf_report = result.elf_report
|
|
738
920
|
self._build_buttons()
|
|
739
921
|
# Step 4c: when the load report has any issue, land on a summary
|
|
740
922
|
# panel instead of auto-selecting the first stage. Lets the user
|
|
@@ -753,29 +935,6 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
753
935
|
else:
|
|
754
936
|
self._set_content(QtWidgets.QWidget())
|
|
755
937
|
|
|
756
|
-
def _index_stage_errors(self) -> None:
|
|
757
|
-
"""Bucket pipeline errors by stage name.
|
|
758
|
-
|
|
759
|
-
Only errors raised against the active pipeline file and whose path
|
|
760
|
-
starts with '<group_key> -> <stage>' are recognised as stage-scoped.
|
|
761
|
-
Cfg_t-side errors (declaration mistakes, S1/S2/S4) and pipeline
|
|
762
|
-
errors at the group/Flow level fall through and remain visible only
|
|
763
|
-
in the console report.
|
|
764
|
-
"""
|
|
765
|
-
self._stage_errors = {label: [] for label in self._flow}
|
|
766
|
-
if not self._group_key:
|
|
767
|
-
return
|
|
768
|
-
prefix = f'{self._group_key} -> '
|
|
769
|
-
for issue in self.registry.report.errors:
|
|
770
|
-
if issue.file != self.pipeline_path:
|
|
771
|
-
continue
|
|
772
|
-
if not issue.path.startswith(prefix):
|
|
773
|
-
continue
|
|
774
|
-
tail = issue.path[len(prefix):]
|
|
775
|
-
stage = tail.split(' -> ', 1)[0]
|
|
776
|
-
if stage in self._stage_errors:
|
|
777
|
-
self._stage_errors[stage].append(issue)
|
|
778
|
-
|
|
779
938
|
def _other_errors(self) -> List[Any]:
|
|
780
939
|
"""Errors not pinned to any stage tab.
|
|
781
940
|
|
|
@@ -822,31 +981,6 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
822
981
|
sections, self.registry, self.elf_path, abi)
|
|
823
982
|
print(self._elf_report.format(), end='')
|
|
824
983
|
|
|
825
|
-
# ---- flow loading ---------------------------------------------------- #
|
|
826
|
-
def _load_flow(self) -> None:
|
|
827
|
-
if not os.path.exists(self.pipeline_path):
|
|
828
|
-
return
|
|
829
|
-
try:
|
|
830
|
-
with open(self.pipeline_path, 'r', encoding='utf-8') as f:
|
|
831
|
-
data = json.load(f)
|
|
832
|
-
except Exception:
|
|
833
|
-
return
|
|
834
|
-
if not isinstance(data, dict) or not data:
|
|
835
|
-
return
|
|
836
|
-
self._group_key = next(iter(data.keys()))
|
|
837
|
-
group = data.get(self._group_key, {})
|
|
838
|
-
if not isinstance(group, dict):
|
|
839
|
-
return
|
|
840
|
-
# Keep the raw loaded document so Save can write it back verbatim,
|
|
841
|
-
# patching only the 'items' of edited sections. This preserves group
|
|
842
|
-
# structure, render hints and any keys the UI does not render.
|
|
843
|
-
self._raw_data = data
|
|
844
|
-
self._flow = list(group.get('Flow', []) or [])
|
|
845
|
-
self._section_specs = {
|
|
846
|
-
label: spec for label, spec in group.items()
|
|
847
|
-
if label != 'Flow' and isinstance(spec, dict)
|
|
848
|
-
}
|
|
849
|
-
|
|
850
984
|
# ---- buttons --------------------------------------------------------- #
|
|
851
985
|
def _build_buttons(self) -> None:
|
|
852
986
|
while self.buttons_layout.count():
|
|
@@ -1583,6 +1717,14 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
1583
1717
|
layout.setContentsMargins(8, 8, 8, 8)
|
|
1584
1718
|
layout.setSpacing(8)
|
|
1585
1719
|
|
|
1720
|
+
# No sources selected yet: nothing has been loaded, so there is no
|
|
1721
|
+
# report to show. Avoid touching self.registry (still None).
|
|
1722
|
+
if self.registry is None:
|
|
1723
|
+
hint = QtWidgets.QLabel('No sources loaded')
|
|
1724
|
+
layout.addWidget(hint)
|
|
1725
|
+
layout.addStretch(1)
|
|
1726
|
+
return panel
|
|
1727
|
+
|
|
1586
1728
|
report = self.registry.report
|
|
1587
1729
|
if report.has_errors or report.has_warnings:
|
|
1588
1730
|
layout.addWidget(self._make_summary_panel())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: struct2ui
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
4
4
|
Summary: Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin
|
|
5
5
|
Author: Jay
|
|
6
6
|
License: MIT License
|
|
@@ -286,9 +286,33 @@ editor.set_sources(
|
|
|
286
286
|
| `elf_file` | Path to an ELF for `.bin` layout verification; setting it enables verification (toggle later via the Settings checkbox, which keeps the path) |
|
|
287
287
|
| `elf_enabled` | Override whether ELF verification runs, independent of whether a path is set |
|
|
288
288
|
| `reload` | Rebuild schema / flow / UI from the new sources, defaults to `True` |
|
|
289
|
+
| `async_load` | Run that reload on a background thread (defaults to `False`). See [Async Loading](#async-loading) |
|
|
289
290
|
|
|
290
291
|
Toolbar orientation is set with `set_flow_orientation('horizontal' | 'vertical')`.
|
|
291
292
|
|
|
293
|
+
#### Async Loading
|
|
294
|
+
|
|
295
|
+
Parsing the modules, validating the pipeline and (optionally) reading the ELF
|
|
296
|
+
all happen during the reload. For large module sets or ELFs this can take a
|
|
297
|
+
while, and by default it runs synchronously — `set_sources()` blocks until the
|
|
298
|
+
editor is fully built, which is what programmatic callers and tests want.
|
|
299
|
+
|
|
300
|
+
A GUI host can avoid the startup freeze by passing `async_load=True` *after*
|
|
301
|
+
`show()`: the window appears immediately and shows a `Loading...` placeholder
|
|
302
|
+
while the heavy parsing runs on a worker thread, then swaps in the real content
|
|
303
|
+
when it is ready. Reloads triggered while one is already running supersede the
|
|
304
|
+
older one.
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
editor.show()
|
|
308
|
+
editor.set_sources(
|
|
309
|
+
cfg_dir="cfg_t",
|
|
310
|
+
flow_file="abc.json",
|
|
311
|
+
elf_file="fw.elf",
|
|
312
|
+
async_load=True, # parse off the GUI thread; window stays responsive
|
|
313
|
+
)
|
|
314
|
+
```
|
|
315
|
+
|
|
292
316
|
## Custom Toolbar Buttons
|
|
293
317
|
|
|
294
318
|
Host applications can add their own buttons to the top path bar via
|
|
@@ -328,7 +352,7 @@ from code (e.g. wired to a custom button):
|
|
|
328
352
|
|
|
329
353
|
| Method | Description |
|
|
330
354
|
| --- | --- |
|
|
331
|
-
| `set_sources(cfg_dir=None, flow_file=None, elf_file=None, elf_enabled=None, reload=True)` | Point the editor at its source files after construction. See [Setting Sources](#setting-sources). |
|
|
355
|
+
| `set_sources(cfg_dir=None, flow_file=None, elf_file=None, elf_enabled=None, reload=True, async_load=False)` | Point the editor at its source files after construction. See [Setting Sources](#setting-sources). |
|
|
332
356
|
| `set_flow_orientation(orientation)` | Switch the flow-button strip between `'horizontal'` (top, default) and `'vertical'` (left). Rebuilds the strip and keeps the active stage selected. |
|
|
333
357
|
| `show_section(label) -> None` | Open the stage/section named `label` in the content area (the same as clicking its flow button). Paints the error panel instead when that stage has pipeline errors; clears the content when the label is unknown. |
|
|
334
358
|
| `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
|
|
@@ -129,7 +129,7 @@ def test_roundtrip_real_c_files():
|
|
|
129
129
|
"""Parsing the project's own cfg_t/*.c and loading the result must not
|
|
130
130
|
produce schema errors for the structs they define."""
|
|
131
131
|
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
132
|
-
c_path = os.path.join(base, 'examples', '
|
|
132
|
+
c_path = os.path.join(base, 'examples', 'abc_test', 'cfg_t', 'a_cfg_t.c')
|
|
133
133
|
with open(c_path, encoding='utf-8') as f:
|
|
134
134
|
out = build_schema_dict(parse_c_source(f.read()))
|
|
135
135
|
assert 'a_cfg_t' in out
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Tests for path handling (paths come from set_sources(), not memory)."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
+
import os
|
|
4
5
|
|
|
5
6
|
from Qt import QtWidgets
|
|
6
7
|
|
|
@@ -142,9 +143,10 @@ def test_overflow_menu_carries_group_separators(qapp, make_editor,
|
|
|
142
143
|
def test_new_editor_ignores_previous_paths(qapp, make_editor, real_cfg_dir,
|
|
143
144
|
real_flow):
|
|
144
145
|
first = make_editor(real_flow, real_cfg_dir)
|
|
145
|
-
|
|
146
|
+
examples = os.path.dirname(os.path.dirname(real_flow))
|
|
147
|
+
first.pipeline_path = os.path.join(examples, 'speech', 'speech.json')
|
|
146
148
|
first.struct_dir = real_cfg_dir
|
|
147
|
-
first.
|
|
149
|
+
first._reload(async_load=False)
|
|
148
150
|
|
|
149
151
|
second = StructEditor()
|
|
150
152
|
assert second.pipeline_path == ''
|
|
@@ -168,7 +170,7 @@ def test_reload_new_pipeline_does_not_keep_old_edits(
|
|
|
168
170
|
spin.setValue(999)
|
|
169
171
|
|
|
170
172
|
w.pipeline_path = str(other)
|
|
171
|
-
w._reload()
|
|
173
|
+
w._reload(async_load=False)
|
|
172
174
|
|
|
173
175
|
assert w._raw_data['ABC Test']['A']['items']['level'] == 7
|
|
174
176
|
|
|
@@ -33,7 +33,7 @@ def test_empty_containers():
|
|
|
33
33
|
def test_roundtrip_real_flow():
|
|
34
34
|
import os
|
|
35
35
|
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
36
|
-
data = json.load(open(os.path.join(base, 'examples', 'abc.json'), encoding='utf-8'))
|
|
36
|
+
data = json.load(open(os.path.join(base, 'examples', 'abc_test', 'abc.json'), encoding='utf-8'))
|
|
37
37
|
assert json.loads(dumps_json(data)) == data
|
|
38
38
|
|
|
39
39
|
|
|
@@ -19,7 +19,7 @@ def flow_copy(tmp_path):
|
|
|
19
19
|
"""Copy the real abc.json into a temp file so saves never touch the repo."""
|
|
20
20
|
import os
|
|
21
21
|
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
22
|
-
src = os.path.join(base, 'examples', 'abc.json')
|
|
22
|
+
src = os.path.join(base, 'examples', 'abc_test', 'abc.json')
|
|
23
23
|
dst = tmp_path / 'flow.json'
|
|
24
24
|
shutil.copy(src, dst)
|
|
25
25
|
return str(dst)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|