@@ -141,45 +141,38 @@ class _PortConnectionsContainer(QtWidgets.QWidget):
141141 under a tab in the ``NodePropWidget`` widget.
142142 """
143143
144- ingroup_visible_toggled = QtCore .Signal (bool )
145- outgroup_visible_toggled = QtCore .Signal (bool )
146-
147144 def __init__ (self , parent = None , node = None ):
148145 super (_PortConnectionsContainer , self ).__init__ (parent )
149146 self ._node = node
150147 self ._ports = {}
151148
152- in_group , self .in_tree = self ._build_tree_group ('Input Ports' )
153- in_group .setToolTip ('Display input port connections' )
149+ self .input_group , self .input_tree = self ._build_tree_group (
150+ 'Input Ports'
151+ )
152+ self .input_group .setToolTip ('Display input port connections' )
154153 for _ , port in node .inputs ().items ():
155- self ._build_row (self .in_tree , port )
156- for col in range (self .in_tree .columnCount ()):
157- self .in_tree .resizeColumnToContents (col )
154+ self ._build_row (self .input_tree , port )
155+ for col in range (self .input_tree .columnCount ()):
156+ self .input_tree .resizeColumnToContents (col )
158157
159- out_group , self .out_tree = self ._build_tree_group ('Output Ports' )
160- out_group .setToolTip ('Display output port connections' )
158+ self .output_group , self .output_tree = self ._build_tree_group (
159+ 'Output Ports'
160+ )
161+ self .output_group .setToolTip ('Display output port connections' )
161162 for _ , port in node .outputs ().items ():
162- self ._build_row (self .out_tree , port )
163- for col in range (self .out_tree .columnCount ()):
164- self .out_tree .resizeColumnToContents (col )
163+ self ._build_row (self .output_tree , port )
164+ for col in range (self .output_tree .columnCount ()):
165+ self .output_tree .resizeColumnToContents (col )
165166
166167 layout = QtWidgets .QVBoxLayout (self )
167- layout .addWidget (in_group )
168- layout .addWidget (out_group )
168+ layout .addWidget (self . input_group )
169+ layout .addWidget (self . output_group )
169170 layout .addStretch ()
170171
171- # wire up signals & slots
172- in_group .clicked .connect (
173- lambda x : self .ingroup_visible_toggled .emit (x )
174- )
175- out_group .clicked .connect (
176- lambda x : self .outgroup_visible_toggled .emit (x )
177- )
178-
179- in_group .setChecked (False )
180- self .in_tree .setVisible (False )
181- out_group .setChecked (False )
182- self .out_tree .setVisible (False )
172+ self .input_group .setChecked (False )
173+ self .input_tree .setVisible (False )
174+ self .output_group .setChecked (False )
175+ self .output_tree .setVisible (False )
183176
184177 def __repr__ (self ):
185178 return '<{} object at {}>' .format (
@@ -189,6 +182,8 @@ def __repr__(self):
189182 @staticmethod
190183 def _build_tree_group (title ):
191184 """
185+ Build the ports group box and ports tree widget.
186+
192187 Args:
193188 title (str): group box title.
194189
@@ -218,9 +213,11 @@ def _build_tree_group(title):
218213
219214 def _build_row (self , tree , port ):
220215 """
216+ Builds a new row in the parent ports tree widget.
217+
221218 Args:
222- tree (QtWidgets.QTreeWidget):
223- port (NodeGraphQt.Port):
219+ tree (QtWidgets.QTreeWidget): parent port tree widget.
220+ port (NodeGraphQt.Port): port object.
224221 """
225222 item = QtWidgets .QTreeWidgetItem (tree )
226223 item .setFlags (item .flags () & ~ QtCore .Qt .ItemIsSelectable )
@@ -245,15 +242,15 @@ def _build_row(self, tree, port):
245242 tree .setItemWidget (item , 2 , combo )
246243
247244 focus_btn = QtWidgets .QPushButton ()
248- focus_btn .setIcon (QtGui .QIcon (tree . style (). standardPixmap (
249- QtWidgets .QStyle .SP_DialogYesButton
250- )))
245+ focus_btn .setIcon (QtGui .QIcon (
246+ tree . style (). standardPixmap ( QtWidgets .QStyle .SP_DialogYesButton )
247+ ))
251248 focus_btn .clicked .connect (
252- lambda : self ._on_focus_on_node (self ._ports .get (combo .currentText ()))
249+ lambda : self ._on_focus_to_node (self ._ports .get (combo .currentText ()))
253250 )
254251 tree .setItemWidget (item , 3 , focus_btn )
255252
256- def _on_focus_on_node (self , port ):
253+ def _on_focus_to_node (self , port ):
257254 """
258255 Slot function emits the node is of the connected port.
259256
@@ -280,9 +277,6 @@ class NodePropWidget(QtWidgets.QWidget):
280277 property_changed = QtCore .Signal (str , str , object )
281278 property_closed = QtCore .Signal (str )
282279
283- # emitted when a widget is shown or hidden. (node_id, visible, widget)
284- widget_visible_changed = QtCore .Signal (str , bool , QtWidgets .QWidget )
285-
286280 def __init__ (self , parent = None , node = None ):
287281 super (NodePropWidget , self ).__init__ (parent )
288282 self .__node_id = node .id
@@ -322,17 +316,7 @@ def __init__(self, parent=None, node=None):
322316 layout .addWidget (self .__tab )
323317 layout .addWidget (self .type_wgt )
324318
325- self ._ports_container = self ._read_node (node )
326- self ._ports_container .ingroup_visible_toggled .connect (
327- lambda v : self .widget_visible_changed .emit (
328- self .__node_id , v , self ._ports_container .in_tree
329- )
330- )
331- self ._ports_container .outgroup_visible_toggled .connect (
332- lambda v : self .widget_visible_changed .emit (
333- self .__node_id , v , self ._ports_container .out_tree
334- )
335- )
319+ self ._port_connections = self ._read_node (node )
336320
337321 def __repr__ (self ):
338322 return '<{} object at {}>' .format (
@@ -479,7 +463,7 @@ def get_widget(self, name):
479463 name (str): property name.
480464
481465 Returns:
482- QtWidgets.QWidget : property widget.
466+ NodeGraphQt.custom_widgets.properties_bin.prop_widgets_abstract.BaseProperty : property widget.
483467 """
484468 if name == 'name' :
485469 return self .name_wgt
@@ -488,6 +472,15 @@ def get_widget(self, name):
488472 if widget :
489473 return widget
490474
475+ def get_port_connection_widget (self ):
476+ """
477+ Returns the ports connections container widget.
478+
479+ Returns:
480+ _PortConnectionsContainer: port container widget.
481+ """
482+ return self ._port_connections
483+
491484
492485class PropertiesBinWidget (QtWidgets .QWidget ):
493486 """
@@ -537,6 +530,9 @@ def __init__(self, parent=None, node_graph=None):
537530 self ._limit .valueChanged .connect (self .__on_limit_changed )
538531 self .resize (450 , 400 )
539532
533+ # this attribute to block signals if for the "on_property_changed" signal
534+ # in case devs that don't implemented the ".prop_widgets_abstract.BaseProperty"
535+ # widget is not implemented properly to prevent infinite loop.
540536 self ._block_signal = False
541537
542538 self ._lock = False
@@ -571,7 +567,7 @@ def __repr__(self):
571567 self .__class__ .__name__ , hex (id (self ))
572568 )
573569
574- def __on_widget_visible_changed (self , node_id , visible , tree_widget ):
570+ def __on_port_tree_visible_changed (self , node_id , visible , tree_widget ):
575571 """
576572 Triggered when the visibility of the port tree widget changes we
577573 resize the property list table row.
@@ -635,11 +631,11 @@ def __on_graph_property_changed(self, node, prop_name, prop_value):
635631 if not properties_widget :
636632 return
637633
638- property_window = properties_widget .get_widget (prop_name )
634+ property_widget = properties_widget .get_widget (prop_name )
639635
640- if property_window and prop_value != property_window .get_value ():
636+ if property_widget and prop_value != property_widget .get_value ():
641637 self ._block_signal = True
642- property_window .set_value (prop_value )
638+ property_widget .set_value (prop_value )
643639 self ._block_signal = False
644640
645641 def __on_property_widget_changed (self , node_id , prop_name , prop_value ):
@@ -691,12 +687,22 @@ def add_node(self, node):
691687 self ._prop_list .removeRow (itm_find [0 ].row ())
692688
693689 self ._prop_list .insertRow (0 )
690+
694691 prop_widget = NodePropWidget (node = node )
695- prop_widget .property_changed .connect (self .__on_property_widget_changed )
696692 prop_widget .property_closed .connect (self .__on_prop_close )
697- prop_widget .widget_visible_changed .connect (
698- self .__on_widget_visible_changed
693+ prop_widget .property_changed .connect (self .__on_property_widget_changed )
694+ port_connections = prop_widget .get_port_connection_widget ()
695+ port_connections .input_group .clicked .connect (
696+ lambda v : self .__on_port_tree_visible_changed (
697+ prop_widget .node_id (), v , port_connections .input_tree
698+ )
699699 )
700+ port_connections .output_group .clicked .connect (
701+ lambda v : self .__on_port_tree_visible_changed (
702+ prop_widget .node_id (), v , port_connections .output_tree
703+ )
704+ )
705+
700706 self ._prop_list .setCellWidget (0 , 0 , prop_widget )
701707
702708 item = QtWidgets .QTableWidgetItem (node .id )
0 commit comments