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:
QObjectEntry 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 callsuper().__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
widgetproperty 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:
edge_connected: Emitted when an edge is connected to this entryedge_disconnected: Emitted when an edge is disconnected from this entryname_changed: Emitted when the name of this entry is changedtheme_changed: Emitted when the theme of this entry is changedresized: Emitted when the entry width is resized
- graphics#
Graphics object that is shown in the scene representing this entry
- Type:
Properties
Input entry type with an input socket
Output entry type with an output socket
Static entry type with no input or output
Signal that is emitted when an edge is connected to this entry
Signal that is emitted when an edge is disconnected from this entry
Get or set the name of the entry
name_changed(QString)Signal that emits the new name of then entry if it changed
Get or set the node this entry is part of.
resized(double)Signal that is emitted when the width of the entry is changed
Get or set the socket for this entry (None if there is no socket)
Get or set the theme of the entry.
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
Get or set the widget that is displayed in this entry.
Methods
Create a new entry.
Create a socket for the entry
Calculate the value of this entry.
Connect an editing signal to the entry widget.
Disconnect the editing signal from the entry widget.
Get the state of this entry as a (JSON-safe) dictionary.
Override this method to load the saved additional values and restore the entry state.
Remove this entry from the node it is part of.
Override this method to save any additional values to the entry state.
Set the state of this entry from a state dictionary.
Update the position and width of the entry based on the node settings.
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:
name (str) – The name for the entry
entry_type (int) – The type of the entry (
TYPE_STATIC,TYPE_INPUT, orTYPE_OUTPUT)theme (Type[
Theme], optional) – Theme for the entry (default:DarkTheme)
- 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 socketcustom: additional values saved through thesave()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
stateis the same as the dictionary returned by thesave()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 socketcustom: additional values saved through thesave()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_disconnected: Signal#
Signal that is emitted when an edge is disconnected from this entry
- Type:
- property name: str#
Get or set the name of the entry
- 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.