pySimBlocks.gui.widgets.diagram_view

class pySimBlocks.gui.widgets.diagram_view.DiagramView[source]

Bases: QGraphicsView

Interactive Qt graphics view for the block diagram canvas.

Handles block/connection rendering, drag-and-drop, keyboard shortcuts, zoom, and mouse-driven wire creation.

diagram_scene

The underlying QGraphicsScene.

theme

Current visual theme (colours, brushes).

pending_port

Port item waiting for a connection to be completed.

temp_connection

Temporary wire shown while dragging from a port.

copied_block

Most recently copied block, used for paste.

project_controller

Controller coordinating model mutations.

block_items

Mapping from block UID to its visual BlockItem.

connections

Mapping from ConnectionInstance to its visual ConnectionItem.

add_block(block_instance: BlockInstance, block_layout: dict[str, Any] | None = None) None[source]

Add a visual block item to the scene for the given block instance.

Parameters:
  • block_instance – The block model to represent visually.

  • block_layout – Optional dict with position/size hints.

refresh_block_port(block_instance: BlockInstance) None[source]

Refresh the port visuals of the block item for the given instance.

Parameters:

block_instance – The block whose port items should be refreshed.

remove_block(block_instance: BlockInstance) None[source]

Remove the visual block item for the given instance from the scene.

Parameters:

block_instance – The block whose visual item should be removed.

add_connection(connection_instance: ConnectionInstance, points: list[QPointF] | None = None) None[source]

Add a visual wire to the scene for the given connection instance.

Parameters:
  • connection_instance – The connection model to represent visually.

  • points – Optional list of intermediate waypoints for the wire.

remove_connection(connection_instance: ConnectionInstance) None[source]

Remove the visual wire for the given connection instance from the scene.

Parameters:

connection_instance – The connection whose visual item should be removed.

get_block_item_from_instance(block_instance: BlockInstance) BlockItem | None[source]

Return the visual BlockItem for the given block instance, or None.

Parameters:

block_instance – The block model to look up.

Returns:

The corresponding BlockItem, or None if not found.

create_connection_event(port: PortItem) None[source]

Begin a wire-drag interaction from the given port item.

Parameters:

port – The port item from which the connection is being drawn.

update_block_param_event(block_instance: BlockInstance, params: dict[str, Any]) None[source]

Delegate a parameter update for the given block to the project controller.

Parameters:
  • block_instance – The block to update.

  • params – New parameter dict to apply.

on_block_moved(block_item: BlockItem) None[source]

Mark the project dirty and refresh all wires connected to the moved block.

Parameters:

block_item – The block item that was repositioned.

on_block_ports_refreshed(block_item: BlockItem) None[source]

Refresh all wire positions after the ports of a block have been updated.

Parameters:

block_item – The block item whose ports were refreshed.

dragEnterEvent(event) None[source]

Accept drag events that carry text MIME data.

Parameters:

event – Qt drag-enter event.

dragMoveEvent(event) None[source]

Accept proposed drag-move actions unconditionally.

Parameters:

event – Qt drag-move event.

dropEvent(event) None[source]

Handle a block drop by adding the corresponding block to the project.

Parameters:

event – Qt drop event carrying "category:block_type" text.

keyPressEvent(event) None[source]

Handle keyboard shortcuts for copy, paste, delete, zoom, rotate, and center.

Parameters:

event – Qt key-press event.

wheelEvent(event) None[source]

Zoom the view when Ctrl is held, otherwise scroll normally.

Parameters:

event – Qt wheel event.

mouseMoveEvent(event) None[source]

Update the temporary wire endpoint while dragging from a port.

Parameters:

event – Qt mouse-move event.

mouseReleaseEvent(event) None[source]

Complete or cancel a wire drag on mouse release.

Parameters:

event – Qt mouse-release event.

delete_selected() None[source]

Remove all selected blocks and connections from the project.

clear_scene() None[source]

Remove all blocks and connections from the scene and reset state.

scale_view(factor: float) None[source]

Scale the view by factor, clamped to the allowed zoom range.

Parameters:

factor – Multiplicative zoom factor to apply.

staticMetaObject = PySide6.QtCore.QMetaObject("DiagramView" inherits "QGraphicsView": )