def setup_exp(self): """Prepares the patch expander once a patch has been selected. Currently triggered via a button press. """ class MyNode(BaseNode): """ example test node. """ # set a unique node identifier. __identifier__ = 'com.chantasticvfx' # set the initial default node name. NODE_NAME = 'my node' def __init__(self): super(MyNode, self).__init__() self.set_color(25, 58, 51) # QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) # win = QtWidgets.QApplication([]) win = QWidget() win.setWindowTitle( "Interactive Patch Routing: {}".format(self.curr_viz["name"]) ) win.setWindowIcon(QIcon( os.path.join(os.getcwd(), "zoia_lib", "UI", "resources", "logo.ico"))) win.setFixedSize(540, 540) # create node graph. graph = NodeGraph() # set up default menu and commands. setup_context_menu(graph) # widget used for the node graph. graph_widget = graph.widget graph_widget.resize(1100, 800) graph_widget.show() # 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) # show the nodes list when a node is "double clicked" in the graph. node_tree = NodeTreeWidget(node_graph=graph) def show_nodes_list(node): if not node_tree.isVisible(): node_tree.update() node_tree.show() graph.node_double_clicked.connect(show_nodes_list) # registered nodes. nodes_to_reg = [ # BackdropNode, MyNode, # basic_nodes.FooNode, # basic_nodes.BarNode, # widget_nodes.DropdownMenuNode, # widget_nodes.TextInputNode, # widget_nodes.CheckboxNode ] graph.register_nodes(nodes_to_reg) pch = self.curr_viz nodes = {} for module in pch['modules']: my_node = graph.create_node( 'com.chantasticvfx.MyNode', name=(module['type'] if module['name'] == '' else module['name']) + str(module["number"]), color='#0a1e20', text_color='#feab20' ) inp, outp, in_pos, out_pos = [], [], [], [] for key, param in module['blocks'].items(): if 'in' in key: my_node.add_input(key) inp.append(key) in_pos.append(int(param["position"])) elif param["isParam"]: my_node.add_input(key) inp.append(key) in_pos.append(int(param["position"])) elif 'out' in key: my_node.add_output(key) outp.append(key) out_pos.append(int(param["position"])) nodes[module["number"]] = my_node, inp, outp, in_pos, out_pos # print(nodes) # map pos from nodes to connections def node_pos_map(node): inpts = node[1] outps = node[2] in_pos = node[3] out_pos = node[4] node_pos_start = [x for x in range(0, len(inpts))] node_pos_end = [x for x in range(0, len(outps))] data_input = dict(zip(in_pos, node_pos_start)) data_output = dict(zip(out_pos, node_pos_end)) return {**data_input, **data_output} data = [] for key, node in nodes.items(): data.append(node_pos_map(node)) for conn in pch['connections']: mod, block = conn['source'].split('.') nmod, nblock = conn['destination'].split('.') src = data[int(mod)] dest = data[int(nmod)] try: nodes[int(mod)][0].set_output( src[int(block)], nodes[int(nmod)][0].input(dest[int(nblock)]) ) except KeyError as e: print(conn, e) except IndexError as e: print(conn, e) print('done making connections') # auto layout nodes. graph.auto_layout_nodes() # wrap a backdrop node. # backdrop_node = graph.create_node('nodeGraphQt.nodes.BackdropNode') # backdrop_node.wrap_nodes([text_node, checkbox_node]) graph.fit_to_selection() win.exec_()
# create example "TextInputNode". checkbox_node = graph.create_node('com.chantasticvfx.CheckboxNode', name='checkbox node') # create node with a combo box menu. menu_node = graph.create_node('com.chantasticvfx.DropdownMenuNode', name='menu node') # change node icon. this_path = os.path.dirname(os.path.abspath(__file__)) icon = os.path.join(this_path, 'example_nodes', 'pear.png') bar_node = graph.create_node('com.chantasticvfx.BarNode') bar_node.set_icon(icon) bar_node.set_name('icon node') # connect the nodes. foo_node.set_output(0, bar_node.input(2)) menu_node.set_input(0, bar_node.output(1)) bar_node.set_input(0, text_node.output(0)) # auto layout nodes. graph.auto_layout_nodes() # wrap a backdrop node. backdrop_node = graph.create_node('nodeGraphQt.nodes.BackdropNode') backdrop_node.wrap_nodes([text_node, checkbox_node]) graph.fit_to_selection() app.exec_()