pySimBlocks.gui.graphics.block_item

class pySimBlocks.gui.graphics.block_item.BlockItem(instance: BlockInstance, pos: QPointF | QPoint, view: DiagramView, layout: dict | None = None)[source]

Bases: QGraphicsRectItem

Render and interact with a block instance on the diagram scene.

view

Diagram view owning this graphics item.

instance

Block instance represented by the item.

orientation

Display orientation of the block.

port_items

Visual port items attached to the block.

WIDTH = 120
HEIGHT = 60
MIN_WIDTH = 40
MIN_HEIGHT = 30
GRID_DX = 5
GRID_DY = 5
SELECTION_HANDLE_SIZE = 8
SELECTION_HANDLE_HIT_SIZE = 16
TYPE_LABEL_MIN_HEIGHT = 45
get_port_item(name: str) PortItem | None[source]

Return the visual port item matching the given port name.

Parameters:

name – Port name to look up.

Returns:

Matching port item, or None if not found.

refresh_ports()[source]

Synchronize visual ports with the current block instance ports.

toggle_orientation()[source]

Flip the block orientation and relayout its ports.

set_orientation(orientation: str) None[source]
boundingRect() QRectF[source]

Return the item bounds including resize-handle hit areas.

Returns:

Bounding rectangle used for painting and interaction.

shape() QPainterPath[source]

Return the selectable shape including resize handles.

Returns:

Painter path used for hit testing.

paint(painter, option, widget=None)[source]

Paint the block body, label, and resize handles when selected.

Parameters:
  • painter – Painter used to render the item.

  • option – Style option describing the current paint state.

  • widget – Optional target widget.

mousePressEvent(event)[source]

Start resize interaction when a selected handle is pressed.

Parameters:

event – Qt mouse-press event.

mouseMoveEvent(event)[source]

Resize or move the block in response to mouse movement.

Parameters:

event – Qt mouse-move event.

mouseReleaseEvent(event)[source]

End any active resize interaction.

Parameters:

event – Qt mouse-release event.

mouseDoubleClickEvent(event)[source]

Open the block configuration dialog on double click.

Parameters:

event – Qt mouse double-click event.

itemChange(change, value)[source]

Snap movement to the grid and notify the view when position changes.

Parameters:
  • change – Item change identifier.

  • value – Proposed new value for the change.

Returns:

Adjusted change value when snapping is needed, otherwise the base implementation result.