struct2ui 0.4.0__tar.gz → 0.4.2__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.
Files changed (45) hide show
  1. {struct2ui-0.4.0/src/struct2ui.egg-info → struct2ui-0.4.2}/PKG-INFO +67 -17
  2. {struct2ui-0.4.0 → struct2ui-0.4.2}/README.md +66 -16
  3. {struct2ui-0.4.0 → struct2ui-0.4.2}/pyproject.toml +1 -1
  4. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/__init__.py +1 -1
  5. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/editor.py +286 -94
  6. {struct2ui-0.4.0 → struct2ui-0.4.2/src/struct2ui.egg-info}/PKG-INFO +67 -17
  7. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_editor.py +56 -49
  8. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_load_report.py +12 -11
  9. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_save.py +48 -51
  10. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_value_readback.py +2 -3
  11. {struct2ui-0.4.0 → struct2ui-0.4.2}/LICENSE +0 -0
  12. {struct2ui-0.4.0 → struct2ui-0.4.2}/setup.cfg +0 -0
  13. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/exporters/__init__.py +0 -0
  14. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/exporters/bin_emitter.py +0 -0
  15. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/exporters/c_emitter.py +0 -0
  16. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/exporters/c_parser.py +0 -0
  17. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/exporters/elf_verifier.py +0 -0
  18. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/exporters/json_format.py +0 -0
  19. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/c2j.png +0 -0
  20. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/elf.png +0 -0
  21. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/export_notes_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  22. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/flowchart_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  23. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/refresh_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  24. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/report_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  25. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/save_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  26. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/save_as_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  27. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/settings_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  28. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/icons/widgets_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  29. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/schema.py +0 -0
  30. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/ui/__init__.py +0 -0
  31. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/ui/renderers.py +0 -0
  32. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/ui/tables.py +0 -0
  33. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui/ui/widgets.py +0 -0
  34. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui.egg-info/SOURCES.txt +0 -0
  35. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui.egg-info/dependency_links.txt +0 -0
  36. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui.egg-info/requires.txt +0 -0
  37. {struct2ui-0.4.0 → struct2ui-0.4.2}/src/struct2ui.egg-info/top_level.txt +0 -0
  38. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_bin_emitter.py +0 -0
  39. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_c_emitter.py +0 -0
  40. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_c_parser.py +0 -0
  41. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_choices.py +0 -0
  42. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_elf_verifier.py +0 -0
  43. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_float_precision.py +0 -0
  44. {struct2ui-0.4.0 → struct2ui-0.4.2}/tests/test_int_checkbox.py +0 -0
  45. {struct2ui-0.4.0 → struct2ui-0.4.2}/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.0
3
+ Version: 0.4.2
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
- flow_file="abc.json", # pipeline definition file (optional)
92
- cfg_dir="cfg_t", # modules dir: *.json holding struct/enum/typedef (optional)
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,72 @@ from struct2ui import StructEditor
246
247
  class MyWindow(QtWidgets.QMainWindow):
247
248
  def __init__(self):
248
249
  super().__init__()
249
- editor = StructEditor(
250
- "abc.json", "cfg_t",
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
+ | `async_load` | Run that reload on a background thread (defaults to `False`). See [Async Loading](#async-loading) |
290
+
291
+ Toolbar orientation is set with `set_flow_orientation('horizontal' | 'vertical')`.
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
+
271
316
  ## Custom Toolbar Buttons
272
317
 
273
318
  Host applications can add their own buttons to the top path bar via
@@ -276,7 +321,8 @@ the built-in buttons by a divider that is added automatically — you only choos
276
321
  which side they sit on (once, via the `custom_button_position` constructor arg).
277
322
 
278
323
  ```python
279
- editor = StructEditor("abc.json", "cfg_t", custom_button_position="end")
324
+ editor = StructEditor(custom_button_position="end")
325
+ editor.set_sources(cfg_dir="cfg_t", flow_file="abc.json")
280
326
 
281
327
  def on_send():
282
328
  print(editor.current_values())
@@ -306,8 +352,12 @@ from code (e.g. wired to a custom button):
306
352
 
307
353
  | Method | Description |
308
354
  | --- | --- |
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). |
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. |
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. |
309
358
  | `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
310
359
  | `current_paths() -> dict` | Current `{'modules', 'pipeline', 'elf'}` file paths; an empty string means that slot is unset. |
360
+ | `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
361
  | `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
362
 
313
363
  `export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
@@ -346,7 +396,7 @@ from struct2ui.exporters import (
346
396
  | Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
347
397
  | UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
348
398
  | 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; QSettings path memory |
399
+ | Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel |
350
400
 
351
401
  ## Development
352
402
 
@@ -34,9 +34,10 @@ from struct2ui import StructEditor
34
34
 
35
35
  app = QtWidgets.QApplication([])
36
36
 
37
- editor = StructEditor(
38
- flow_file="abc.json", # pipeline definition file (optional)
39
- cfg_dir="cfg_t", # modules dir: *.json holding struct/enum/typedef (optional)
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,72 @@ from struct2ui import StructEditor
193
194
  class MyWindow(QtWidgets.QMainWindow):
194
195
  def __init__(self):
195
196
  super().__init__()
196
- editor = StructEditor(
197
- "abc.json", "cfg_t",
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
+ | `async_load` | Run that reload on a background thread (defaults to `False`). See [Async Loading](#async-loading) |
237
+
238
+ Toolbar orientation is set with `set_flow_orientation('horizontal' | 'vertical')`.
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
+
218
263
  ## Custom Toolbar Buttons
219
264
 
220
265
  Host applications can add their own buttons to the top path bar via
@@ -223,7 +268,8 @@ the built-in buttons by a divider that is added automatically — you only choos
223
268
  which side they sit on (once, via the `custom_button_position` constructor arg).
224
269
 
225
270
  ```python
226
- editor = StructEditor("abc.json", "cfg_t", custom_button_position="end")
271
+ editor = StructEditor(custom_button_position="end")
272
+ editor.set_sources(cfg_dir="cfg_t", flow_file="abc.json")
227
273
 
228
274
  def on_send():
229
275
  print(editor.current_values())
@@ -253,8 +299,12 @@ from code (e.g. wired to a custom button):
253
299
 
254
300
  | Method | Description |
255
301
  | --- | --- |
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). |
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. |
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. |
256
305
  | `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
257
306
  | `current_paths() -> dict` | Current `{'modules', 'pipeline', 'elf'}` file paths; an empty string means that slot is unset. |
307
+ | `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
308
  | `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
309
 
260
310
  `export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
@@ -293,7 +343,7 @@ from struct2ui.exporters import (
293
343
  | Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
294
344
  | UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
295
345
  | 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; QSettings path memory |
346
+ | Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel |
297
347
 
298
348
  ## Development
299
349
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "struct2ui"
7
- version = "0.4.0"
7
+ version = "0.4.2"
8
8
  description = "Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,4 +1,4 @@
1
1
  from .editor import StructEditor
2
2
 
3
- __version__ = "0.4.0"
3
+ __version__ = "0.4.2"
4
4
  __all__ = ["StructEditor"]