forked from jchanvfx/NodeGraphQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_auto_nodes.py
90 lines (70 loc) · 2.78 KB
/
example_auto_nodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
# -*- coding: utf-8 -*-
from NodeGraphQt import NodeGraph, setup_context_menu, \
QtWidgets, QtCore, PropertiesBinWidget, BackdropNode
from example_auto_nodes import Publish, RootNode, update_nodes, setup_node_menu
import importlib
import inspect
import sys
import os
def get_nodes_from_folder(folder_path):
path, folder_name = os.path.split(folder_path)
if path not in sys.path:
sys.path.append(path)
nodes = []
for i in os.listdir(folder_path):
if not i.endswith(".py") or i.startswith("_"):
continue
filename = i[:-3]
module_name = folder_name + "." + filename
for name, obj in inspect.getmembers(importlib.import_module(module_name)):
if inspect.isclass(obj) and filename in str(obj):
if len(inspect.getmembers(obj)) > 0 and obj.__identifier__ != '__None':
nodes.append(obj)
return nodes
def get_published_nodes_from_folder(folder_path):
path, folder_name = os.path.split(folder_path)
if path not in sys.path:
sys.path.append(path)
nodes = []
for i in os.listdir(folder_path):
if not i.endswith(".node") and not i.endswith(".json"):
continue
file_name = os.path.join(folder_path, i)
node = Publish.create_node_class(file_name)
if node is not None:
nodes.append(node)
return nodes
if __name__ == '__main__':
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
app = QtWidgets.QApplication()
# create node graph.
graph = NodeGraph()
graph.use_OpenGL()
# set up default menu and commands.
setup_context_menu(graph)
setup_node_menu(graph, Publish)
# show the properties bin when a node is "double clicked" in the graph.
properties_bin = PropertiesBinWidget(node_graph=graph)
properties_bin.setWindowFlags(QtCore.Qt.Tool)
def show_prop_bin(node):
if not properties_bin.isVisible():
properties_bin.show()
graph.node_double_clicked.connect(show_prop_bin)
# register nodes
reg_nodes = get_nodes_from_folder(os.getcwd() + "/example_auto_nodes")
BackdropNode.__identifier__ = 'Utility::Backdrop'
reg_nodes.append(BackdropNode)
reg_nodes.extend(get_published_nodes_from_folder(os.getcwd() + "/example_auto_nodes/published_nodes"))
[graph.register_node(n) for n in reg_nodes]
# create root node
# if we want to use sub graph system, root node is must.
graph.add_node(RootNode())
# create test nodes
graph.load_session(r'example_auto_nodes/networks/example_SubGraph.json')
update_nodes(graph.root_node().children())
# widget used for the node graph.
graph_widget = graph.widget
graph_widget.resize(1100, 800)
graph_widget.show()
sys.exit(app.exec_())