GraphModel

class omni.kit.widget.graph.graph_model.GraphModel

Bases: object

The base class for the Graph model.

The model is the central component of the graph widget. It is the application’s dynamic data structure, independent of the user interface, and it directly manages the data. It follows closely model–view pattern. It defines the standard interface to be able to interoperate with the components of the model-view architecture. It is not supposed to be instantiated directly. Instead, the user should subclass it to create a new model.

The model manages two kinds of data elements. Node and port are the atomic data elements of the model. Both node and port can have any number of sub-ports and any number of input and output connections.

There is no specific Python type for the elements of the model. Since Python has dynamic types, the model can return any object as a node or a port. When the widget needs to get a property of the node, it provides the given node back to the model.

Example:

class UsdShadeModel(GraphModel):
    @property
    def nodes(self, prim=None):
        # Return Usd.Prim in a list
        return [stage.GetPrimAtPath(selection)]

    @property
    def name(self, item=None):
        # item here is Usd.Prim because UsdShadeModel.nodes returns
        # Usd.Prim
        return item.GetPath().name

# Accessing nodes and properties example
model = UsdShadeModel()

# UsdShadeModel decides the type of nodes. It's a list with Usd.Prim
nodes = model.nodes

for node in nodes:
    # The node is accessed through evaluation of self[key]. It will
    # return the proxy object that redirects its properties back to
    # model. So the following line will call UsdShadeModel.name(node).
    name = model[node].name
    print(f"The model has node {name}")

Methods

__init__()

can_connect(source, target)

Return if it's possible to connect source to target

destroy()

has_nodes(obj)

Returns true if the model can currently build the graph network using the provided object

position_begin_edit(item)

Called when the user started dragging the node

position_end_edit(item)

Called when the user finished dragging the node and released the mouse

size_begin_edit(item)

Called when the user started resizing the node

size_end_edit(item)

Called when the user finished resizing the node and released the mouse

special_select_widget(node, node_widget)

subscribe_item_changed(fn)

Return the object that will automatically unsubscribe when destroyed.

subscribe_node_changed(fn)

Return the object that will automatically unsubscribe when destroyed.

subscribe_selection_changed(fn)

Return the object that will automatically unsubscribe when destroyed.

Attributes

DISPLAY_NAME

description

The text label that is displayed on the backdrop in the node graph.

display_color

The node color.

expansion_state

icon

Return icon of the image

inputs

name

The name of the item how it should be displayed in the view

nodes

outputs

ports

position

Returns the position of the node

preview

Return the preview of the image

preview_state

Return the state of the preview of the node

selection

size

The node size.

stacking_order

This value is a hint when an application cares about the visibility of a node and whether each node overlaps another.

type

__init__()
class ExpansionState(value)

Bases: Enum

An enumeration.

class PreviewState(value)

Bases: IntFlag

An enumeration.

can_connect(source, target)

Return if it’s possible to connect source to target

static has_nodes(obj)

Returns true if the model can currently build the graph network using the provided object

position_begin_edit(item)

Called when the user started dragging the node

position_end_edit(item)

Called when the user finished dragging the node and released the mouse

size_begin_edit(item)

Called when the user started resizing the node

size_end_edit(item)

Called when the user finished resizing the node and released the mouse

subscribe_item_changed(fn)

Return the object that will automatically unsubscribe when destroyed.

subscribe_node_changed(fn)

Return the object that will automatically unsubscribe when destroyed.

subscribe_selection_changed(fn)

Return the object that will automatically unsubscribe when destroyed.

property description

The text label that is displayed on the backdrop in the node graph.

property display_color

The node color.

property icon: Optional[Union[str, Any]]

Return icon of the image

property name: str

The name of the item how it should be displayed in the view

property position

Returns the position of the node

property preview: Optional[Union[str, Any]]

Return the preview of the image

property preview_state: PreviewState

Return the state of the preview of the node

property size

The node size. Is used for nodes like Backdrop.

property stacking_order

This value is a hint when an application cares about the visibility of a node and whether each node overlaps another.