This project is a node-based editor built using Dear PyGui. It allows users to create, connect, and manage nodes that perform various operations. The system is designed to be extensible, allowing developers to create custom nodes with specific functionalities.
- Create and manage nodes
- Connect nodes to pass data between them
- Save and load workspace configurations
- Customizable node operations
- Copy/Past
- A preview window to visualize the output of a node (control + left click on a node)
- Type security for the nodes inputs and outputs
- undo/redo
-
Clone the repository:
git clone https://github.com/dron3flyv3r/NodeSystem-MK2.git cd NodeSystem-MK2
-
Install the required dependencies:
pip install dearpygui
To start the node editor, run the following command:
python NodeEditor/NodeEditor.py
This will open the main viewport where you can add, connect, and manage nodes.
Here you can see a simple example of the basic operations that are included in the node system.
Here you can see a simple templating example, where you can create a template and use it to find where in a image the template is located.
To create a new node, follow these steps:
-
Create a new Python file in the
NodeEditor/Nodes
directory. For example,MyNode.py
. -
Define a new class that inherits from
Node
. Implement the required methods.
# filepath: /NodeSystem-MK2/NodeEditor/Nodes/MyNode.py
import dearpygui.dearpygui as dpg
from NodeEditor.Core.Node import Node
from NodeEditor.Core.NodePackage import NodePackage
class MyNode(Node):
def __init__(self):
super().__init__("MyNode", "Category")
self.input_idx = self.add_input("Input")
self.add_output("Output")
def compose(self):
dpg.add_text("MyNode")
def execute(self, inputs: list[NodePackage]) -> list[NodePackage]:
input_package = inputs[self.input_idx]
output_package = NodePackage()
output_package.number = input_package.number * 2 # Example operation
return [output_package]
def view(self, output: NodePackage):
dpg.add_text(f"Output: {output.number}")
- The new node will be automatically loaded and available in the node editor.
To create a custom node package, inherit from NodePackage
:
from NodeEditor.Core.NodePackage import NodePackage
class MyNodePackage(NodePackage):
# Define any attributes or methods you need.
pass
When working with a custom package, simply pass or return instances of it from node methods:
def execute(self, inputs: list[MyNodePackage]) -> list[MyNodePackage]:
return [MyNodePackage()]
The base class for all nodes. It provides methods to add inputs, outputs, and define the node's behavior.
__init__(self, label: str, catagory: str, max_width: int = 100)
: Initializes the node with a label and category.add_input(self, label: str = "") -> int
: Adds an input to the node.add_output(self, label: str = "") -> int
: Adds an output to the node.compose(self)
: Defines the node's UI components.execute(self, inputs: list[NodePackage]) -> list[NodePackage]
: Defines the node's operation.view(self, output: NodePackage)
: Updates the node's view with the output data. (Need eitherview
orviewer
)viewer(self, outputs: list[NodePackage])
: Updates the node's view with the output data. (Need eitherview
orviewer
)
A class to encapsulate data passed between nodes.
number: int
: An example attribute.string: str
: An example attribute.text(self) -> str
: Returns a string representation of the package.copy(self) -> 'NodePackage'
: Returns a deep copy of the package.
Contributions are welcome! Please fork the repository and submit a pull request.