QNodeEditor.entry.Entry#

class QNodeEditor.entry.Entry(name: str, entry_type: int = 0, theme: ~typing.Type[~QNodeEditor.themes.theme.Theme] = <class 'QNodeEditor.themes.dark.DarkTheme'>)#

Bases: QObject

Entry container holding a widget and an optional socket for input/output.

This class is abstract and cannot be used by itself. To define entries to use in nodes, inherit from this class and override the __init__ method (making sure to call super().__init__()) to set the entry properties.

Examples

To define an entry with a QLabel and an input socket:

from PyQt5.QtWidgets import QLabel

class MyEntry(Entry):

    def __init__(self, name):
        super().__init__(name, Entry.TYPE_INPUT)

        self.widget = QLabel(name)

The widget property can be set to add a widget to the entry. This can be any widget. The widget is constrained in width by the node, but not in height.

We can connect to signals in the entry to update our widget if required:

def __init__(self, name):
    ...
    self.name_changed.connect(self.handle_name_change)

def handle_name_change(self, new_name):
    self.widget.setText(new_name)

The available signals are:

graphics#

Graphics object that is shown in the scene representing this entry

Type:

EntryGraphics

value#

Output value of this entry (if not set: NoValue)

Type:

Any

Properties

TYPE_INPUT

Input entry type with an input socket

TYPE_OUTPUT

Output entry type with an output socket

TYPE_STATIC

Static entry type with no input or output

edge_connected()

Signal that is emitted when an edge is connected to this entry

edge_disconnected()

Signal that is emitted when an edge is disconnected from this entry

name

Get or set the name of the entry

name_changed(QString)

Signal that emits the new name of then entry if it changed

node

Get or set the node this entry is part of.

resized(double)

Signal that is emitted when the width of the entry is changed

socket

Get or set the socket for this entry (None if there is no socket)

theme

Get or set the theme of the entry.

theme_changed()

Signal that is emitted when the theme of the entry is changed

value_changed(PyQt_PyObject)

Signal that emits the new value of the entry widget if it changed

widget

Get or set the widget that is displayed in this entry.

Methods

__init__

Create a new entry.

add_socket

Create a socket for the entry

calculate_value

Calculate the value of this entry.

connect_signal

Connect an editing signal to the entry widget.

disconnect_signal

Disconnect the editing signal from the entry widget.

get_state

Get the state of this entry as a (JSON-safe) dictionary.

load

Override this method to load the saved additional values and restore the entry state.

remove

Remove this entry from the node it is part of.

save

Override this method to save any additional values to the entry state.

set_state

Set the state of this entry from a state dictionary.

update_geometry

Update the position and width of the entry based on the node settings.

update_padding

Update the padding for the entry widget based on the set theme

__init__(name: str, entry_type: int = 0, theme: ~typing.Type[~QNodeEditor.themes.theme.Theme] = <class 'QNodeEditor.themes.dark.DarkTheme'>)#

Create a new entry.

Parameters:
add_socket() Socket#

Create a socket for the entry

Returns:

Created socket

Return type:

Socket

calculate_value() Any#

Calculate the value of this entry.

There are two cases:

  • If this entry is an input and an edge is connected, evaluate the connected node and take its value.

  • Otherwise, use the value of the widget in the entry (None if unable to retrieve value).

See get_widget_value() for the supported widgets.

Returns:

Value of this entry

Return type:

Any

connect_signal() None#

Connect an editing signal to the entry widget.

Return type:

None

disconnect_signal() None#

Disconnect the editing signal from the entry widget.

Return type:

None

get_state() dict#

Get the state of this entry as a (JSON-safe) dictionary.

The dictionary contains:

  • socket: state of the entry socket

  • custom: additional values saved through the save() method

Returns:

JSON-safe dictionary representing entry state

Return type:

dict

load(state: dict) bool#

Override this method to load the saved additional values and restore the entry state.

The received state is the same as the dictionary returned by the save() method (an empty dictionary if not overridden).

Use this method to use the saved values to restore the entry to the desired state.

Parameters:

state (dict) – Saved additional values by save()

Returns:

Whether the method executed successfully

Return type:

bool

remove() None#

Remove this entry from the node it is part of.

Any edges connected to this entry are also removed.

Return type:

None

save() dict#

Override this method to save any additional values to the entry state.

The dictionary returned by this function is saved along with the rest of the entry state. It is provided back to the load() method when the node is loaded again.

Use this method to add any variables to the node state that are needed to restore the entry to the desired state when the entry is loaded.

Returns:

  • dict – Additional values to save (key, value) pairs.

    Must be JSON-safe

  • :meta abstract:

set_state(state: dict, restore_id: bool = True) bool#

Set the state of this entry from a state dictionary.

The dictionary contains:

  • socket: state of the entry socket

  • custom: additional values saved through the save() method

Parameters:
  • state (dict) – Dictionary representation of the desired entry state

  • restore_id (bool) – Whether to restore the internal IDs of the entry sockets (used to reconnect saved edges)

Returns:

Whether setting the entry state succeeded

Return type:

bool

update_geometry() None#

Update the position and width of the entry based on the node settings.

After this update, update all connected edges in case the socket positions changed.

Return type:

None

update_padding() None#

Update the padding for the entry widget based on the set theme

Return type:

None

TYPE_INPUT: int = 1#

Input entry type with an input socket

Type:

int

TYPE_OUTPUT: int = 2#

Output entry type with an output socket

Type:

int

TYPE_STATIC: int = 0#

Static entry type with no input or output

Type:

int

edge_connected: Signal#

Signal that is emitted when an edge is connected to this entry

Type:

Signal

edge_disconnected: Signal#

Signal that is emitted when an edge is disconnected from this entry

Type:

Signal

property name: str#

Get or set the name of the entry

name_changed(QString): Signal#

Signal that emits the new name of then entry if it changed

Type:

Signal

property node: Node | None#

Get or set the node this entry is part of.

resized(double): Signal#

Signal that is emitted when the width of the entry is changed

Type:

Signal

property socket: Socket#

Get or set the socket for this entry (None if there is no socket)

Setting the socket will automatically attach signals to detect edge changes.

property theme: Type[Theme]#

Get or set the theme of the entry.

Setting the theme of the entry affects all child elements.

theme_changed: Signal#

Signal that is emitted when the theme of the entry is changed

Type:

Signal

value_changed(PyQt_PyObject): Signal#

Signal that emits the new value of the entry widget if it changed

Type:

Signal

property widget: QWidget#

Get or set the widget that is displayed in this entry.

Setting the widget will automatically attach signals to detect a value change (if possible).