Metadata-Version: 2.4
Name: struct2ui
Version: 0.1.0
Summary: Render C struct / JSON schema as editable PySide6 UI, export to C/JSON/bin
Author: Jay
License: MIT License
        
        Copyright (c) 2026 Jay
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Keywords: qt,pyside6,gui,c-struct,json-schema,code-generation,parameter-tuning
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Code Generators
Classifier: Topic :: Software Development :: User Interfaces
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Qt.py>=1.3
Provides-Extra: pyside6
Requires-Dist: PySide6>=6.4; extra == "pyside6"
Provides-Extra: pyqt6
Requires-Dist: PyQt6>=6.4; extra == "pyqt6"
Provides-Extra: elf
Requires-Dist: pyelftools>=0.29; extra == "elf"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: pyelftools>=0.29; extra == "dev"
Dynamic: license-file

# struct2ui

Render C structs / JSON schemas as an **editable PySide6 UI**, and convert freely between **C / JSON / bin**. Built for algorithm parameter tuning: describe a C interface in JSON, auto-generate a Qt form, edit it, then export back to C source, JSON, or binary.

## Features

- **JSON → UI**: describe C structs / enums / arrays with minimal JSON and auto-render Qt widgets (int→QSpinBox, float→QDoubleSpinBox, enum→QComboBox, etc.).
- **Embeddable**: `StructEditor` is a plain `QWidget` that drops into any PySide6 / PyQt UI.
- **Multi-format export**: edited results export to C source, JSON, or binary; C source can also be parsed back into a schema.
- **Validation**: keyword spell-checking (with “Did you mean X?” hints), semantic audits (`min<=max`, `step>0`), and pipeline cross-validation.
- **Qt-binding agnostic**: built on [Qt.py](https://github.com/mottosso/Qt.py) — works with PySide6 / PyQt6 / PySide2 / PyQt5.

## Installation

```bash
pip install struct2ui

# Pick a Qt binding (choose one)
pip install "struct2ui[pyside6]"
pip install "struct2ui[pyqt6]"

# Enable ELF layout verification (optional)
pip install "struct2ui[elf]"
```

> The library itself only depends on `Qt.py`; you must install a Qt binding (PySide6 / PyQt6 / etc.) yourself.
> ELF verification depends on `pyelftools`, installed via the `[elf]` extra.

## Quick Start

```python
from Qt import QtWidgets
from struct2ui import StructEditor

app = QtWidgets.QApplication([])

editor = StructEditor(
    flow_file="abc.json",   # pipeline definition file
    cfg_dir="cfg_t",        # modules dir: *.json holding struct/enum/typedef
)
editor.resize(480, 600)
editor.show()

app.exec_()
```

## Embedding into an Existing UI

`StructEditor` is a regular `QWidget`; just put it into a layout:

```python
from Qt import QtWidgets
from struct2ui import StructEditor

class MyWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        editor = StructEditor(
            "abc.json", "cfg_t",
            settings_org="MyCompany",   # custom QSettings scope to
            settings_app="MyApp",       # avoid clashing with the host app
        )
        self.setCentralWidget(editor)
```

### Constructor Parameters

| Parameter | Description |
| --- | --- |
| `flow_file` | Path to the pipeline JSON file (pipeline definition) |
| `cfg_dir` | Modules directory holding `*.json` (struct / enum / typedef definitions) |
| `parent` | Qt parent object, defaults to `None` |
| `appearance` | Button appearance overrides, `{key: {'mode': ..., 'icon': ..., 'text': ...}}` |
| `settings_org` | QSettings organization name, defaults to `'struct2ui'` |
| `settings_app` | QSettings application name, defaults to `'StructEditor'` |

## Export API

The low-level export functions can be used standalone, without any UI:

```python
from struct2ui.schema import SchemaRegistry
from struct2ui.exporters import (
    emit_c,          # sections + registry -> C source string
    dumps_json,      # -> JSON string
    emit_bin,        # -> binary bytes
    merge_abi,       # merge ABI info
    verify_sections, # verify .bin layout against an ELF
    parse_c_source,  # C source -> parse result
    build_schema_dict,
)
```

## Architecture

| Layer | Module | Responsibility |
| --- | --- | --- |
| Schema (pure data, no Qt) | `struct2ui.schema` | Parse `*.json` into a Field tree; spell-checking, semantic audits, pipeline cross-validation |
| UI rendering | `struct2ui.ui` | `WidgetFactory`, `FormRenderer`/`TreeRenderer`, array tables, `when` conditional binding |
| Export | `struct2ui.exporters` | C / JSON / bin export, C source reverse parsing, ELF verification |
| Top-level widget | `struct2ui.StructEditor` | Path bar / action buttons / content area; load report panel; QSettings path memory |

## Development

```bash
pip install -e ".[dev]" --no-build-isolation
python -m pytest
```

Tests live under `tests/` and drive real Qt widgets headlessly on the offscreen platform.

## License

[MIT](LICENSE) © Jay
