struct2ui 0.3.0__tar.gz → 0.4.0__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.3.0/src/struct2ui.egg-info → struct2ui-0.4.0}/PKG-INFO +5 -5
  2. {struct2ui-0.3.0 → struct2ui-0.4.0}/README.md +4 -4
  3. {struct2ui-0.3.0 → struct2ui-0.4.0}/pyproject.toml +1 -1
  4. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/__init__.py +1 -1
  5. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/editor.py +160 -72
  6. {struct2ui-0.3.0 → struct2ui-0.4.0/src/struct2ui.egg-info}/PKG-INFO +5 -5
  7. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_editor.py +18 -20
  8. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_save.py +17 -9
  9. {struct2ui-0.3.0 → struct2ui-0.4.0}/LICENSE +0 -0
  10. {struct2ui-0.3.0 → struct2ui-0.4.0}/setup.cfg +0 -0
  11. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/exporters/__init__.py +0 -0
  12. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/exporters/bin_emitter.py +0 -0
  13. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/exporters/c_emitter.py +0 -0
  14. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/exporters/c_parser.py +0 -0
  15. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/exporters/elf_verifier.py +0 -0
  16. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/exporters/json_format.py +0 -0
  17. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/c2j.png +0 -0
  18. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/elf.png +0 -0
  19. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/export_notes_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  20. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/flowchart_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  21. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/refresh_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  22. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/report_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  23. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/save_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  24. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/save_as_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  25. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/settings_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  26. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/icons/widgets_24dp_000000_FILL0_wght400_GRAD0_opsz24.png +0 -0
  27. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/schema.py +0 -0
  28. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/ui/__init__.py +0 -0
  29. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/ui/renderers.py +0 -0
  30. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/ui/tables.py +0 -0
  31. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui/ui/widgets.py +0 -0
  32. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui.egg-info/SOURCES.txt +0 -0
  33. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui.egg-info/dependency_links.txt +0 -0
  34. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui.egg-info/requires.txt +0 -0
  35. {struct2ui-0.3.0 → struct2ui-0.4.0}/src/struct2ui.egg-info/top_level.txt +0 -0
  36. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_bin_emitter.py +0 -0
  37. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_c_emitter.py +0 -0
  38. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_c_parser.py +0 -0
  39. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_choices.py +0 -0
  40. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_elf_verifier.py +0 -0
  41. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_float_precision.py +0 -0
  42. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_int_checkbox.py +0 -0
  43. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_json_format.py +0 -0
  44. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_load_report.py +0 -0
  45. {struct2ui-0.3.0 → struct2ui-0.4.0}/tests/test_value_readback.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: struct2ui
3
- Version: 0.3.0
3
+ Version: 0.4.0
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
@@ -260,8 +260,8 @@ class MyWindow(QtWidgets.QMainWindow):
260
260
  | --- | --- |
261
261
  | `flow_file` | Path to the pipeline JSON file (pipeline definition), defaults to `None`; pick it in the UI when omitted |
262
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. |
263
264
  | `parent` | Qt parent object, defaults to `None` |
264
- | `elf_path` | Path to an ELF for layout verification, defaults to `None`; pick it in the UI when omitted |
265
265
  | `appearance` | Button appearance overrides, `{key: {'mode': ..., 'icon': ..., 'text': ...}}` |
266
266
  | `settings_org` | QSettings organization name, defaults to `'struct2ui'` |
267
267
  | `settings_app` | QSettings application name, defaults to `'StructEditor'` |
@@ -308,9 +308,9 @@ from code (e.g. wired to a custom button):
308
308
  | --- | --- |
309
309
  | `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
310
310
  | `current_paths() -> dict` | Current `{'modules', 'pipeline', 'elf'}` file paths; an empty string means that slot is unset. |
311
- | `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 no ELF is selected), `False` otherwise. |
311
+ | `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
312
 
313
- `export_bin` verifies the ELF layout first when an ELF is selected (the file is
313
+ `export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
314
314
  still written, matching the UI flow). With `show_dialogs=True` it pops the same
315
315
  success / ELF-mismatch / failure dialogs the UI shows; with the default
316
316
  `show_dialogs=False` no dialogs appear and render/write failures are raised as
