33 NODE_LAYOUT_HORIZONTAL )
44
55from NodeGraphQt .nodes .base_node import BaseNode
6+ from NodeGraphQt .nodes .port_node import PortInputNode , PortOutputNode
67from NodeGraphQt .qgraphics .node_group import (GroupNodeItem ,
78 GroupNodeVerticalItem )
89
@@ -14,6 +15,9 @@ class GroupNode(BaseNode):
1415 inside of it.
1516
1617 **Inherited from:** :class:`NodeGraphQt.BaseNode`
18+
19+ .. image:: ../_images/group_node.png
20+ :width: 250px
1721 """
1822
1923 NODE_NAME = 'Group'
@@ -35,11 +39,14 @@ def is_expanded(self):
3539 Returns:
3640 bool: true if the node is expanded.
3741 """
42+ if not self .graph :
43+ return False
3844 return bool (self .id in self .graph .sub_graphs )
3945
4046 def get_sub_graph (self ):
4147 """
42- Returns the initialized sub node graph controller to the group node.
48+ Returns the sub graph controller to the group node if initialized
49+ or returns None.
4350
4451 Returns:
4552 NodeGraphQt.SubGraph or None: sub graph controller.
@@ -84,3 +91,71 @@ def collapse(self):
8491 :meth:`SubGraph.collapse_group_node`.
8592 """
8693 self .graph .collapse_group_node (self )
94+
95+ def add_input (self , name = 'input' , multi_input = False , display_name = True ,
96+ color = None , locked = False , painter_func = None ):
97+ port = super (GroupNode , self ).add_input (
98+ name = name ,
99+ multi_input = multi_input ,
100+ display_name = display_name ,
101+ color = color ,
102+ locked = locked ,
103+ painter_func = painter_func
104+ )
105+ if self .is_expanded :
106+ input_node = PortInputNode (parent_port = port )
107+ input_node .NODE_NAME = port .name ()
108+ input_node .model .set_property ('name' , port .name ())
109+ input_node .add_output (port .name ())
110+ sub_graph = self .get_sub_graph ()
111+ sub_graph .add_node (input_node , selected = False , push_undo = False )
112+
113+ return port
114+
115+ def add_output (self , name = 'output' , multi_output = True , display_name = True ,
116+ color = None , locked = False , painter_func = None ):
117+ port = super (GroupNode , self ).add_output (
118+ name = name ,
119+ multi_output = multi_output ,
120+ display_name = display_name ,
121+ color = color ,
122+ locked = locked ,
123+ painter_func = painter_func
124+ )
125+ if self .is_expanded :
126+ output_port = PortOutputNode (parent_port = port )
127+ output_port .NODE_NAME = port .name ()
128+ output_port .model .set_property ('name' , port .name ())
129+ output_port .add_input (port .name ())
130+ sub_graph = self .get_sub_graph ()
131+ sub_graph .add_node (output_port , selected = False , push_undo = False )
132+
133+ return port
134+
135+ def delete_input (self , port ):
136+ if type (port ) in [int , str ]:
137+ port = self .get_output (port )
138+ if port is None :
139+ return
140+
141+ if self .is_expanded :
142+ sub_graph = self .get_sub_graph ()
143+ port_node = sub_graph .get_node_by_port (port )
144+ if port_node :
145+ sub_graph .remove_node (port_node , push_undo = False )
146+
147+ super (GroupNode , self ).delete_input (port )
148+
149+ def delete_output (self , port ):
150+ if type (port ) in [int , str ]:
151+ port = self .get_output (port )
152+ if port is None :
153+ return
154+
155+ if self .is_expanded :
156+ sub_graph = self .get_sub_graph ()
157+ port_node = sub_graph .get_node_by_port (port )
158+ if port_node :
159+ sub_graph .remove_node (port_node , push_undo = False )
160+
161+ super (GroupNode , self ).delete_output (port )
0 commit comments