struct2ui 0.4.0__tar.gz → 0.4.1__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.0/src/struct2ui.egg-info → struct2ui-0.4.1}/PKG-INFO +43 -17
- {struct2ui-0.4.0 → struct2ui-0.4.1}/README.md +42 -16
- {struct2ui-0.4.0 → struct2ui-0.4.1}/pyproject.toml +1 -1
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/__init__.py +1 -1
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/editor.py +85 -27
- {struct2ui-0.4.0 → struct2ui-0.4.1/src/struct2ui.egg-info}/PKG-INFO +43 -17
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_editor.py +54 -47
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_load_report.py +12 -11
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_save.py +48 -51
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_value_readback.py +2 -3
- {struct2ui-0.4.0 → struct2ui-0.4.1}/LICENSE +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/setup.cfg +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/exporters/__init__.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/exporters/bin_emitter.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/exporters/c_emitter.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/exporters/c_parser.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/exporters/elf_verifier.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/exporters/json_format.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/c2j.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/elf.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/export_notes_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/flowchart_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/refresh_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/report_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/save_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/save_as_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/settings_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/icons/widgets_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/schema.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/ui/__init__.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/ui/renderers.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/ui/tables.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui/ui/widgets.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui.egg-info/SOURCES.txt +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui.egg-info/dependency_links.txt +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui.egg-info/requires.txt +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/src/struct2ui.egg-info/top_level.txt +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_bin_emitter.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_c_emitter.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_c_parser.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_choices.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_elf_verifier.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_float_precision.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_int_checkbox.py +0 -0
- {struct2ui-0.4.0 → struct2ui-0.4.1}/tests/test_json_format.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.1
|
|
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
|
|
@@ -87,9 +87,10 @@ from struct2ui import StructEditor
|
|
|
87
87
|
|
|
88
88
|
app = QtWidgets.QApplication([])
|
|
89
89
|
|
|
90
|
-
editor = StructEditor(
|
|
91
|
-
|
|
92
|
-
cfg_dir="cfg_t", # modules dir: *.json holding struct/enum/typedef
|
|
90
|
+
editor = StructEditor()
|
|
91
|
+
editor.set_sources(
|
|
92
|
+
cfg_dir="cfg_t", # modules dir: *.json holding struct/enum/typedef
|
|
93
|
+
flow_file="abc.json", # pipeline definition file
|
|
93
94
|
)
|
|
94
95
|
editor.resize(480, 600)
|
|
95
96
|
editor.show()
|
|
@@ -246,28 +247,48 @@ from struct2ui import StructEditor
|
|
|
246
247
|
class MyWindow(QtWidgets.QMainWindow):
|
|
247
248
|
def __init__(self):
|
|
248
249
|
super().__init__()
|
|
249
|
-
editor = StructEditor(
|
|
250
|
-
|
|
251
|
-
settings_org="MyCompany", # custom QSettings scope to
|
|
252
|
-
settings_app="MyApp", # avoid clashing with the host app
|
|
253
|
-
)
|
|
250
|
+
editor = StructEditor()
|
|
251
|
+
editor.set_sources(cfg_dir="cfg_t", flow_file="abc.json")
|
|
254
252
|
self.setCentralWidget(editor)
|
|
255
253
|
```
|
|
256
254
|
|
|
255
|
+
`StructEditor` takes no source paths at construction time and keeps no
|
|
256
|
+
persistent state of its own. Point it at its sources after creating it with
|
|
257
|
+
`set_sources()` (or let the user pick them at runtime via Settings). If you
|
|
258
|
+
want to remember the last-used paths across runs, store them in the host app
|
|
259
|
+
and call `set_sources()` again at startup.
|
|
260
|
+
|
|
257
261
|
### Constructor Parameters
|
|
258
262
|
|
|
259
263
|
| Parameter | Description |
|
|
260
264
|
| --- | --- |
|
|
261
|
-
| `flow_file` | Path to the pipeline JSON file (pipeline definition), defaults to `None`; pick it in the UI when omitted |
|
|
262
|
-
| `cfg_dir` | Modules directory holding `*.json` (struct / enum / typedef definitions), defaults to `None`; pick it in the UI when omitted |
|
|
263
|
-
| `elf_file` | Path to an ELF for layout verification, defaults to `None`; pick it under Settings when omitted. The enable checkbox there toggles verification on/off while keeping the path. |
|
|
264
265
|
| `parent` | Qt parent object, defaults to `None` |
|
|
265
266
|
| `appearance` | Button appearance overrides, `{key: {'mode': ..., 'icon': ..., 'text': ...}}` |
|
|
266
|
-
| `settings_org` | QSettings organization name, defaults to `'struct2ui'` |
|
|
267
|
-
| `settings_app` | QSettings application name, defaults to `'StructEditor'` |
|
|
268
|
-
| `toolbar_orientation` | Toolbar layout, `'horizontal'` (default) or `'vertical'` |
|
|
269
267
|
| `custom_button_position` | Where `add_custom_button()` drops buttons relative to the built-ins: `'end'` (after, default) or `'start'` (before / far left) |
|
|
270
268
|
|
|
269
|
+
### Setting Sources
|
|
270
|
+
|
|
271
|
+
Source paths are configured after construction, not passed to the constructor.
|
|
272
|
+
Omitting an argument leaves that slot untouched.
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
editor.set_sources(
|
|
276
|
+
cfg_dir="cfg_t", # modules dir: *.json with struct/enum/typedef defs
|
|
277
|
+
flow_file="abc.json", # pipeline definition file
|
|
278
|
+
elf_file="fw.elf", # optional ELF for .bin layout verification
|
|
279
|
+
)
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
| `set_sources` argument | Description |
|
|
283
|
+
| --- | --- |
|
|
284
|
+
| `cfg_dir` | Modules directory holding `*.json` (struct / enum / typedef definitions) |
|
|
285
|
+
| `flow_file` | Path to the pipeline JSON file (pipeline definition) |
|
|
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
|
+
| `elf_enabled` | Override whether ELF verification runs, independent of whether a path is set |
|
|
288
|
+
| `reload` | Rebuild schema / flow / UI from the new sources, defaults to `True` |
|
|
289
|
+
|
|
290
|
+
Toolbar orientation is set with `set_flow_orientation('horizontal' | 'vertical')`.
|
|
291
|
+
|
|
271
292
|
## Custom Toolbar Buttons
|
|
272
293
|
|
|
273
294
|
Host applications can add their own buttons to the top path bar via
|
|
@@ -276,7 +297,8 @@ the built-in buttons by a divider that is added automatically — you only choos
|
|
|
276
297
|
which side they sit on (once, via the `custom_button_position` constructor arg).
|
|
277
298
|
|
|
278
299
|
```python
|
|
279
|
-
editor = StructEditor(
|
|
300
|
+
editor = StructEditor(custom_button_position="end")
|
|
301
|
+
editor.set_sources(cfg_dir="cfg_t", flow_file="abc.json")
|
|
280
302
|
|
|
281
303
|
def on_send():
|
|
282
304
|
print(editor.current_values())
|
|
@@ -306,8 +328,12 @@ from code (e.g. wired to a custom button):
|
|
|
306
328
|
|
|
307
329
|
| Method | Description |
|
|
308
330
|
| --- | --- |
|
|
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). |
|
|
332
|
+
| `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
|
+
| `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. |
|
|
309
334
|
| `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
|
|
310
335
|
| `current_paths() -> dict` | Current `{'modules', 'pipeline', 'elf'}` file paths; an empty string means that slot is unset. |
|
|
336
|
+
| `add_custom_button(text, on_click, icon=None, checkable=False) -> QPushButton` | Add a host button to the top path bar. See [Custom Toolbar Buttons](#custom-toolbar-buttons). |
|
|
311
337
|
| `export_bin(path, show_dialogs=False) -> bool` | Write the current pipeline to a `.bin` at `path` — the programmatic equivalent of clicking Export → Binary. Returns `True` when there are no ELF layout errors (or ELF verification is off), `False` otherwise. |
|
|
312
338
|
|
|
313
339
|
`export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
|
|
@@ -346,7 +372,7 @@ from struct2ui.exporters import (
|
|
|
346
372
|
| Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
|
|
347
373
|
| UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
|
|
348
374
|
| Export | `struct2ui.exporters` | C / JSON / bin export, C source reverse parsing, ELF verification |
|
|
349
|
-
| Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel
|
|
375
|
+
| Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel |
|
|
350
376
|
|
|
351
377
|
## Development
|
|
352
378
|
|
|
@@ -34,9 +34,10 @@ from struct2ui import StructEditor
|
|
|
34
34
|
|
|
35
35
|
app = QtWidgets.QApplication([])
|
|
36
36
|
|
|
37
|
-
editor = StructEditor(
|
|
38
|
-
|
|
39
|
-
cfg_dir="cfg_t", # modules dir: *.json holding struct/enum/typedef
|
|
37
|
+
editor = StructEditor()
|
|
38
|
+
editor.set_sources(
|
|
39
|
+
cfg_dir="cfg_t", # modules dir: *.json holding struct/enum/typedef
|
|
40
|
+
flow_file="abc.json", # pipeline definition file
|
|
40
41
|
)
|
|
41
42
|
editor.resize(480, 600)
|
|
42
43
|
editor.show()
|
|
@@ -193,28 +194,48 @@ from struct2ui import StructEditor
|
|
|
193
194
|
class MyWindow(QtWidgets.QMainWindow):
|
|
194
195
|
def __init__(self):
|
|
195
196
|
super().__init__()
|
|
196
|
-
editor = StructEditor(
|
|
197
|
-
|
|
198
|
-
settings_org="MyCompany", # custom QSettings scope to
|
|
199
|
-
settings_app="MyApp", # avoid clashing with the host app
|
|
200
|
-
)
|
|
197
|
+
editor = StructEditor()
|
|
198
|
+
editor.set_sources(cfg_dir="cfg_t", flow_file="abc.json")
|
|
201
199
|
self.setCentralWidget(editor)
|
|
202
200
|
```
|
|
203
201
|
|
|
202
|
+
`StructEditor` takes no source paths at construction time and keeps no
|
|
203
|
+
persistent state of its own. Point it at its sources after creating it with
|
|
204
|
+
`set_sources()` (or let the user pick them at runtime via Settings). If you
|
|
205
|
+
want to remember the last-used paths across runs, store them in the host app
|
|
206
|
+
and call `set_sources()` again at startup.
|
|
207
|
+
|
|
204
208
|
### Constructor Parameters
|
|
205
209
|
|
|
206
210
|
| Parameter | Description |
|
|
207
211
|
| --- | --- |
|
|
208
|
-
| `flow_file` | Path to the pipeline JSON file (pipeline definition), defaults to `None`; pick it in the UI when omitted |
|
|
209
|
-
| `cfg_dir` | Modules directory holding `*.json` (struct / enum / typedef definitions), defaults to `None`; pick it in the UI when omitted |
|
|
210
|
-
| `elf_file` | Path to an ELF for layout verification, defaults to `None`; pick it under Settings when omitted. The enable checkbox there toggles verification on/off while keeping the path. |
|
|
211
212
|
| `parent` | Qt parent object, defaults to `None` |
|
|
212
213
|
| `appearance` | Button appearance overrides, `{key: {'mode': ..., 'icon': ..., 'text': ...}}` |
|
|
213
|
-
| `settings_org` | QSettings organization name, defaults to `'struct2ui'` |
|
|
214
|
-
| `settings_app` | QSettings application name, defaults to `'StructEditor'` |
|
|
215
|
-
| `toolbar_orientation` | Toolbar layout, `'horizontal'` (default) or `'vertical'` |
|
|
216
214
|
| `custom_button_position` | Where `add_custom_button()` drops buttons relative to the built-ins: `'end'` (after, default) or `'start'` (before / far left) |
|
|
217
215
|
|
|
216
|
+
### Setting Sources
|
|
217
|
+
|
|
218
|
+
Source paths are configured after construction, not passed to the constructor.
|
|
219
|
+
Omitting an argument leaves that slot untouched.
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
editor.set_sources(
|
|
223
|
+
cfg_dir="cfg_t", # modules dir: *.json with struct/enum/typedef defs
|
|
224
|
+
flow_file="abc.json", # pipeline definition file
|
|
225
|
+
elf_file="fw.elf", # optional ELF for .bin layout verification
|
|
226
|
+
)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
| `set_sources` argument | Description |
|
|
230
|
+
| --- | --- |
|
|
231
|
+
| `cfg_dir` | Modules directory holding `*.json` (struct / enum / typedef definitions) |
|
|
232
|
+
| `flow_file` | Path to the pipeline JSON file (pipeline definition) |
|
|
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
|
+
| `elf_enabled` | Override whether ELF verification runs, independent of whether a path is set |
|
|
235
|
+
| `reload` | Rebuild schema / flow / UI from the new sources, defaults to `True` |
|
|
236
|
+
|
|
237
|
+
Toolbar orientation is set with `set_flow_orientation('horizontal' | 'vertical')`.
|
|
238
|
+
|
|
218
239
|
## Custom Toolbar Buttons
|
|
219
240
|
|
|
220
241
|
Host applications can add their own buttons to the top path bar via
|
|
@@ -223,7 +244,8 @@ the built-in buttons by a divider that is added automatically — you only choos
|
|
|
223
244
|
which side they sit on (once, via the `custom_button_position` constructor arg).
|
|
224
245
|
|
|
225
246
|
```python
|
|
226
|
-
editor = StructEditor(
|
|
247
|
+
editor = StructEditor(custom_button_position="end")
|
|
248
|
+
editor.set_sources(cfg_dir="cfg_t", flow_file="abc.json")
|
|
227
249
|
|
|
228
250
|
def on_send():
|
|
229
251
|
print(editor.current_values())
|
|
@@ -253,8 +275,12 @@ from code (e.g. wired to a custom button):
|
|
|
253
275
|
|
|
254
276
|
| Method | Description |
|
|
255
277
|
| --- | --- |
|
|
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). |
|
|
279
|
+
| `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
|
+
| `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. |
|
|
256
281
|
| `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
|
|
257
282
|
| `current_paths() -> dict` | Current `{'modules', 'pipeline', 'elf'}` file paths; an empty string means that slot is unset. |
|
|
283
|
+
| `add_custom_button(text, on_click, icon=None, checkable=False) -> QPushButton` | Add a host button to the top path bar. See [Custom Toolbar Buttons](#custom-toolbar-buttons). |
|
|
258
284
|
| `export_bin(path, show_dialogs=False) -> bool` | Write the current pipeline to a `.bin` at `path` — the programmatic equivalent of clicking Export → Binary. Returns `True` when there are no ELF layout errors (or ELF verification is off), `False` otherwise. |
|
|
259
285
|
|
|
260
286
|
`export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
|
|
@@ -293,7 +319,7 @@ from struct2ui.exporters import (
|
|
|
293
319
|
| Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
|
|
294
320
|
| UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
|
|
295
321
|
| Export | `struct2ui.exporters` | C / JSON / bin export, C source reverse parsing, ELF verification |
|
|
296
|
-
| Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel
|
|
322
|
+
| Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel |
|
|
297
323
|
|
|
298
324
|
## Development
|
|
299
325
|
|
|
@@ -69,10 +69,34 @@ class _OverflowBar(QtWidgets.QWidget):
|
|
|
69
69
|
self.overflow_btn.hide()
|
|
70
70
|
self._tail: QtWidgets.QWidget = None # type: ignore[assignment]
|
|
71
71
|
|
|
72
|
+
# Modern, borderless toolbar look: buttons are flat by default and
|
|
73
|
+
# only grow a subtle rounded background on hover / press / check.
|
|
74
|
+
# Scoped to this bar's child buttons so a host application's other
|
|
75
|
+
# QPushButtons are left untouched.
|
|
76
|
+
self.setStyleSheet(
|
|
77
|
+
'QPushButton, QToolButton {'
|
|
78
|
+
' border: none;'
|
|
79
|
+
' background: transparent;'
|
|
80
|
+
' border-radius: 4px;'
|
|
81
|
+
' padding: 4px;'
|
|
82
|
+
'}'
|
|
83
|
+
'QPushButton:hover, QToolButton:hover {'
|
|
84
|
+
' background: rgba(0, 0, 0, 28);'
|
|
85
|
+
'}'
|
|
86
|
+
'QPushButton:pressed, QToolButton:pressed,'
|
|
87
|
+
' QPushButton:checked, QToolButton:checked {'
|
|
88
|
+
' background: rgba(0, 0, 0, 50);'
|
|
89
|
+
'}'
|
|
90
|
+
'QToolButton::menu-indicator { image: none; width: 0; }'
|
|
91
|
+
)
|
|
92
|
+
|
|
72
93
|
def _make_separator(self):
|
|
94
|
+
# A thin flat rule that matches the borderless buttons, instead of the
|
|
95
|
+
# heavier sunken VLine bevel. Drawn as a 1px coloured block so the
|
|
96
|
+
# shade is reliable across styles (QFrame's VLine ignores QSS color).
|
|
73
97
|
line = QtWidgets.QFrame(self)
|
|
74
|
-
line.
|
|
75
|
-
line.
|
|
98
|
+
line.setFixedWidth(1)
|
|
99
|
+
line.setStyleSheet('background: rgba(0, 0, 0, 40);')
|
|
76
100
|
return line
|
|
77
101
|
|
|
78
102
|
def set_buttons(self, buttons, tail, separators=None):
|
|
@@ -164,7 +188,17 @@ class _OverflowBar(QtWidgets.QWidget):
|
|
|
164
188
|
overflow_w = self.overflow_btn.sizeHint().width() + spacing
|
|
165
189
|
available = self.width() - reserved
|
|
166
190
|
|
|
167
|
-
|
|
191
|
+
# Each button's footprint includes the group divider drawn to its left
|
|
192
|
+
# (when it has one and isn't the first item), since that divider also
|
|
193
|
+
# takes room in the row. Skipping it underestimates the width and lets
|
|
194
|
+
# a button that doesn't actually fit stay visible.
|
|
195
|
+
widths = []
|
|
196
|
+
for idx, (btn, _label, _cb) in enumerate(self._buttons):
|
|
197
|
+
w = btn.sizeHint().width() + spacing
|
|
198
|
+
sep = self._separators.get(btn)
|
|
199
|
+
if sep is not None and idx > 0:
|
|
200
|
+
w += sep.sizeHint().width() + spacing
|
|
201
|
+
widths.append(w)
|
|
168
202
|
total = sum(widths)
|
|
169
203
|
|
|
170
204
|
if total <= available:
|
|
@@ -230,12 +264,8 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
230
264
|
'SP_FileDialogDetailedView'),
|
|
231
265
|
}
|
|
232
266
|
|
|
233
|
-
def __init__(self,
|
|
234
|
-
elf_file: str = None, parent=None,
|
|
267
|
+
def __init__(self, parent=None,
|
|
235
268
|
appearance: Dict[str, Dict[str, Any]] = None,
|
|
236
|
-
settings_org: str = 'struct2ui',
|
|
237
|
-
settings_app: str = 'StructEditor',
|
|
238
|
-
toolbar_orientation: str = 'horizontal',
|
|
239
269
|
custom_button_position: str = 'end'):
|
|
240
270
|
super().__init__(parent)
|
|
241
271
|
# Where add_custom_button() drops new buttons relative to the built-in
|
|
@@ -253,22 +283,25 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
253
283
|
self._appearance: Dict[str, Dict[str, Any]] = appearance or {}
|
|
254
284
|
# Flow-button strip orientation: 'horizontal' (top, default) keeps the
|
|
255
285
|
# legacy stacked layout; 'vertical' moves the strip to the left so the
|
|
256
|
-
# long row of stage buttons stops eating horizontal width.
|
|
257
|
-
|
|
258
|
-
|
|
286
|
+
# long row of stage buttons stops eating horizontal width. Change it at
|
|
287
|
+
# runtime with set_flow_orientation().
|
|
288
|
+
self._flow_orientation = 'horizontal'
|
|
259
289
|
self._icons_dir = os.path.join(
|
|
260
290
|
os.path.dirname(os.path.abspath(__file__)), 'icons')
|
|
261
|
-
#
|
|
262
|
-
#
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
#
|
|
270
|
-
|
|
271
|
-
|
|
291
|
+
# Sources start empty: a host app points them somewhere after
|
|
292
|
+
# construction via set_sources(), or the user picks them through the
|
|
293
|
+
# Settings panel. Nothing is persisted across runs - a host app that
|
|
294
|
+
# wants memory should call set_sources() again at startup.
|
|
295
|
+
# The last export format is remembered only for this session.
|
|
296
|
+
self._last_export_type = 'c'
|
|
297
|
+
self.pipeline_path = ''
|
|
298
|
+
self.struct_dir = ''
|
|
299
|
+
# Optional ELF for later .bin layout verification. The path persists
|
|
300
|
+
# once set; the enable flag (driven by the Settings checkbox) decides
|
|
301
|
+
# whether verification actually runs, so the user can toggle it off and
|
|
302
|
+
# back on without re-picking the file.
|
|
303
|
+
self.elf_path = ''
|
|
304
|
+
self.elf_enabled = False
|
|
272
305
|
# Line edits that mirror the source paths inside the Settings panel.
|
|
273
306
|
# Empty until _make_settings_panel builds the panel; the path-refresh
|
|
274
307
|
# helpers no-op while it is empty.
|
|
@@ -559,6 +592,31 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
559
592
|
|
|
560
593
|
return elf_ok
|
|
561
594
|
|
|
595
|
+
def set_sources(self, cfg_dir: str = None, flow_file: str = None,
|
|
596
|
+
elf_file: str = None, elf_enabled: bool = None,
|
|
597
|
+
reload: bool = True) -> None:
|
|
598
|
+
"""Point the editor at its source files after construction.
|
|
599
|
+
|
|
600
|
+
Each path argument is applied only when given (pass ``None`` to leave
|
|
601
|
+
that slot untouched). Setting ``elf_file`` turns ELF verification on by
|
|
602
|
+
default; pass ``elf_enabled`` to override that. With ``reload=True``
|
|
603
|
+
(the default) the schema, flow and UI are rebuilt from the new sources,
|
|
604
|
+
mirroring a click on the Reload button.
|
|
605
|
+
"""
|
|
606
|
+
if cfg_dir is not None:
|
|
607
|
+
self.struct_dir = cfg_dir
|
|
608
|
+
if flow_file is not None:
|
|
609
|
+
self.pipeline_path = flow_file
|
|
610
|
+
if elf_file is not None:
|
|
611
|
+
self.elf_path = elf_file
|
|
612
|
+
if elf_enabled is None:
|
|
613
|
+
self.elf_enabled = bool(elf_file)
|
|
614
|
+
if elf_enabled is not None:
|
|
615
|
+
self._set_elf_enabled(elf_enabled)
|
|
616
|
+
self._refresh_path_tooltips()
|
|
617
|
+
if reload:
|
|
618
|
+
self._reload()
|
|
619
|
+
|
|
562
620
|
def current_paths(self) -> Dict[str, str]:
|
|
563
621
|
"""Return the current Modules / Pipeline / ELF file paths.
|
|
564
622
|
|
|
@@ -956,10 +1014,10 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
956
1014
|
}
|
|
957
1015
|
|
|
958
1016
|
def _on_export_clicked(self) -> None:
|
|
959
|
-
# Remember the last chosen export type; default to .c.
|
|
960
|
-
# type pre-selects the matching filter so the next
|
|
961
|
-
# what was used before.
|
|
962
|
-
last_type = self.
|
|
1017
|
+
# Remember the last chosen export type for this session; default to .c.
|
|
1018
|
+
# The remembered type pre-selects the matching filter so the next
|
|
1019
|
+
# export defaults to what was used before.
|
|
1020
|
+
last_type = self._last_export_type
|
|
963
1021
|
if last_type not in self._EXPORT_FILTERS:
|
|
964
1022
|
last_type = 'c'
|
|
965
1023
|
filters = ';;'.join(self._EXPORT_FILTERS.values())
|
|
@@ -978,7 +1036,7 @@ class StructEditor(QtWidgets.QWidget):
|
|
|
978
1036
|
'bin' if selected_filter == self._EXPORT_FILTERS['bin'] else 'c')
|
|
979
1037
|
if not ext:
|
|
980
1038
|
chosen = f'{chosen}.{export_type}'
|
|
981
|
-
self.
|
|
1039
|
+
self._last_export_type = export_type
|
|
982
1040
|
|
|
983
1041
|
# Strictest ELF check before a .bin export. The .bin is a raw image
|
|
984
1042
|
# of the target struct memory, so a layout mismatch with the ELF is
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: struct2ui
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
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
|
|
@@ -87,9 +87,10 @@ from struct2ui import StructEditor
|
|
|
87
87
|
|
|
88
88
|
app = QtWidgets.QApplication([])
|
|
89
89
|
|
|
90
|
-
editor = StructEditor(
|
|
91
|
-
|
|
92
|
-
cfg_dir="cfg_t", # modules dir: *.json holding struct/enum/typedef
|
|
90
|
+
editor = StructEditor()
|
|
91
|
+
editor.set_sources(
|
|
92
|
+
cfg_dir="cfg_t", # modules dir: *.json holding struct/enum/typedef
|
|
93
|
+
flow_file="abc.json", # pipeline definition file
|
|
93
94
|
)
|
|
94
95
|
editor.resize(480, 600)
|
|
95
96
|
editor.show()
|
|
@@ -246,28 +247,48 @@ from struct2ui import StructEditor
|
|
|
246
247
|
class MyWindow(QtWidgets.QMainWindow):
|
|
247
248
|
def __init__(self):
|
|
248
249
|
super().__init__()
|
|
249
|
-
editor = StructEditor(
|
|
250
|
-
|
|
251
|
-
settings_org="MyCompany", # custom QSettings scope to
|
|
252
|
-
settings_app="MyApp", # avoid clashing with the host app
|
|
253
|
-
)
|
|
250
|
+
editor = StructEditor()
|
|
251
|
+
editor.set_sources(cfg_dir="cfg_t", flow_file="abc.json")
|
|
254
252
|
self.setCentralWidget(editor)
|
|
255
253
|
```
|
|
256
254
|
|
|
255
|
+
`StructEditor` takes no source paths at construction time and keeps no
|
|
256
|
+
persistent state of its own. Point it at its sources after creating it with
|
|
257
|
+
`set_sources()` (or let the user pick them at runtime via Settings). If you
|
|
258
|
+
want to remember the last-used paths across runs, store them in the host app
|
|
259
|
+
and call `set_sources()` again at startup.
|
|
260
|
+
|
|
257
261
|
### Constructor Parameters
|
|
258
262
|
|
|
259
263
|
| Parameter | Description |
|
|
260
264
|
| --- | --- |
|
|
261
|
-
| `flow_file` | Path to the pipeline JSON file (pipeline definition), defaults to `None`; pick it in the UI when omitted |
|
|
262
|
-
| `cfg_dir` | Modules directory holding `*.json` (struct / enum / typedef definitions), defaults to `None`; pick it in the UI when omitted |
|
|
263
|
-
| `elf_file` | Path to an ELF for layout verification, defaults to `None`; pick it under Settings when omitted. The enable checkbox there toggles verification on/off while keeping the path. |
|
|
264
265
|
| `parent` | Qt parent object, defaults to `None` |
|
|
265
266
|
| `appearance` | Button appearance overrides, `{key: {'mode': ..., 'icon': ..., 'text': ...}}` |
|
|
266
|
-
| `settings_org` | QSettings organization name, defaults to `'struct2ui'` |
|
|
267
|
-
| `settings_app` | QSettings application name, defaults to `'StructEditor'` |
|
|
268
|
-
| `toolbar_orientation` | Toolbar layout, `'horizontal'` (default) or `'vertical'` |
|
|
269
267
|
| `custom_button_position` | Where `add_custom_button()` drops buttons relative to the built-ins: `'end'` (after, default) or `'start'` (before / far left) |
|
|
270
268
|
|
|
269
|
+
### Setting Sources
|
|
270
|
+
|
|
271
|
+
Source paths are configured after construction, not passed to the constructor.
|
|
272
|
+
Omitting an argument leaves that slot untouched.
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
editor.set_sources(
|
|
276
|
+
cfg_dir="cfg_t", # modules dir: *.json with struct/enum/typedef defs
|
|
277
|
+
flow_file="abc.json", # pipeline definition file
|
|
278
|
+
elf_file="fw.elf", # optional ELF for .bin layout verification
|
|
279
|
+
)
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
| `set_sources` argument | Description |
|
|
283
|
+
| --- | --- |
|
|
284
|
+
| `cfg_dir` | Modules directory holding `*.json` (struct / enum / typedef definitions) |
|
|
285
|
+
| `flow_file` | Path to the pipeline JSON file (pipeline definition) |
|
|
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
|
+
| `elf_enabled` | Override whether ELF verification runs, independent of whether a path is set |
|
|
288
|
+
| `reload` | Rebuild schema / flow / UI from the new sources, defaults to `True` |
|
|
289
|
+
|
|
290
|
+
Toolbar orientation is set with `set_flow_orientation('horizontal' | 'vertical')`.
|
|
291
|
+
|
|
271
292
|
## Custom Toolbar Buttons
|
|
272
293
|
|
|
273
294
|
Host applications can add their own buttons to the top path bar via
|
|
@@ -276,7 +297,8 @@ the built-in buttons by a divider that is added automatically — you only choos
|
|
|
276
297
|
which side they sit on (once, via the `custom_button_position` constructor arg).
|
|
277
298
|
|
|
278
299
|
```python
|
|
279
|
-
editor = StructEditor(
|
|
300
|
+
editor = StructEditor(custom_button_position="end")
|
|
301
|
+
editor.set_sources(cfg_dir="cfg_t", flow_file="abc.json")
|
|
280
302
|
|
|
281
303
|
def on_send():
|
|
282
304
|
print(editor.current_values())
|
|
@@ -306,8 +328,12 @@ from code (e.g. wired to a custom button):
|
|
|
306
328
|
|
|
307
329
|
| Method | Description |
|
|
308
330
|
| --- | --- |
|
|
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). |
|
|
332
|
+
| `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
|
+
| `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. |
|
|
309
334
|
| `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
|
|
310
335
|
| `current_paths() -> dict` | Current `{'modules', 'pipeline', 'elf'}` file paths; an empty string means that slot is unset. |
|
|
336
|
+
| `add_custom_button(text, on_click, icon=None, checkable=False) -> QPushButton` | Add a host button to the top path bar. See [Custom Toolbar Buttons](#custom-toolbar-buttons). |
|
|
311
337
|
| `export_bin(path, show_dialogs=False) -> bool` | Write the current pipeline to a `.bin` at `path` — the programmatic equivalent of clicking Export → Binary. Returns `True` when there are no ELF layout errors (or ELF verification is off), `False` otherwise. |
|
|
312
338
|
|
|
313
339
|
`export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
|
|
@@ -346,7 +372,7 @@ from struct2ui.exporters import (
|
|
|
346
372
|
| Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
|
|
347
373
|
| UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
|
|
348
374
|
| Export | `struct2ui.exporters` | C / JSON / bin export, C source reverse parsing, ELF verification |
|
|
349
|
-
| Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel
|
|
375
|
+
| Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel |
|
|
350
376
|
|
|
351
377
|
## Development
|
|
352
378
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
"""Tests for path handling (paths come from
|
|
1
|
+
"""Tests for path handling (paths come from set_sources(), not memory)."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
|
|
5
|
-
from Qt import
|
|
5
|
+
from Qt import QtWidgets
|
|
6
6
|
|
|
7
7
|
from struct2ui.editor import StructEditor
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def
|
|
11
|
-
|
|
10
|
+
def test_paths_come_from_set_sources(qapp, make_editor, real_cfg_dir,
|
|
11
|
+
real_flow):
|
|
12
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
12
13
|
assert w.pipeline_path == real_flow
|
|
13
14
|
assert w.struct_dir == real_cfg_dir
|
|
14
15
|
|
|
@@ -43,13 +44,27 @@ def _button_index(bar, btn):
|
|
|
43
44
|
return [b for b, _, _ in bar._buttons].index(btn)
|
|
44
45
|
|
|
45
46
|
|
|
46
|
-
def
|
|
47
|
-
|
|
47
|
+
def _button_footprints(bar):
|
|
48
|
+
spacing = bar._layout.spacing()
|
|
49
|
+
widths = []
|
|
50
|
+
for idx, (btn, _lbl, _cb) in enumerate(bar._buttons):
|
|
51
|
+
w = btn.sizeHint().width() + spacing
|
|
52
|
+
sep = bar._separators.get(btn)
|
|
53
|
+
if sep is not None and idx > 0:
|
|
54
|
+
w += sep.sizeHint().width() + spacing
|
|
55
|
+
widths.append(w)
|
|
56
|
+
return widths
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_path_bar_has_group_separators(qapp, make_editor, real_cfg_dir,
|
|
60
|
+
real_flow):
|
|
61
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
48
62
|
bar = w.path_bar
|
|
49
|
-
#
|
|
50
|
-
#
|
|
63
|
+
# One built-in group divider before the button at index 4. Source paths
|
|
64
|
+
# now live in the Settings panel, so the bar holds only action buttons:
|
|
65
|
+
# edit group [Reload, Save, Save As, Export] | tools group [C2J, Report].
|
|
51
66
|
sep_indices = sorted(_button_index(bar, b) for b in bar._separators)
|
|
52
|
-
assert sep_indices == [4
|
|
67
|
+
assert sep_indices == [4]
|
|
53
68
|
|
|
54
69
|
|
|
55
70
|
def test_custom_button_first_starts_group(qapp):
|
|
@@ -107,8 +122,9 @@ def test_separator_hidden_when_its_button_overflows(qapp):
|
|
|
107
122
|
assert sep.isHidden()
|
|
108
123
|
|
|
109
124
|
|
|
110
|
-
def test_overflow_menu_carries_group_separators(qapp,
|
|
111
|
-
|
|
125
|
+
def test_overflow_menu_carries_group_separators(qapp, make_editor,
|
|
126
|
+
real_cfg_dir, real_flow):
|
|
127
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
112
128
|
bar = w.path_bar
|
|
113
129
|
bar.resize(40, 40)
|
|
114
130
|
bar._relayout()
|
|
@@ -123,21 +139,9 @@ def test_overflow_menu_carries_group_separators(qapp, real_cfg_dir, real_flow):
|
|
|
123
139
|
assert len(sep_positions) == 1
|
|
124
140
|
|
|
125
141
|
|
|
126
|
-
def
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
new_flow = real_flow.replace('abc.json', 'speech.json')
|
|
130
|
-
w.pipeline_path = new_flow
|
|
131
|
-
w.struct_dir = real_cfg_dir
|
|
132
|
-
w._on_reload_clicked()
|
|
133
|
-
|
|
134
|
-
s = QtCore.QSettings('struct2ui', 'StructEditor')
|
|
135
|
-
assert s.value('flow_path') is None
|
|
136
|
-
assert s.value('cfg_dir') is None
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def test_new_editor_ignores_previous_paths(qapp, real_cfg_dir, real_flow):
|
|
140
|
-
first = StructEditor(real_flow, real_cfg_dir)
|
|
142
|
+
def test_new_editor_ignores_previous_paths(qapp, make_editor, real_cfg_dir,
|
|
143
|
+
real_flow):
|
|
144
|
+
first = make_editor(real_flow, real_cfg_dir)
|
|
141
145
|
first.pipeline_path = real_flow.replace('abc.json', 'speech.json')
|
|
142
146
|
first.struct_dir = real_cfg_dir
|
|
143
147
|
first._on_reload_clicked()
|
|
@@ -148,7 +152,7 @@ def test_new_editor_ignores_previous_paths(qapp, real_cfg_dir, real_flow):
|
|
|
148
152
|
|
|
149
153
|
|
|
150
154
|
def test_reload_new_pipeline_does_not_keep_old_edits(
|
|
151
|
-
qapp, real_cfg_dir, real_flow, tmp_path):
|
|
155
|
+
qapp, make_editor, real_cfg_dir, real_flow, tmp_path):
|
|
152
156
|
# Regression: switching to a different pipeline must show the new file's
|
|
153
157
|
# values, not the previous (still-displayed) section's edited values.
|
|
154
158
|
other = tmp_path / 'other.json'
|
|
@@ -157,7 +161,7 @@ def test_reload_new_pipeline_does_not_keep_old_edits(
|
|
|
157
161
|
data['ABC Test']['A']['items']['level'] = 7
|
|
158
162
|
other.write_text(json.dumps(data), encoding='utf-8')
|
|
159
163
|
|
|
160
|
-
w =
|
|
164
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
161
165
|
w._on_button_clicked('A')
|
|
162
166
|
spin = next(s for s in w._content_widget.findChildren(QtWidgets.QSpinBox)
|
|
163
167
|
if s.value() == 50)
|
|
@@ -176,21 +180,23 @@ def _flow_button_labels(w):
|
|
|
176
180
|
QtWidgets.QPushButton)]
|
|
177
181
|
|
|
178
182
|
|
|
179
|
-
def test_flow_orientation_defaults_to_horizontal(qapp,
|
|
180
|
-
|
|
183
|
+
def test_flow_orientation_defaults_to_horizontal(qapp, make_editor,
|
|
184
|
+
real_cfg_dir, real_flow):
|
|
185
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
181
186
|
assert w._flow_orientation == 'horizontal'
|
|
182
187
|
assert isinstance(w.buttons_layout, QtWidgets.QHBoxLayout)
|
|
183
188
|
|
|
184
189
|
|
|
185
|
-
def
|
|
186
|
-
|
|
190
|
+
def test_flow_orientation_vertical_via_api(qapp, make_editor, real_cfg_dir,
|
|
191
|
+
real_flow):
|
|
192
|
+
w = make_editor(real_flow, real_cfg_dir, toolbar_orientation='vertical')
|
|
187
193
|
assert w._flow_orientation == 'vertical'
|
|
188
194
|
assert isinstance(w.buttons_layout, QtWidgets.QVBoxLayout)
|
|
189
195
|
|
|
190
196
|
|
|
191
197
|
def test_set_flow_orientation_flips_layout_and_keeps_buttons(
|
|
192
|
-
qapp, real_cfg_dir, real_flow):
|
|
193
|
-
w =
|
|
198
|
+
qapp, make_editor, real_cfg_dir, real_flow):
|
|
199
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
194
200
|
before = _flow_button_labels(w)
|
|
195
201
|
assert isinstance(w.buttons_layout, QtWidgets.QHBoxLayout)
|
|
196
202
|
|
|
@@ -203,8 +209,9 @@ def test_set_flow_orientation_flips_layout_and_keeps_buttons(
|
|
|
203
209
|
assert _flow_button_labels(w) == before
|
|
204
210
|
|
|
205
211
|
|
|
206
|
-
def test_path_bar_shows_all_buttons_when_wide(qapp, real_cfg_dir,
|
|
207
|
-
|
|
212
|
+
def test_path_bar_shows_all_buttons_when_wide(qapp, make_editor, real_cfg_dir,
|
|
213
|
+
real_flow):
|
|
214
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
208
215
|
bar = w.path_bar
|
|
209
216
|
bar.resize(2000, 40)
|
|
210
217
|
bar._relayout()
|
|
@@ -214,21 +221,21 @@ def test_path_bar_shows_all_buttons_when_wide(qapp, real_cfg_dir, real_flow):
|
|
|
214
221
|
|
|
215
222
|
|
|
216
223
|
def test_path_bar_overflows_rightmost_buttons_when_narrow(
|
|
217
|
-
qapp, real_cfg_dir, real_flow):
|
|
218
|
-
w =
|
|
224
|
+
qapp, make_editor, real_cfg_dir, real_flow):
|
|
225
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
219
226
|
bar = w.path_bar
|
|
220
227
|
spacing = bar._layout.spacing()
|
|
221
228
|
tail = bar._tail.sizeHint().width() + spacing
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
#
|
|
225
|
-
#
|
|
226
|
-
width = tail +
|
|
229
|
+
btn_w = _button_footprints(bar)
|
|
230
|
+
# Too narrow to hold every button: leave room for the tail and all but the
|
|
231
|
+
# last button, with no slack for the overflow control. The bar must then
|
|
232
|
+
# collapse from the right, hiding at least the rightmost button.
|
|
233
|
+
width = tail + sum(btn_w[:-1])
|
|
227
234
|
bar.resize(width, 40)
|
|
228
235
|
bar._relayout()
|
|
229
236
|
assert not bar.overflow_btn.isHidden()
|
|
230
237
|
assert bar.overflow_menu.actions()
|
|
231
|
-
# Leftmost button stays; rightmost button overflows first.
|
|
238
|
+
# Leftmost button stays; the rightmost button overflows first.
|
|
232
239
|
assert not bar._buttons[0][0].isHidden()
|
|
233
240
|
assert bar._buttons[-1][0].isHidden()
|
|
234
241
|
# Order is preserved (no reordering happened).
|
|
@@ -237,13 +244,13 @@ def test_path_bar_overflows_rightmost_buttons_when_narrow(
|
|
|
237
244
|
|
|
238
245
|
|
|
239
246
|
def test_path_bar_overflows_multiple_buttons_at_once(
|
|
240
|
-
qapp, real_cfg_dir, real_flow):
|
|
241
|
-
w =
|
|
247
|
+
qapp, make_editor, real_cfg_dir, real_flow):
|
|
248
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
242
249
|
bar = w.path_bar
|
|
243
250
|
spacing = bar._layout.spacing()
|
|
244
251
|
tail = bar._tail.sizeHint().width() + spacing
|
|
245
252
|
overflow = bar.overflow_btn.sizeHint().width() + spacing
|
|
246
|
-
btn_w =
|
|
253
|
+
btn_w = _button_footprints(bar)
|
|
247
254
|
# Only enough room for the first two buttons; the rest must all overflow
|
|
248
255
|
# in a single relayout pass.
|
|
249
256
|
width = tail + overflow + btn_w[0] + btn_w[1]
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
"""Tests for the load-report summary panel (Step 5 A + B)."""
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
4
|
|
|
5
5
|
from Qt import QtCore, QtWidgets
|
|
6
6
|
|
|
7
|
-
from struct2ui.editor import StructEditor
|
|
8
|
-
|
|
9
7
|
|
|
10
8
|
STAGE_ERROR_PIPELINE = {
|
|
11
9
|
'ABC Test': {
|
|
@@ -49,18 +47,20 @@ def _checked_buttons(widget):
|
|
|
49
47
|
|
|
50
48
|
# ---- A: clickable summary rows ------------------------------------------- #
|
|
51
49
|
|
|
52
|
-
def test_summary_stage_row_is_clickable(qapp, real_cfg_dir,
|
|
50
|
+
def test_summary_stage_row_is_clickable(qapp, make_editor, real_cfg_dir,
|
|
51
|
+
write_flow):
|
|
53
52
|
flow = write_flow(STAGE_ERROR_PIPELINE)
|
|
54
|
-
w =
|
|
53
|
+
w = make_editor(flow, real_cfg_dir)
|
|
55
54
|
|
|
56
55
|
stage_rows = [it for it in _list_items(w._content_widget)
|
|
57
56
|
if it.data(QtCore.Qt.UserRole) is not None]
|
|
58
57
|
assert any(it.data(QtCore.Qt.UserRole) == 'A' for it in stage_rows)
|
|
59
58
|
|
|
60
59
|
|
|
61
|
-
def test_activating_stage_row_opens_tab(qapp, real_cfg_dir,
|
|
60
|
+
def test_activating_stage_row_opens_tab(qapp, make_editor, real_cfg_dir,
|
|
61
|
+
write_flow):
|
|
62
62
|
flow = write_flow(STAGE_ERROR_PIPELINE)
|
|
63
|
-
w =
|
|
63
|
+
w = make_editor(flow, real_cfg_dir)
|
|
64
64
|
|
|
65
65
|
row_a = next(it for it in _list_items(w._content_widget)
|
|
66
66
|
if it.data(QtCore.Qt.UserRole) == 'A')
|
|
@@ -72,20 +72,21 @@ def test_activating_stage_row_opens_tab(qapp, real_cfg_dir, write_flow):
|
|
|
72
72
|
|
|
73
73
|
# ---- B: non-stage errors shown in full ----------------------------------- #
|
|
74
74
|
|
|
75
|
-
def test_other_errors_collected(qapp, cfg_dir_with, write_flow):
|
|
75
|
+
def test_other_errors_collected(qapp, make_editor, cfg_dir_with, write_flow):
|
|
76
76
|
cfg = cfg_dir_with({'bad_cfg_t': BAD_CFG})
|
|
77
77
|
flow = write_flow(STAGE_ERROR_PIPELINE)
|
|
78
|
-
w =
|
|
78
|
+
w = make_editor(flow, cfg)
|
|
79
79
|
|
|
80
80
|
others = w._other_errors()
|
|
81
81
|
assert len(others) == 2
|
|
82
82
|
assert all('bad_struct' in e.path for e in others)
|
|
83
83
|
|
|
84
84
|
|
|
85
|
-
def test_other_errors_rendered_in_summary(qapp, cfg_dir_with,
|
|
85
|
+
def test_other_errors_rendered_in_summary(qapp, make_editor, cfg_dir_with,
|
|
86
|
+
write_flow):
|
|
86
87
|
cfg = cfg_dir_with({'bad_cfg_t': BAD_CFG})
|
|
87
88
|
flow = write_flow(STAGE_ERROR_PIPELINE)
|
|
88
|
-
w =
|
|
89
|
+
w = make_editor(flow, cfg)
|
|
89
90
|
|
|
90
91
|
panel = w._content_widget
|
|
91
92
|
texts = [it.text() for it in _list_items(panel)]
|
|
@@ -11,9 +11,7 @@ import shutil
|
|
|
11
11
|
|
|
12
12
|
import pytest
|
|
13
13
|
|
|
14
|
-
from Qt import
|
|
15
|
-
|
|
16
|
-
from struct2ui.editor import StructEditor
|
|
14
|
+
from Qt import QtWidgets
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
@pytest.fixture
|
|
@@ -42,8 +40,8 @@ def _spin(widget, value):
|
|
|
42
40
|
return None
|
|
43
41
|
|
|
44
42
|
|
|
45
|
-
def test_save_preserves_structure(qapp, real_cfg_dir, flow_copy):
|
|
46
|
-
w =
|
|
43
|
+
def test_save_preserves_structure(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
44
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
47
45
|
w._on_button_clicked('A')
|
|
48
46
|
w._on_save_clicked()
|
|
49
47
|
|
|
@@ -55,8 +53,8 @@ def test_save_preserves_structure(qapp, real_cfg_dir, flow_copy):
|
|
|
55
53
|
assert group['A']['items']['level'] == 50
|
|
56
54
|
|
|
57
55
|
|
|
58
|
-
def test_edit_then_save_persists(qapp, real_cfg_dir, flow_copy):
|
|
59
|
-
w =
|
|
56
|
+
def test_edit_then_save_persists(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
57
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
60
58
|
w._on_button_clicked('A')
|
|
61
59
|
|
|
62
60
|
spin = _spin(w._content_widget, 50)
|
|
@@ -70,8 +68,9 @@ def test_edit_then_save_persists(qapp, real_cfg_dir, flow_copy):
|
|
|
70
68
|
assert data['ABC Test']['A']['items']['level'] == 88
|
|
71
69
|
|
|
72
70
|
|
|
73
|
-
def test_edit_survives_section_switch(qapp, real_cfg_dir,
|
|
74
|
-
|
|
71
|
+
def test_edit_survives_section_switch(qapp, make_editor, real_cfg_dir,
|
|
72
|
+
flow_copy):
|
|
73
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
75
74
|
w._on_button_clicked('A')
|
|
76
75
|
spin = _spin(w._content_widget, 50)
|
|
77
76
|
spin.setValue(77)
|
|
@@ -84,8 +83,9 @@ def test_edit_survives_section_switch(qapp, real_cfg_dir, flow_copy):
|
|
|
84
83
|
assert data['ABC Test']['A']['items']['level'] == 77
|
|
85
84
|
|
|
86
85
|
|
|
87
|
-
def test_save_as_redirects_path(qapp, real_cfg_dir, flow_copy,
|
|
88
|
-
|
|
86
|
+
def test_save_as_redirects_path(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
87
|
+
tmp_path):
|
|
88
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
89
89
|
w._on_button_clicked('A')
|
|
90
90
|
|
|
91
91
|
target = str(tmp_path / 'other.json')
|
|
@@ -99,9 +99,9 @@ def test_save_as_redirects_path(qapp, real_cfg_dir, flow_copy, tmp_path):
|
|
|
99
99
|
assert data['ABC Test']['A']['items']['level'] == 50
|
|
100
100
|
|
|
101
101
|
|
|
102
|
-
def test_export_defaults_to_c(qapp, real_cfg_dir, flow_copy,
|
|
103
|
-
monkeypatch):
|
|
104
|
-
w =
|
|
102
|
+
def test_export_defaults_to_c(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
103
|
+
tmp_path, monkeypatch):
|
|
104
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
105
105
|
target = str(tmp_path / 'out.c')
|
|
106
106
|
monkeypatch.setattr(
|
|
107
107
|
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
@@ -114,13 +114,12 @@ def test_export_defaults_to_c(qapp, real_cfg_dir, flow_copy, tmp_path,
|
|
|
114
114
|
assert 'a_cfg_t A = {' in text
|
|
115
115
|
assert '.level = 50' in text
|
|
116
116
|
assert '.mode = A_MODE_HIGH' in text
|
|
117
|
-
|
|
118
|
-
assert s.value('export_type') == 'c'
|
|
117
|
+
assert w._last_export_type == 'c'
|
|
119
118
|
|
|
120
119
|
|
|
121
|
-
def test_export_remembers_bin_type(qapp, real_cfg_dir, flow_copy,
|
|
122
|
-
monkeypatch):
|
|
123
|
-
w =
|
|
120
|
+
def test_export_remembers_bin_type(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
121
|
+
tmp_path, monkeypatch):
|
|
122
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
124
123
|
target = str(tmp_path / 'out.bin')
|
|
125
124
|
monkeypatch.setattr(
|
|
126
125
|
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
@@ -131,31 +130,29 @@ def test_export_remembers_bin_type(qapp, real_cfg_dir, flow_copy, tmp_path,
|
|
|
131
130
|
assert os.path.exists(target)
|
|
132
131
|
data = open(target, 'rb').read()
|
|
133
132
|
assert len(data) > 0
|
|
134
|
-
|
|
135
|
-
assert s.value('export_type') == 'bin'
|
|
133
|
+
assert w._last_export_type == 'bin'
|
|
136
134
|
|
|
137
135
|
|
|
138
|
-
def test_export_cancel_does_nothing(qapp, real_cfg_dir, flow_copy,
|
|
136
|
+
def test_export_cancel_does_nothing(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
139
137
|
monkeypatch):
|
|
140
|
-
w =
|
|
138
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
141
139
|
monkeypatch.setattr(
|
|
142
140
|
QtWidgets.QFileDialog, 'getSaveFileName',
|
|
143
141
|
lambda *a, **k: ('', ''))
|
|
144
142
|
|
|
145
143
|
w._on_export_clicked()
|
|
146
144
|
|
|
147
|
-
|
|
148
|
-
assert s.value('export_type') is None
|
|
145
|
+
assert w._last_export_type == 'c'
|
|
149
146
|
|
|
150
147
|
|
|
151
|
-
def test_elf_starts_unselected(qapp, real_cfg_dir, flow_copy):
|
|
152
|
-
w =
|
|
148
|
+
def test_elf_starts_unselected(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
149
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
153
150
|
assert w.elf_path == ''
|
|
154
151
|
|
|
155
152
|
|
|
156
|
-
def test_pick_elf_sets_path(qapp, real_cfg_dir, flow_copy,
|
|
157
|
-
monkeypatch):
|
|
158
|
-
w =
|
|
153
|
+
def test_pick_elf_sets_path(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
154
|
+
tmp_path, monkeypatch):
|
|
155
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
159
156
|
elf = str(tmp_path / 'fw.elf')
|
|
160
157
|
open(elf, 'wb').close()
|
|
161
158
|
monkeypatch.setattr(
|
|
@@ -164,14 +161,12 @@ def test_pick_elf_sets_path(qapp, real_cfg_dir, flow_copy, tmp_path,
|
|
|
164
161
|
w._pick_elf_file()
|
|
165
162
|
|
|
166
163
|
assert w.elf_path == elf
|
|
167
|
-
s = QtCore.QSettings('struct2ui', 'StructEditor')
|
|
168
|
-
assert s.value('elf_path') is None
|
|
169
164
|
|
|
170
165
|
|
|
171
|
-
def test_disabling_elf_keeps_path_but_deactivates(qapp,
|
|
172
|
-
|
|
173
|
-
monkeypatch):
|
|
174
|
-
w =
|
|
166
|
+
def test_disabling_elf_keeps_path_but_deactivates(qapp, make_editor,
|
|
167
|
+
real_cfg_dir, flow_copy,
|
|
168
|
+
tmp_path, monkeypatch):
|
|
169
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
175
170
|
elf = str(tmp_path / 'fw.elf')
|
|
176
171
|
open(elf, 'wb').close()
|
|
177
172
|
monkeypatch.setattr(
|
|
@@ -192,8 +187,9 @@ def test_disabling_elf_keeps_path_but_deactivates(qapp, real_cfg_dir,
|
|
|
192
187
|
assert w._elf_active() is True
|
|
193
188
|
|
|
194
189
|
|
|
195
|
-
def test_pick_elf_cancel_keeps_state(qapp, real_cfg_dir, flow_copy,
|
|
196
|
-
|
|
190
|
+
def test_pick_elf_cancel_keeps_state(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
191
|
+
monkeypatch):
|
|
192
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
197
193
|
monkeypatch.setattr(
|
|
198
194
|
QtWidgets.QFileDialog, 'getOpenFileName', lambda *a, **k: ('', ''))
|
|
199
195
|
|
|
@@ -202,8 +198,9 @@ def test_pick_elf_cancel_keeps_state(qapp, real_cfg_dir, flow_copy, monkeypatch)
|
|
|
202
198
|
assert w.elf_path == ''
|
|
203
199
|
|
|
204
200
|
|
|
205
|
-
def test_export_bin_api_writes_file(qapp, real_cfg_dir, flow_copy,
|
|
206
|
-
|
|
201
|
+
def test_export_bin_api_writes_file(qapp, make_editor, real_cfg_dir, flow_copy,
|
|
202
|
+
tmp_path):
|
|
203
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
207
204
|
target = str(tmp_path / 'api.bin')
|
|
208
205
|
|
|
209
206
|
result = w.export_bin(target)
|
|
@@ -213,18 +210,18 @@ def test_export_bin_api_writes_file(qapp, real_cfg_dir, flow_copy, tmp_path):
|
|
|
213
210
|
assert len(open(target, 'rb').read()) > 0
|
|
214
211
|
|
|
215
212
|
|
|
216
|
-
def test_export_bin_api_raises_on_bad_path(qapp,
|
|
217
|
-
tmp_path):
|
|
218
|
-
w =
|
|
213
|
+
def test_export_bin_api_raises_on_bad_path(qapp, make_editor, real_cfg_dir,
|
|
214
|
+
flow_copy, tmp_path):
|
|
215
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
219
216
|
bad = str(tmp_path / 'no_such_dir' / 'api.bin')
|
|
220
217
|
|
|
221
218
|
with pytest.raises(Exception):
|
|
222
219
|
w.export_bin(bad)
|
|
223
220
|
|
|
224
221
|
|
|
225
|
-
def test_export_bin_api_dialog_swallows_error(qapp,
|
|
226
|
-
tmp_path, monkeypatch):
|
|
227
|
-
w =
|
|
222
|
+
def test_export_bin_api_dialog_swallows_error(qapp, make_editor, real_cfg_dir,
|
|
223
|
+
flow_copy, tmp_path, monkeypatch):
|
|
224
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
228
225
|
bad = str(tmp_path / 'no_such_dir' / 'api.bin')
|
|
229
226
|
monkeypatch.setattr(
|
|
230
227
|
QtWidgets.QMessageBox, 'critical', lambda *a, **k: None)
|
|
@@ -232,9 +229,9 @@ def test_export_bin_api_dialog_swallows_error(qapp, real_cfg_dir, flow_copy,
|
|
|
232
229
|
assert w.export_bin(bad, show_dialogs=True) is False
|
|
233
230
|
|
|
234
231
|
|
|
235
|
-
def test_export_bin_api_dialog_on_success(qapp,
|
|
236
|
-
tmp_path, monkeypatch):
|
|
237
|
-
w =
|
|
232
|
+
def test_export_bin_api_dialog_on_success(qapp, make_editor, real_cfg_dir,
|
|
233
|
+
flow_copy, tmp_path, monkeypatch):
|
|
234
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
238
235
|
target = str(tmp_path / 'api.bin')
|
|
239
236
|
shown = []
|
|
240
237
|
monkeypatch.setattr(
|
|
@@ -249,8 +246,8 @@ def test_export_bin_api_dialog_on_success(qapp, real_cfg_dir, flow_copy,
|
|
|
249
246
|
assert len(shown) == 1
|
|
250
247
|
|
|
251
248
|
|
|
252
|
-
def test_current_paths_api(qapp, real_cfg_dir, flow_copy):
|
|
253
|
-
w =
|
|
249
|
+
def test_current_paths_api(qapp, make_editor, real_cfg_dir, flow_copy):
|
|
250
|
+
w = make_editor(flow_copy, real_cfg_dir)
|
|
254
251
|
paths = w.current_paths()
|
|
255
252
|
assert paths['modules'] == real_cfg_dir
|
|
256
253
|
assert paths['pipeline'] == flow_copy
|
|
@@ -9,7 +9,6 @@ from Qt import QtWidgets
|
|
|
9
9
|
|
|
10
10
|
from struct2ui.schema import SchemaRegistry, merge_instance
|
|
11
11
|
from struct2ui.ui import pick_renderer, collect_view_values, collect_values
|
|
12
|
-
from struct2ui.editor import StructEditor
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
def _render(real_cfg_dir, type_name, items):
|
|
@@ -73,8 +72,8 @@ def test_panel_without_collector_returns_none(qapp):
|
|
|
73
72
|
assert collect_view_values(plain) is None
|
|
74
73
|
|
|
75
74
|
|
|
76
|
-
def test_current_values_via_widget(qapp, real_cfg_dir, real_flow):
|
|
77
|
-
w =
|
|
75
|
+
def test_current_values_via_widget(qapp, make_editor, real_cfg_dir, real_flow):
|
|
76
|
+
w = make_editor(real_flow, real_cfg_dir)
|
|
78
77
|
w.show_section('A')
|
|
79
78
|
out = w.current_values()
|
|
80
79
|
assert out['level'] == 50
|
|
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
|