Reorganized the application around a clear frontend/backend boundary.

src/bedit/
├── __main__.py
├── core/                   # Pure Python, no PySide
│   ├── model.py
│   ├── port_types.py
│   ├── serializer.py
│   └── libraries.py
└── gui/                    # All Qt-dependent code
    ├── app.py
    ├── main_window.py
    ├── preferences.py
    ├── controllers/
    ├── dialogs/
    ├── graphics/
    ├── models/
    └── generated/          # Designer/resource output only
Notable improvements:
Domain models, serialization, port types, and library parsing are now Qt-free.
Qt signals and undo infrastructure are explicitly isolated under gui/controllers.
Library parsing is separated from the Qt repository and tree models.
All generated Python is contained in gui/generated.
Designer build tasks now write to the generated directory.
The application entry point and package metadata use the new paths.
README now documents the structure and dependency rules.
Removed the old mixed document, library, and workspace packages.
This commit is contained in:
2026-07-20 12:09:00 +02:00
parent 1a47952358
commit 48a2b4c8d0
43 changed files with 1011 additions and 310 deletions

View File

@@ -0,0 +1,162 @@
from copy import deepcopy
from uuid import uuid4
from PySide6.QtCore import Qt
from PySide6.QtWidgets import (
QComboBox,
QDialog,
QDialogButtonBox,
QFormLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QListWidget,
QListWidgetItem,
QMessageBox,
QPushButton,
QSplitter,
QVBoxLayout,
QWidget,
)
from bedit.core.model import Component, Port
from bedit.core.port_types import PortTypeRegistry
PORT_ROLE = Qt.ItemDataRole.UserRole
class PortOptionsDialog(QDialog):
"""Unified editor for a component's typed, oriented ports."""
def __init__(self, component: Component, parent=None, *, read_only: bool = False) -> None:
super().__init__(parent)
self.setWindowTitle(f"Port Options — {component.name}")
self.resize(620, 380)
self.ports: list[tuple[Port, str]] = [
*((deepcopy(port), "input") for port in component.inputs),
*((deepcopy(port), "output") for port in component.outputs),
]
self._loading = False
layout = QVBoxLayout(self)
splitter = QSplitter()
left = QWidget()
left_layout = QVBoxLayout(left)
self.list = QListWidget()
self.list.currentRowChanged.connect(self._load_current)
left_layout.addWidget(self.list)
port_buttons = QHBoxLayout()
self.add_button = QPushButton("Add Port")
self.remove_button = QPushButton("Remove Port")
self.add_button.clicked.connect(self.add_port)
self.remove_button.clicked.connect(self.remove_port)
port_buttons.addWidget(self.add_button)
port_buttons.addWidget(self.remove_button)
left_layout.addLayout(port_buttons)
right = QWidget()
form = QFormLayout(right)
self.name_edit = QLineEdit()
self.type_combo = QComboBox()
for port_type in PortTypeRegistry.all():
self.type_combo.addItem(port_type.display_name, port_type.id)
self.orientation_combo = QComboBox()
self.orientation_combo.addItem("Input", "input")
self.orientation_combo.addItem("Output", "output")
form.addRow("Name:", self.name_edit)
form.addRow("Type:", self.type_combo)
form.addRow("Orientation:", self.orientation_combo)
form.addRow("", QLabel("New ports start at (0, 0) in the icon editor."))
self.name_edit.textEdited.connect(self._store_current)
self.type_combo.currentIndexChanged.connect(self._store_current)
self.orientation_combo.currentIndexChanged.connect(self._store_current)
splitter.addWidget(left)
splitter.addWidget(right)
splitter.setSizes([250, 370])
layout.addWidget(splitter)
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
layout.addWidget(buttons)
if read_only:
self.add_button.setEnabled(False)
self.remove_button.setEnabled(False)
self.name_edit.setReadOnly(True)
self.type_combo.setEnabled(False)
self.orientation_combo.setEnabled(False)
buttons.button(QDialogButtonBox.StandardButton.Ok).setText("Close")
buttons.button(QDialogButtonBox.StandardButton.Cancel).hide()
self._rebuild_list(0 if self.ports else -1)
@property
def inputs(self) -> list[Port]:
return [port for port, orientation in self.ports if orientation == "input"]
@property
def outputs(self) -> list[Port]:
return [port for port, orientation in self.ports if orientation == "output"]
def _rebuild_list(self, row: int = -1) -> None:
self.list.clear()
for port, orientation in self.ports:
item = QListWidgetItem(f"{port.name} [{orientation}, {port.type}]")
item.setData(PORT_ROLE, port.id)
self.list.addItem(item)
self.list.setCurrentRow(min(row, len(self.ports) - 1))
self._update_enabled()
def _load_current(self, row: int) -> None:
self._loading = True
enabled = 0 <= row < len(self.ports)
if enabled:
port, orientation = self.ports[row]
self.name_edit.setText(port.name)
self.type_combo.setCurrentIndex(self.type_combo.findData(port.type))
self.orientation_combo.setCurrentIndex(self.orientation_combo.findData(orientation))
else:
self.name_edit.clear()
self._loading = False
self._update_enabled()
def _update_enabled(self) -> None:
enabled = self.list.currentRow() >= 0
self.remove_button.setEnabled(enabled)
self.name_edit.setEnabled(enabled)
self.type_combo.setEnabled(enabled)
self.orientation_combo.setEnabled(enabled)
def _store_current(self) -> None:
row = self.list.currentRow()
if self._loading or not (0 <= row < len(self.ports)):
return
port, _orientation = self.ports[row]
port.name = self.name_edit.text()
port.type = self.type_combo.currentData()
self.ports[row] = (port, self.orientation_combo.currentData())
self.list.item(row).setText(
f"{port.name} [{self.ports[row][1]}, {port.type}]"
)
def add_port(self) -> None:
port = Port(
id=f"port-{uuid4().hex[:8]}",
name=f"Port {len(self.ports) + 1}",
properties={"iconPosition": {"x": 0.0, "y": 0.0}},
type="signal",
)
self.ports.append((port, "input"))
self._rebuild_list(len(self.ports) - 1)
self.name_edit.selectAll()
self.name_edit.setFocus()
def remove_port(self) -> None:
row = self.list.currentRow()
if row >= 0:
self.ports.pop(row)
self._rebuild_list(min(row, len(self.ports) - 1))
def accept(self) -> None:
self._store_current()
if any(not port.name.strip() for port, _orientation in self.ports):
QMessageBox.warning(self, "Invalid port", "Every port must have a name.")
return
super().accept()