Skip to content

Component Base Classes

The classes in digsim.circuit.components.atoms that all components are built on. Every component has the methods of Component, like name(), port() and inports(). Subclass them to write your own components.

Component

Component(
    circuit: Circuit,
    name: str | None = None,
    display_name: str | None = None,
)

Bases: ABC

The component base class

circuit property

circuit: Circuit

Get the circuit for the current component

ports property

ports: list[Port]

Get component ports

parent property writable

parent: Component | None

Get parent component

wire property writable

wire: NoReturn

Property needed to be able to have a setter

active property

active: bool

Return True if this component is active/activated ('on' for a switch for example)

has_action property

has_action: bool

Return True if this component is interactive

name

name() -> str

Get the component name

set_name

set_name(name: str, update_circuit: bool = True) -> None

Set the component name

display_name

display_name() -> str

Get the component display name

set_display_name

set_display_name(display_name: str) -> None

Set the component display name

port

port(portname: str) -> Port

Get port with name 'portname'

inports

inports() -> list[Port]

Get component input ports

outports

outports() -> list[Port]

Get component output ports

path

path() -> str

Get component path (iterative)

is_toplevel

is_toplevel() -> bool

Return True if this component is a toplevel component

add_port

add_port(port: Port) -> None

Add port to component, also add a 'portname' variable to the component with help of the 'self.dict'

parameter_set

parameter_set(
    parameter: str, value: ParameterValue
) -> None

Set component parameter

parameter_get

parameter_get(parameter: str) -> Any

Get component parameter

update

update() -> None

This function is called if a port change and that port should update its parent

default_state

default_state() -> None

Setup default state, for example port outputs

init

init() -> None

Initialize port, will be called when circuit is initialized

get_parameters classmethod

get_parameters() -> dict[str, Parameter]

Return parameters

reconfigure

reconfigure() -> None

Update the component from the parameters

settings_to_dict

settings_to_dict() -> dict[str, ParameterValue]

Return component settings as a dict

onpress

onpress() -> None

What to happen for an interactive activation

onrelease

onrelease() -> None

What to happen for an interactive de-activation

CallbackComponent

CallbackComponent(
    circuit: Circuit,
    name: str | None,
    callback: Callable[[Component], None] | None = None,
)

Bases: Component

A component that will call a callback function upon change, this is used to for example output text in stdout or update GUI objects when the component change value.

set_callback

set_callback(callback: Callable[[Component], None]) -> None

Set CallbackComponent callback function

MultiComponent

MultiComponent(circuit: Circuit, name: str | None = None)

Bases: Component

A component that holds one or several sub components. The sub components are in the circuit too, so the circuit initializes them.

add

add(component: Component) -> None

Add sub-component to MultiComponent

Parameters

Parameter

Bases: TypedDict

The description of a component parameter, returned by get_parameters(). The GUI builds the settings dialog from it, see "The settings dialog" in the guide for adding components to the GUI.

type instance-attribute

description instance-attribute

description: str

default instance-attribute

default: NotRequired[Any]

min instance-attribute

min: NotRequired[int]

max instance-attribute

max: NotRequired[int]

reconfigurable instance-attribute

reconfigurable: NotRequired[bool]

single_line instance-attribute

single_line: NotRequired[bool]

invalid_list instance-attribute

invalid_list: NotRequired[list[str]]

items instance-attribute

items: NotRequired[list[str]]

range instance-attribute

range: NotRequired[list[int]]

default_index instance-attribute

default_index: NotRequired[int]

component_list instance-attribute

component_list: NotRequired[dict[str, str]]

fileinfo instance-attribute

fileinfo: NotRequired[str]

ParameterType module-attribute

ParameterType = Literal[
    "bool",
    "component_name",
    "ic_name",
    "int",
    "intrange",
    "list",
    "path",
    "str",
    "width_bool",
    "width_pow2",
]

Exceptions

DigsimException

Bases: Exception

The digsim exception base class

ComponentException

Bases: DigsimException

Component error exception class