@@ -346,7 +346,7 @@ from struct2ui.exporters import (
346
346
  | Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
347
347
  | UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
348
348
  | Export | `struct2ui.exporters` | C / JSON / bin export, C source reverse parsing, ELF verification |
349
- | Top-level widget | `struct2ui.StructEditor` | Path bar / action buttons / content area; load report panel; QSettings path memory |
349
+ | Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel; QSettings path memory |
350
350
 
351
351
  ## Development
352
352
 
@@ -207,8 +207,8 @@ class MyWindow(QtWidgets.QMainWindow):
207
207
  | --- | --- |
208
208
  | `flow_file` | Path to the pipeline JSON file (pipeline definition), defaults to `None`; pick it in the UI when omitted |
209
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. |
210
211
  | `parent` | Qt parent object, defaults to `None` |
211
- | `elf_path` | Path to an ELF for layout verification, defaults to `None`; pick it in the UI when omitted |
212
212
  | `appearance` | Button appearance overrides, `{key: {'mode': ..., 'icon': ..., 'text': ...}}` |
213
213
  | `settings_org` | QSettings organization name, defaults to `'struct2ui'` |
214
214
  | `settings_app` | QSettings application name, defaults to `'StructEditor'` |
@@ -255,9 +255,9 @@ from code (e.g. wired to a custom button):
255
255
  | --- | --- |
256
256
  | `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
257
257
  | `current_paths() -> dict` | Current `{'modules', 'pipeline', 'elf'}` file paths; an empty string means that slot is unset. |
258
- | `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 no ELF is selected), `False` otherwise. |
258
+ | `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
259
 
260
- `export_bin` verifies the ELF layout first when an ELF is selected (the file is
260
+ `export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
261
261
  still written, matching the UI flow). With `show_dialogs=True` it pops the same
262
262
  success / ELF-mismatch / failure dialogs the UI shows; with the default
263
263
  `show_dialogs=False` no dialogs appear and render/write failures are raised as
@@ -293,7 +293,7 @@ from struct2ui.exporters import (
293
293
  | Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
294
294
  | UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
295
295
  | Export | `struct2ui.exporters` | C / JSON / bin export, C source reverse parsing, ELF verification |
296
- | Top-level widget | `struct2ui.StructEditor` | Path bar / action buttons / content area; load report panel; QSettings path memory |
296
+ | Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel; QSettings path memory |
297
297
 
298
298
  ## Development
299
299
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "struct2ui"
7
- version = "0.3.0"
7
+ version = "0.4.0"
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.3.0"
3
+ __version__ = "0.4.0"
4
4
  __all__ = ["StructEditor"]
@@ -230,8 +230,8 @@ class StructEditor(QtWidgets.QWidget):
230
230
  'SP_FileDialogDetailedView'),
231
231
  }
232
232
 
