More fixes and extended lib
This commit is contained in:
@@ -9,7 +9,7 @@ from PySide6.QtWidgets import QAbstractItemView, QDialog, QHeaderView, QMenu
|
||||
from bedit_core.models import Component, ComponentID, ConnectionID, EquationImplementation, GraphImplementation, Port, PortID, Parameter, ParameterID
|
||||
from bedit_core.models import Document as CoreDocument
|
||||
from bedit_gui.documents import Document
|
||||
from bedit_gui.models import Graph, GraphComponentLabel, Icon
|
||||
from bedit_gui.models import Graph, GraphComponentLabel, Icon, PortMetadata
|
||||
from bedit_gui.views.dialogs.interface_editor_dialog import InterfaceEditorDialog
|
||||
from bedit_gui.views.dialogs.param_editor_dialog import ParamEditorDialog
|
||||
from bedit_gui.views.icon_editor_window import IconEditorWindow
|
||||
@@ -22,6 +22,7 @@ ICON_SIZE = QSize(16, 16)
|
||||
class InterfaceEditorLike(Protocol):
|
||||
def exec(self) -> int: ...
|
||||
def ports(self) -> dict[PortID, Port]: ...
|
||||
def port_metadata(self) -> dict[PortID, PortMetadata]: ...
|
||||
|
||||
class ParamEditorLike(Protocol):
|
||||
def exec(self) -> int: ...
|
||||
@@ -29,7 +30,7 @@ class ParamEditorLike(Protocol):
|
||||
|
||||
|
||||
InterfaceEditorFactory = Callable[
|
||||
[dict[PortID, Port], MainWindow],
|
||||
[dict[PortID, Port], dict[PortID, PortMetadata], MainWindow],
|
||||
InterfaceEditorLike,
|
||||
]
|
||||
|
||||
@@ -60,15 +61,17 @@ class DocumentTreeController(QObject):
|
||||
window.ui.documentTree.setModel(self.model)
|
||||
window.ui.documentTree.selectionModel().selectionChanged.connect(self._selection_changed)
|
||||
window.equation_editor.equation_text_change_requested.connect(self.document.update_component_equation_text)
|
||||
window.equation_editor.port_metadata_change_requested.connect(self._change_equation_port_metadata)
|
||||
document.model_changed.connect(self._on_document_changed)
|
||||
document.icon_changed.connect(self._on_icon_changed)
|
||||
document.port_metadata_database_changed.connect(self._on_port_metadata_database_changed)
|
||||
document.graph_component_position_changed.connect(self._on_graph_component_position_changed)
|
||||
document.graph_component_label_changed.connect(self._on_graph_component_label_changed)
|
||||
document.graph_connection_points_changed.connect(self._on_graph_connection_points_changed)
|
||||
document.equation_text_changed.connect(self._on_equation_text_changed)
|
||||
self.model.rename_document_requested.connect(self.document.rename)
|
||||
self.model.rename_component_requested.connect(self.document.rename_component)
|
||||
window.graph_editor.component_move_requested.connect(self.document.move_graph_component)
|
||||
window.graph_editor.component_moves_requested.connect(self.document.move_graph_components)
|
||||
window.graph_editor.component_label_move_requested.connect(self.document.move_graph_component_label)
|
||||
window.graph_editor.component_context_menu_requested.connect(self._show_graph_component_context_menu)
|
||||
window.graph_editor.component_open_requested.connect(self._open_graph_component)
|
||||
@@ -125,7 +128,8 @@ class DocumentTreeController(QObject):
|
||||
|
||||
def _show_component(self, component: Component | None) -> None:
|
||||
if component is not None and isinstance(component.implementation, EquationImplementation):
|
||||
self.window.equation_editor.set_component(component)
|
||||
port_metadata = {port_id: self.document.port_metadata(port_id) for port_id in component.interface.ports}
|
||||
self.window.equation_editor.set_component(component, port_metadata)
|
||||
self.window.equation_editor.show()
|
||||
else:
|
||||
self.window.equation_editor.set_component(None)
|
||||
@@ -133,7 +137,8 @@ class DocumentTreeController(QObject):
|
||||
if component is not None and isinstance(component.implementation, GraphImplementation):
|
||||
graph = self.document.graph_database().graphs.get(self.document.component_id(component), Graph())
|
||||
icons = {component_id: self.document.component_icon(component_id) for component_id in component.implementation.graph.components}
|
||||
self.window.graph_editor.set_component(component, graph, icons)
|
||||
port_metadata = {port_id: self.document.port_metadata(port_id) for child in component.implementation.graph.components.values() for port_id in child.interface.ports}
|
||||
self.window.graph_editor.set_component(component, graph, icons, port_metadata)
|
||||
self.window.graph_editor.show()
|
||||
else:
|
||||
self.window.graph_editor.set_component(None)
|
||||
@@ -152,6 +157,17 @@ class DocumentTreeController(QObject):
|
||||
if graph_component is not None and isinstance(graph_component.implementation, GraphImplementation) and component_id in graph_component.implementation.graph.components:
|
||||
self._show_component(graph_component)
|
||||
|
||||
def _on_port_metadata_database_changed(self, _database: object) -> None:
|
||||
graph_component = self.window.graph_editor.component()
|
||||
if graph_component is not None:
|
||||
self._show_component(graph_component)
|
||||
equation_component = self.window.equation_editor.component()
|
||||
if equation_component is not None:
|
||||
self.window.equation_editor.refresh_port_metadata({port_id: self.document.port_metadata(port_id) for port_id in equation_component.interface.ports})
|
||||
|
||||
def _change_equation_port_metadata(self, component: Component, port_metadata: dict[PortID, PortMetadata]) -> None:
|
||||
self.document.update_component_ports(component, component.interface.ports, port_metadata)
|
||||
|
||||
def _on_graph_component_position_changed(self, graph_id: ComponentID, component_id: ComponentID, position: tuple[int, int] | None) -> None:
|
||||
graph_component = self.window.graph_editor.component()
|
||||
if graph_component is not None and self.document.component_id(graph_component) == graph_id:
|
||||
@@ -242,10 +258,11 @@ class DocumentTreeController(QObject):
|
||||
def _edit_interface(self, component: Component) -> None:
|
||||
dialog = self.interface_editor_factory(
|
||||
component.interface.ports,
|
||||
{port_id: self.document.port_metadata(port_id) for port_id in component.interface.ports},
|
||||
self.window,
|
||||
)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
self.document.update_component_ports(component, dialog.ports())
|
||||
self.document.update_component_ports(component, dialog.ports(), dialog.port_metadata())
|
||||
|
||||
def _edit_params(self, component: Component) -> None:
|
||||
dialog = self.param_editor_factory(
|
||||
|
||||
Reference in New Issue
Block a user