233
- def __init__(self, flow_file: str = None, cfg_dir: str = None, parent=None,
234
- elf_path: str = None,
233
+ def __init__(self, flow_file: str = None, cfg_dir: str = None,
234
+ elf_file: str = None, parent=None,
235
235
  appearance: Dict[str, Dict[str, Any]] = None,
236
236
  settings_org: str = 'struct2ui',
237
237
  settings_app: str = 'StructEditor',
@@ -261,11 +261,20 @@ class StructEditor(QtWidgets.QWidget):
261
261
  # Paths come straight from the constructor arguments; when omitted the
262
262
  # user picks them through the UI. They are not persisted across runs.
263
263
  self._settings = QtCore.QSettings(settings_org, settings_app)
264
- self.speech_path = flow_file or ''
264
+ self.pipeline_path = flow_file or ''
265
265
  self.struct_dir = cfg_dir or ''
266
266
  # Optional ELF the user picks for later .bin layout verification.
267
- # Empty string means no ELF selected (verification stays off).
268
- self.elf_path = elf_path or ''
267
+ # The path persists once chosen; the enable flag (driven by the
268
+ # Settings checkbox) decides whether verification actually runs, so the
269
+ # user can toggle it off and back on without re-picking the file.
270
+ self.elf_path = elf_file or ''
271
+ self.elf_enabled = bool(self.elf_path)
272
+ # Line edits that mirror the source paths inside the Settings panel.
273
+ # Empty until _make_settings_panel builds the panel; the path-refresh
274
+ # helpers no-op while it is empty.
275
+ self._path_edits: Dict[str, QtWidgets.QLineEdit] = {}
276
+ # (edit, browse_btn) of the ELF row, toggled by its enable checkbox.
277
+ self._elf_row = None
269
278
 
270
279
  # Flow data (populated by _reload via _load_flow).
271
280
  self.registry: SchemaRegistry = None # type: ignore[assignment]
@@ -313,6 +322,10 @@ class StructEditor(QtWidgets.QWidget):
313
322
  self._build_body()
314
323
 
315
324
  self._reload()
325
+ # First launch with no sources yet: land on Settings so the user
326
+ # immediately sees where to point Modules / Pipeline / ELF.
327
+ if not self.struct_dir and not self.pipeline_path:
328
+ self._on_settings_clicked()
316
329
 
317
330
  # ---- body layout (flow strip + content) ----------------------------- #
318
331
  def _build_body(self) -> None:
@@ -374,25 +387,20 @@ class StructEditor(QtWidgets.QWidget):
374
387
  # Appearance (text / default icon / custom icon) is resolved per key
375
388
  # via _make_button so a host application can override any of them
376
389
  # through the `appearance` argument.
377
- self.cfg_btn = self._make_button('modules', self._pick_cfg_dir)
378
- self.flow_btn = self._make_button('pipeline', self._pick_flow_file)
379
390
  reload_btn = self._make_button('reload', self._on_reload_clicked)
380
391
  save_btn = self._make_button('save', self._on_save_clicked)
381
392
  save_as_btn = self._make_button('save_as', self._on_save_as_clicked)
382
393
  export_btn = self._make_button('export', self._on_export_clicked)
383
- self.elf_btn = self._make_button('elf', self._pick_elf_file)
384
- self.elf_btn.setCheckable(True)
385
394
  self.report_btn = self._make_button('report', self._on_report_clicked)
386
395
  self.c2j_btn = self._make_button('c2j', self._on_c2j_clicked)
387
396
  self.settings_btn = self._make_button('settings', self._on_settings_clicked)
388
397
 
389
- # Buttons in their original left-to-right order. When the bar is too
390
- # narrow the rightmost buttons collapse into the '\u00bb' overflow menu
391
- # one by one; Settings stays pinned on the far right.
398
+ # Source paths (Modules / Pipeline / ELF) now live in the Settings
399
+ # panel as label + line-edit + Browse rows, so the bar keeps only the
400
+ # frequently-used actions. When the bar is too narrow the rightmost
401
+ # buttons collapse into the '\u00bb' overflow menu one by one; Settings
402
+ # stays pinned on the far right.
392
403
  buttons = [
393
- (self.cfg_btn, 'Modules', self._pick_cfg_dir),
394
- (self.flow_btn, 'Pipeline', self._pick_flow_file),
395
- (self.elf_btn, 'ELF', self._pick_elf_file),
396
404
  (reload_btn, 'Reload', self._on_reload_clicked),
397
405
  (save_btn, 'Save', self._on_save_clicked),
398
406
  (save_as_btn, 'Save As', self._on_save_as_clicked),
@@ -402,13 +410,11 @@ class StructEditor(QtWidgets.QWidget):
402
410
  ]
403
411
 
404
412
  bar = _OverflowBar(self)
405
- # Group dividers: [sources] | [actions] | [tools]
406
- # sources: Modules, Pipeline, ELF, Reload (0..3)
407
- # actions: Save, Save As, Export (4..6)
408
- # tools: C2J, Report (7..8)
409
- bar.set_buttons(buttons, tail=self.settings_btn, separators={4, 7})
413
+ # Group dividers: [edit] | [tools]
414
+ # edit: Reload, Save, Save As, Export (0..3)
415
+ # tools: C2J, Report (4..5)
416
+ bar.set_buttons(buttons, tail=self.settings_btn, separators={4})
410
417
 
411
- self._refresh_path_tooltips()
412
418
  return bar
413
419
 
414
420
  def _make_separator(self) -> QtWidgets.QFrame:
@@ -522,7 +528,7 @@ class StructEditor(QtWidgets.QWidget):
522
528
  Raises on render or write failure when show_dialogs is False.
523
529
  """
524
530
  elf_ok = True
525
- if self.elf_path:
531
+ if self._elf_active():
526
532
  self._verify_elf()
527
533
  elf_ok = not (self._elf_report is not None and
528
534
  self._elf_report.has_errors)
@@ -560,33 +566,40 @@ class StructEditor(QtWidgets.QWidget):
560
566
  """
561
567
  return {
562
568
  'modules': self.struct_dir,
563
- 'pipeline': self.speech_path,
569
+ 'pipeline': self.pipeline_path,
564
570
  'elf': self.elf_path,
565
571
  }
566
572
 
573
+ def _elf_active(self) -> bool:
574
+ # Verification runs only when an ELF is picked and its enable checkbox
575
+ # is on. The path may linger while disabled, so check both.
576
+ return bool(self.elf_enabled and self.elf_path)
577
+
567
578
  def _refresh_path_tooltips(self) -> None:
568
- modules_text = self._appearance.get('modules', {}).get('text', 'Modules')
569
- pipeline_text = self._appearance.get('pipeline', {}).get('text', 'Pipeline')
570
- self.cfg_btn.setToolTip(
571
- f'{modules_text}: {self.struct_dir}' if self.struct_dir
572
- else f'{modules_text}: (select modules directory)')
573
- self.flow_btn.setToolTip(
574
- f'{pipeline_text}: {self.speech_path}' if self.speech_path
575
- else f'{pipeline_text}: (select pipeline JSON)')
579
+ # Source paths are shown in the Settings panel's line edits. Keep them
580
+ # in sync with the current values; a no-op until that panel is built.
581
+ edits = getattr(self, '_path_edits', None)
582
+ if not edits:
583
+ return
584
+ edits['modules'].setText(self.struct_dir)
585
+ edits['pipeline'].setText(self.pipeline_path)
576
586
  self._refresh_elf_tooltip()
577
587
 
578
588
  def _refresh_elf_tooltip(self) -> None:
579
- elf_text = self._appearance.get('elf', {}).get('text', 'ELF')
580
- if self.elf_path:
581
- self.elf_btn.setToolTip(
582
- f'{elf_text}: {self.elf_path}\n(click to change, or pick the '
583
- 'same file to clear)')
584
- else:
585
- self.elf_btn.setToolTip(
586
- f'{elf_text}: (none - pick an ELF to enable .bin layout '
587
- 'verification)')
588
- self.elf_btn.setChecked(bool(self.elf_path))
589
+ edits = getattr(self, '_path_edits', None)
590
+ if not edits:
591
+ return
592
+ edits['elf'].setText(self.elf_path)
593
+
594
+ def _on_settings_destroyed(self, edits) -> None:
595
+ # Only clear if these refs still belong to the destroyed panel; a newer
596
+ # Settings panel may have already replaced them.
597
+ if self._path_edits is edits:
598
+ self._path_edits = {}
599
+ self._elf_row = None
589
600
 
601
+ # Picking a source only stages the path; the user clicks Reload to apply
602
+ # it. This keeps one explicit user action per full rebuild.
590
603
  def _pick_cfg_dir(self) -> None:
591
604
  start = self.struct_dir or os.getcwd()
592
605
  chosen = QtWidgets.QFileDialog.getExistingDirectory(
@@ -594,50 +607,53 @@ class StructEditor(QtWidgets.QWidget):
594
607
  if chosen:
595
608
  self.struct_dir = chosen
596
609
  self._refresh_path_tooltips()
597
- self._reload()
598
610
 
599
611
  def _pick_flow_file(self) -> None:
600
- start = self.speech_path or os.getcwd()
612
+ start = self.pipeline_path or os.getcwd()
601
613
  chosen, _ = QtWidgets.QFileDialog.getOpenFileName(
602
614
  self, 'Select pipeline JSON', start, 'JSON files (*.json)')
603
615
  if chosen:
604
- self.speech_path = chosen
616
+ self.pipeline_path = chosen
605
617
  self._refresh_path_tooltips()
606
- self._reload()
607
618
 
608
619
  def _pick_elf_file(self) -> None:
609
- # Picking the currently-selected ELF again clears the selection,
610
- # turning verification back off.
620
+ # An ELF path enables .bin layout verification; the enable checkbox next
621
+ # to the row turns it on/off. Takes effect on the next Reload.
611
622
  start = self.elf_path or os.getcwd()
612
623
  chosen, _ = QtWidgets.QFileDialog.getOpenFileName(
613
624
  self, 'Select ELF for layout verification', start,
614
625
  'ELF files (*.elf *.axf *.out);;All files (*)')
615
626
  if not chosen:
616
- self._refresh_elf_tooltip()
617
627
  return
618
- self.elf_path = '' if chosen == self.elf_path else chosen
628
+ self.elf_path = chosen
619
629
  self._refresh_elf_tooltip()
620
- # Re-run the full load so ELF verification re-runs and the landing
621
- # panel reflects any new layout issues.
622
- self._reload()
630
+
631
+ def _set_elf_enabled(self, on: bool) -> None:
632
+ # Toggle whether .bin layout verification runs (effective on the next
633
+ # Reload). The path itself is kept, so re-enabling needs no re-pick;
634
+ # we only enable/disable the row's controls to mirror the state.
635
+ self.elf_enabled = bool(on)
636
+ row = getattr(self, '_elf_row', None)
637
+ if row is not None:
638
+ edit, browse_btn = row
639
+ edit.setEnabled(on)
640
+ browse_btn.setEnabled(on)
623
641
 
624
642
  def _on_reload_clicked(self) -> None:
625
- self._refresh_path_tooltips()
626
643
  self._reload()
627
644
 
628
645
  # ---- reload (build schema + flow + UI from current paths) ----------- #
629
646
  def _reload(self) -> None:
630
647
  # Nothing selected yet (e.g. first launch with no constructor paths):
631
648
  # leave the content area blank and wait for the user to pick sources.
632
- if not self.struct_dir and not self.speech_path:
633
- self._refresh_path_tooltips()
649
+ if not self.struct_dir and not self.pipeline_path:
634
650
  self._set_content(QtWidgets.QWidget())
635
651
  return
636
652
  # Schema registry (loads cfg_t/*.json once).
637
653
  self.registry = SchemaRegistry(self.struct_dir)
638
654
 
639
655
  # Cross-validate abc.json against the loaded schema (Step 2/3).
640
- flow_report = FlowValidator(self.registry, self.speech_path).validate()
656
+ flow_report = FlowValidator(self.registry, self.pipeline_path).validate()
641
657
  self.registry.report.extend(flow_report)
642
658
 
643
659
  # Print load report to console (Step 1~3: console only).
@@ -693,7 +709,7 @@ class StructEditor(QtWidgets.QWidget):
693
709
  return
694
710
  prefix = f'{self._group_key} -> '
695
711
  for issue in self.registry.report.errors:
696
- if issue.file != self.speech_path:
712
+ if issue.file != self.pipeline_path:
697
713
  continue
698
714
  if not issue.path.startswith(prefix):
699
715
  continue
@@ -737,7 +753,7 @@ class StructEditor(QtWidgets.QWidget):
737
753
  loaded) is not verified. No ELF -> no verification.
738
754
  """
739
755
  self._elf_report = None
740
- if not self.elf_path or self.registry is None:
756
+ if not self._elf_active() or self.registry is None:
741
757
  return
742
758
  # Pipeline-only: nothing to check without a loaded flow.
743
759
  sections = self._flow_sections()
@@ -750,10 +766,10 @@ class StructEditor(QtWidgets.QWidget):
750
766
 
751
767
  # ---- flow loading ---------------------------------------------------- #
752
768
  def _load_flow(self) -> None:
753
- if not os.path.exists(self.speech_path):
769
+ if not os.path.exists(self.pipeline_path):
754
770
  return
755
771
  try:
756
- with open(self.speech_path, 'r', encoding='utf-8') as f:
772
+ with open(self.pipeline_path, 'r', encoding='utf-8') as f:
757
773
  data = json.load(f)
758
774
  except Exception:
759
775
  return
@@ -861,12 +877,12 @@ class StructEditor(QtWidgets.QWidget):
861
877
  def _on_save_clicked(self) -> None:
862
878
  if not self._raw_data:
863
879
  return
864
- self._save_to(self.speech_path)
880
+ self._save_to(self.pipeline_path)
865
881
 
866
882
  def _on_save_as_clicked(self) -> None:
867
883
  if not self._raw_data:
868
884
  return
869
- start = self.speech_path or os.getcwd()
885
+ start = self.pipeline_path or os.getcwd()
870
886
  chosen, _ = QtWidgets.QFileDialog.getSaveFileName(
871
887
  self, 'Save pipeline JSON as', start, 'JSON files (*.json)')
872
888
  if chosen:
@@ -927,8 +943,8 @@ class StructEditor(QtWidgets.QWidget):
927
943
  self, 'Save failed', f'Could not write {path}:\n{exc}')
928
944
  return
929
945
  # Saving As redirects subsequent Save/Reload to the new file.
930
- if path != self.speech_path:
931
- self.speech_path = path
946
+ if path != self.pipeline_path:
947
+ self.pipeline_path = path
932
948
  self._refresh_path_tooltips()
933
949
  QtWidgets.QMessageBox.information(
934
950
  self, 'Saved', f'Pipeline saved to:\n{path}')
@@ -947,7 +963,7 @@ class StructEditor(QtWidgets.QWidget):
947
963
  if last_type not in self._EXPORT_FILTERS:
948
964
  last_type = 'c'
949
965
  filters = ';;'.join(self._EXPORT_FILTERS.values())
950
- start = self.speech_path or os.getcwd()
966
+ start = self.pipeline_path or os.getcwd()
951
967
  if start:
952
968
  start = os.path.splitext(start)[0] + '.' + last_type
953
969
 
@@ -969,7 +985,7 @@ class StructEditor(QtWidgets.QWidget):
969
985
  # the case that matters most. We still write the file (per design),
970
986
  # but jump to the Report panel afterwards so the mismatch is seen.
971
987
  elf_failed = False
972
- if export_type == 'bin' and self.elf_path:
988
+ if export_type == 'bin' and self._elf_active():
973
989
  self._verify_elf()
974
990
  elf_failed = self._elf_report is not None and \
975
991
  self._elf_report.has_errors
@@ -1387,9 +1403,9 @@ class StructEditor(QtWidgets.QWidget):
1387
1403
  self._set_content(self._make_settings_panel())
1388
1404
 
1389
1405
  def _make_settings_panel(self) -> QtWidgets.QWidget:
1390
- """Reserved settings page. No options yet; kept as an extension point
1391
- so future global preferences land here without touching the button
1392
- wiring again."""
1406
+ """Settings page: source paths (Modules / Pipeline / ELF) plus global
1407
+ preferences. Source rows are read-only line edits driven by the Browse
1408
+ buttons, so the busy toolbar stays focused on edit/tool actions."""
1393
1409
  panel = QtWidgets.QWidget()
1394
1410
  layout = QtWidgets.QVBoxLayout(panel)
1395
1411
  layout.setContentsMargins(8, 8, 8, 8)
@@ -1399,6 +1415,43 @@ class StructEditor(QtWidgets.QWidget):
1399
1415
  header.setStyleSheet('font-weight: bold; font-size: 14px;')
1400
1416
  layout.addWidget(header)
1401
1417
 
1418
+ sources = QtWidgets.QLabel('Sources')
1419
+ sources.setStyleSheet('font-weight: bold;')
1420
+ layout.addWidget(sources)
1421
+
1422
+ grid = QtWidgets.QGridLayout()
1423
+ grid.setHorizontalSpacing(8)
1424
+ grid.setVerticalSpacing(6)
1425
+ grid.setColumnStretch(2, 1)
1426
+
1427
+ modules_text = self._appearance.get('modules', {}).get('text', 'Modules')
1428
+ pipeline_text = self._appearance.get('pipeline', {}).get('text', 'Pipeline')
1429
+ elf_text = self._appearance.get('elf', {}).get('text', 'ELF')
1430
+
1431
+ # Fresh path-edit refs for this panel instance. When the panel is later
1432
+ # destroyed (e.g. on Reload / switching pages) drop the refs so the
1433
+ # _refresh_* helpers don't touch deleted C++ objects - but only if they
1434
+ # still belong to this panel, never the panel that replaced it.
1435
+ self._path_edits = {}
1436
+ edits = self._path_edits
1437
+ panel.destroyed.connect(
1438
+ lambda *_a, e=edits: self._on_settings_destroyed(e))
1439
+ self._add_source_row(
1440
+ grid, 0, modules_text, 'modules', self.struct_dir,
1441
+ '(select modules directory)', self._pick_cfg_dir)
1442
+ self._add_source_row(
1443
+ grid, 1, pipeline_text, 'pipeline', self.pipeline_path,
1444
+ '(select pipeline JSON)', self._pick_flow_file)
1445
+ self._add_source_row(
1446
+ grid, 2, elf_text, 'elf', self.elf_path,
1447
+ '(select an ELF for .bin layout verification)',
1448
+ self._pick_elf_file, toggle=self._set_elf_enabled)
1449
+ layout.addLayout(grid)
1450
+
1451
+ prefs = QtWidgets.QLabel('Preferences')
1452
+ prefs.setStyleSheet('font-weight: bold;')
1453
+ layout.addWidget(prefs)
1454
+
1402
1455
  row = QtWidgets.QHBoxLayout()
1403
1456
  row.setSpacing(8)
1404
1457
  row.addWidget(QtWidgets.QLabel('Layout direction:'))
@@ -1415,6 +1468,40 @@ class StructEditor(QtWidgets.QWidget):
1415
1468
  layout.addStretch(1)
1416
1469
  return panel
1417
1470
 
1471
+ def _add_source_row(self, grid, r, label, key, value, placeholder,
1472
+ browse, toggle=None) -> None:
1473
+ # col 0: optional enable checkbox (only the optional ELF row uses it)
1474
+ # col 1: label col 2: read-only path edit (stretches) col 3: '...'
1475
+ # Rows without a checkbox flush their label to the left across cols
1476
+ # 0-1, so Modules / Pipeline are not indented to match ELF.
1477
+ label_w = QtWidgets.QLabel(f'{label}:')
1478
+ if toggle is not None:
1479
+ check = QtWidgets.QCheckBox()
1480
+ check.setChecked(self.elf_enabled)
1481
+ check.toggled.connect(lambda on: toggle(on))
1482
+ grid.addWidget(check, r, 0)
1483
+ grid.addWidget(label_w, r, 1)
1484
+ else:
1485
+ grid.addWidget(label_w, r, 0, 1, 2)
1486
+
1487
+ edit = QtWidgets.QLineEdit()
1488
+ edit.setReadOnly(True)
1489
+ edit.setText(value)
1490
+ edit.setPlaceholderText(placeholder)
1491
+ self._path_edits[key] = edit
1492
+ grid.addWidget(edit, r, 2)
1493
+
1494
+ browse_btn = QtWidgets.QPushButton('...')
1495
+ browse_btn.setMaximumWidth(32)
1496
+ browse_btn.setToolTip(f'Select {label}')
1497
+ browse_btn.clicked.connect(lambda: browse())
1498
+ grid.addWidget(browse_btn, r, 3)
1499
+
1500
+ if toggle is not None:
1501
+ self._elf_row = (edit, browse_btn)
1502
+ edit.setEnabled(self.elf_enabled)
1503
+ browse_btn.setEnabled(self.elf_enabled)
1504
+
1418
1505
  # ---- report panel (config issues + ELF layout verification) --------- #
1419
1506
  def _on_report_clicked(self) -> None:
1420
1507
  self._capture_active_section()
@@ -1461,10 +1548,11 @@ class StructEditor(QtWidgets.QWidget):
1461
1548
  title.setStyleSheet('font-weight: bold; font-size: 14px;')
1462
1549
  layout.addWidget(title)
1463
1550
 
1464
- if not self.elf_path:
1551
+ if not self._elf_active():
1465
1552
  note = QtWidgets.QLabel(
1466
- 'No ELF selected - layout verification is off. '
1467
- 'Pick an ELF to enable strict layout checks.')
1553
+ 'ELF layout verification is off. '
1554
+ 'Pick an ELF and enable it in Settings for strict layout '
1555
+ 'checks.')
1468
1556
  note.setWordWrap(True)
1469
1557
  note.setStyleSheet('color: #666;')
1470
1558
  layout.addWidget(note)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: struct2ui
3
- Version: 0.3.0
3
+ Version: 0.4.0
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
@@ -260,8 +260,8 @@ class MyWindow(QtWidgets.QMainWindow):
260
260
  | --- | --- |
261
261
  | `flow_file` | Path to the pipeline JSON file (pipeline definition), defaults to `None`; pick it in the UI when omitted |
262
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. |
263
264
  | `parent` | Qt parent object, defaults to `None` |
264
- | `elf_path` | Path to an ELF for layout verification, defaults to `None`; pick it in the UI when omitted |
265
265
  | `appearance` | Button appearance overrides, `{key: {'mode': ..., 'icon': ..., 'text': ...}}` |
266
266
  | `settings_org` | QSettings organization name, defaults to `'struct2ui'` |
267
267
  | `settings_app` | QSettings application name, defaults to `'StructEditor'` |
@@ -308,9 +308,9 @@ from code (e.g. wired to a custom button):
308
308
  | --- | --- |
309
309
  | `current_values() -> dict` | Live editor values of the active section, keyed by field name (empty dict when no parameter section is shown). |
310
310
  | `current_paths() -> dict` | Current `{'modules', 'pipeline', 'elf'}` file paths; an empty string means that slot is unset. |
311
- | `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 no ELF is selected), `False` otherwise. |
311
+ | `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
312
 
313
- `export_bin` verifies the ELF layout first when an ELF is selected (the file is
313
+ `export_bin` verifies the ELF layout first when an ELF is selected and enabled (the file is
314
314
  still written, matching the UI flow). With `show_dialogs=True` it pops the same
315
315
  success / ELF-mismatch / failure dialogs the UI shows; with the default
316
316
  `show_dialogs=False` no dialogs appear and render/write failures are raised as
@@ -346,7 +346,7 @@ from struct2ui.exporters import (
346
346
  | Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
347
347
  | UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
348
348
  | Export | `struct2ui.exporters` | C / JSON / bin export, C source reverse parsing, ELF verification |
349
- | Top-level widget | `struct2ui.StructEditor` | Path bar / action buttons / content area; load report panel; QSettings path memory |
349
+ | Top-level widget | `struct2ui.StructEditor` | Action toolbar / content area; Settings panel for source paths; load report panel; QSettings path memory |
350
350
 
351
351
  ## Development
352
352
 
@@ -9,13 +9,13 @@ from struct2ui.editor import StructEditor
9
9
 
10
10
  def test_paths_come_from_args(qapp, real_cfg_dir, real_flow):
11
11
  w = StructEditor(real_flow, real_cfg_dir)
12
- assert w.speech_path == real_flow
12
+ assert w.pipeline_path == real_flow
13
13
  assert w.struct_dir == real_cfg_dir
14
14
 
15
15
 
16
16
  def test_defaults_to_empty_when_no_args(qapp):
17
17
  w = StructEditor()
18
- assert w.speech_path == ''
18
+ assert w.pipeline_path == ''
19
19
  assert w.struct_dir == ''
20
20
  assert w.elf_path == ''
21
21
 
@@ -76,20 +76,20 @@ def test_custom_button_position_start(qapp):
76
76
  # Custom buttons lead, in add-order, before the built-ins.
77
77
  assert labels[:2] == ['First', 'Second']
78
78
  # The custom group has no leading divider; the divider sits right after
79
- # the last custom button, i.e. before the first built-in (Modules).
79
+ # the last custom button, i.e. before the first built-in (Reload).
80
80
  assert first not in bar._separators
81
81
  assert second not in bar._separators
82
- modules_btn = bar._buttons[2][0]
83
- assert modules_btn is w.cfg_btn
84
- assert modules_btn in bar._separators
82
+ reload_btn = bar._buttons[2][0]
83
+ assert bar._buttons[2][1] == 'Reload'
84
+ assert reload_btn in bar._separators
85
85
 
86
- # Verify the *visual* order in the layout: First, Second, divider, Modules.
87
- sep = bar._separators[modules_btn]
86
+ # Verify the *visual* order in the layout: First, Second, divider, Reload.
87
+ sep = bar._separators[reload_btn]
88
88
  i_first = bar._layout.indexOf(first)
89
89
  i_second = bar._layout.indexOf(second)
90
90
  i_sep = bar._layout.indexOf(sep)
91
- i_modules = bar._layout.indexOf(modules_btn)
92
- assert i_first < i_second < i_sep < i_modules
91
+ i_reload = bar._layout.indexOf(reload_btn)
92
+ assert i_first < i_second < i_sep < i_reload
93
93
 
94
94
 
95
95
  def test_separator_hidden_when_its_button_overflows(qapp):
@@ -118,17 +118,16 @@ def test_overflow_menu_carries_group_separators(qapp, real_cfg_dir, real_flow):
118
118
  assert not acts[0].isSeparator()
119
119
  sep_positions = [i for i, a in enumerate(acts) if a.isSeparator()]
120
120
  labels = [a.text() for a in acts if not a.isSeparator()]
121
- assert labels == ['Modules', 'Pipeline', 'ELF', 'Reload',
122
- 'Save', 'Save As', 'Export', 'C2J', 'Report']
123
- # Two group dividers (sources|actions and actions|tools).
124
- assert len(sep_positions) == 2
121
+ assert labels == ['Reload', 'Save', 'Save As', 'Export', 'C2J', 'Report']
122
+ # One group divider (edit|tools).
123
+ assert len(sep_positions) == 1
125
124
 
126
125
 
127
126
  def test_reload_does_not_persist_paths(qapp, real_cfg_dir, real_flow):
128
127
  w = StructEditor(real_flow, real_cfg_dir)
129
128
 
130
129
  new_flow = real_flow.replace('abc.json', 'speech.json')
131
- w.speech_path = new_flow
130
+ w.pipeline_path = new_flow
132
131
  w.struct_dir = real_cfg_dir
133
132
  w._on_reload_clicked()
134
133
 
@@ -139,12 +138,12 @@ def test_reload_does_not_persist_paths(qapp, real_cfg_dir, real_flow):
139
138
 
140
139
  def test_new_editor_ignores_previous_paths(qapp, real_cfg_dir, real_flow):
141
140
  first = StructEditor(real_flow, real_cfg_dir)
142
- first.speech_path = real_flow.replace('abc.json', 'speech.json')
141
+ first.pipeline_path = real_flow.replace('abc.json', 'speech.json')
143
142
  first.struct_dir = real_cfg_dir
144
143
  first._on_reload_clicked()
145
144
 
146
145
  second = StructEditor()
147
- assert second.speech_path == ''
146
+ assert second.pipeline_path == ''
148
147
  assert second.struct_dir == ''
149
148
 
150
149
 
@@ -164,7 +163,7 @@ def test_reload_new_pipeline_does_not_keep_old_edits(
164
163
  if s.value() == 50)
165
164
  spin.setValue(999)
166
165
 
167
- w.speech_path = str(other)
166
+ w.pipeline_path = str(other)
168
167
  w._reload()
169
168
 
170
169
  assert w._raw_data['ABC Test']['A']['items']['level'] == 7
@@ -234,8 +233,7 @@ def test_path_bar_overflows_rightmost_buttons_when_narrow(
234
233
  assert bar._buttons[-1][0].isHidden()
235
234
  # Order is preserved (no reordering happened).
236
235
  assert [lbl for _b, lbl, _cb in bar._buttons] == [
237
- 'Modules', 'Pipeline', 'ELF', 'Reload',
238
- 'Save', 'Save As', 'Export', 'C2J', 'Report']
236
+ 'Reload', 'Save', 'Save As', 'Export', 'C2J', 'Report']
239
237
 
240
238
 
241
239
  def test_path_bar_overflows_multiple_buttons_at_once(
@@ -91,8 +91,9 @@ def test_save_as_redirects_path(qapp, real_cfg_dir, flow_copy, tmp_path):
91
91
  target = str(tmp_path / 'other.json')
92
92
  w._save_to(target)
93
93
 
94
- assert w.speech_path == target
95
- assert target in w.flow_btn.toolTip()
94
+ assert w.pipeline_path == target
95
+ w._on_settings_clicked()
96
+ assert w._path_edits['pipeline'].text() == target
96
97
  with open(target, encoding='utf-8') as f:
97
98
  data = json.load(f)
98
99
  assert data['ABC Test']['A']['items']['level'] == 50
@@ -150,7 +151,6 @@ def test_export_cancel_does_nothing(qapp, real_cfg_dir, flow_copy,
150
151
  def test_elf_starts_unselected(qapp, real_cfg_dir, flow_copy):
151
152
  w = StructEditor(flow_copy, real_cfg_dir)
152
153
  assert w.elf_path == ''
153
- assert w.elf_btn.isChecked() is False
154
154
 
155
155
 
156
156
  def test_pick_elf_sets_path(qapp, real_cfg_dir, flow_copy, tmp_path,
@@ -164,24 +164,32 @@ def test_pick_elf_sets_path(qapp, real_cfg_dir, flow_copy, tmp_path,
164
164
  w._pick_elf_file()
165
165
 
166
166
  assert w.elf_path == elf
167
- assert w.elf_btn.isChecked() is True
168
167
  s = QtCore.QSettings('struct2ui', 'StructEditor')
169
168
  assert s.value('elf_path') is None
170
169
 
171
170
 
172
- def test_pick_same_elf_clears_selection(qapp, real_cfg_dir, flow_copy,
173
- tmp_path, monkeypatch):
171
+ def test_disabling_elf_keeps_path_but_deactivates(qapp, real_cfg_dir,
172
+ flow_copy, tmp_path,
173
+ monkeypatch):
174
174
  w = StructEditor(flow_copy, real_cfg_dir)
175
175
  elf = str(tmp_path / 'fw.elf')
176
176
  open(elf, 'wb').close()
177
177
  monkeypatch.setattr(
178
178
  QtWidgets.QFileDialog, 'getOpenFileName', lambda *a, **k: (elf, ''))
179
179
 
180
+ w._on_settings_clicked()
180
181
  w._pick_elf_file()
181
- w._pick_elf_file()
182
+ w._set_elf_enabled(True)
183
+ assert w.elf_path == elf
184
+ assert w._elf_active() is True
182
185
 
183
- assert w.elf_path == ''
184
- assert w.elf_btn.isChecked() is False
186
+ w._set_elf_enabled(False)
187
+ assert w.elf_path == elf
188
+ assert w._elf_active() is False
189
+
190
+ w._set_elf_enabled(True)
191
+ assert w.elf_path == elf
192
+ assert w._elf_active() is True
185
193
 
186
194
 
187
195
  def test_pick_elf_cancel_keeps_state(qapp, real_cfg_dir, flow_copy, monkeypatch):
File without changes
File without changes