55 NODE_WIDTH , NODE_HEIGHT ,
66 NODE_ICON_SIZE , ICON_NODE_BASE ,
77 NODE_SEL_COLOR , NODE_SEL_BORDER_COLOR ,
8- Z_VAL_NODE , Z_VAL_NODE_WIDGET )
8+ PORT_FALLOFF , Z_VAL_NODE , Z_VAL_NODE_WIDGET )
99from NodeGraphQt .errors import NodeWidgetError
1010from NodeGraphQt .qgraphics .node_abstract import AbstractNodeItem
1111from NodeGraphQt .qgraphics .port import PortItem
@@ -194,7 +194,7 @@ def paint(self, painter, option, widget):
194194
195195 def mousePressEvent (self , event ):
196196 if event .button () == QtCore .Qt .LeftButton :
197- start = PortItem ().boundingRect ().width ()
197+ start = PortItem ().boundingRect ().width () - PORT_FALLOFF
198198 end = self .boundingRect ().width () - start
199199 x_pos = event .pos ().x ()
200200 if not start <= x_pos <= end :
@@ -300,17 +300,19 @@ def calc_size(self, add_w=0.0, add_h=0.0):
300300 height = self ._text_item .boundingRect ().height ()
301301
302302 if self ._widgets :
303- width = max ([
303+ wid_width = max ([
304304 w .boundingRect ().width () for w in self ._widgets .values ()
305305 ])
306+ if width < wid_width :
307+ width = wid_width
306308
307309 port_height = 0.0
308310 if self ._input_items :
309311 input_widths = []
310312 for port , text in self ._input_items .items ():
311- input_width = port .boundingRect ().width ()
313+ input_width = port .boundingRect ().width () - PORT_FALLOFF
312314 if text .isVisible ():
313- input_width += text .boundingRect ().width ()
315+ input_width += text .boundingRect ().width () / 1.5
314316 input_widths .append (input_width )
315317 width += max (input_widths )
316318 port_height = port .boundingRect ().height ()
@@ -320,7 +322,7 @@ def calc_size(self, add_w=0.0, add_h=0.0):
320322 for port , text in self ._output_items .items ():
321323 output_width = port .boundingRect ().width ()
322324 if text .isVisible ():
323- output_width += text .boundingRect ().width ()
325+ output_width += text .boundingRect ().width () / 1.5
324326 output_widths .append (output_width )
325327 width += max (output_widths )
326328 port_height = port .boundingRect ().height ()
@@ -395,6 +397,8 @@ def arrange_ports(self, v_offset=0.0):
395397 v_offset (float): port vertical offset.
396398 """
397399 width = self ._width
400+ txt_offset = PORT_FALLOFF - 2
401+ spacing = 1
398402
399403 # adjust input position
400404 inputs = [p for p in self .inputs if p .isVisible ()]
@@ -405,11 +409,12 @@ def arrange_ports(self, v_offset=0.0):
405409 port_y = v_offset
406410 for port in inputs :
407411 port .setPos (port_x , port_y )
408- port_y += port_height
412+ port_y += port_height + spacing
409413 # adjust input text position
410414 for port , text in self ._input_items .items ():
411415 if port .isVisible ():
412- text .setPos (port .boundingRect ().width () / 2 , port .y () - 1.5 )
416+ txt_x = port .boundingRect ().width () / 2 - txt_offset
417+ text .setPos (txt_x , port .y () - 1.5 )
413418
414419 # adjust output position
415420 outputs = [p for p in self .outputs if p .isVisible ()]
@@ -420,14 +425,13 @@ def arrange_ports(self, v_offset=0.0):
420425 port_y = v_offset
421426 for port in outputs :
422427 port .setPos (port_x , port_y )
423- port_y += port_height
428+ port_y += port_height + spacing
424429 # adjust output text position
425430 for port , text in self ._output_items .items ():
426- if not port .isVisible ():
427- continue
428- txt_width = text .boundingRect ().width ()
429- txt_x = port .x () - txt_width
430- text .setPos (txt_x , port .y () - 1.5 )
431+ if port .isVisible ():
432+ txt_width = text .boundingRect ().width () - txt_offset
433+ txt_x = port .x () - txt_width
434+ text .setPos (txt_x , port .y () - 1.5 )
431435
432436 def offset_label (self , x = 0.0 , y = 0.0 ):
433437 """
@@ -441,14 +445,9 @@ def offset_label(self, x=0.0, y=0.0):
441445 icon_y = self ._text_item .pos ().y () + y
442446 self ._text_item .setPos (icon_x , icon_y )
443447
444- def post_init (self , viewer = None , pos = None ):
448+ def draw_node (self ):
445449 """
446- Called after node has been added into the scene.
447- Adjust the node layout and form after the node has been added.
448-
449- Args:
450- viewer (NodeGraphQt.widgets.viewer.NodeViewer): not used
451- pos (tuple): cursor position.
450+ Draw the node item in the scene.
452451 """
453452 height = self ._text_item .boundingRect ().height ()
454453
@@ -470,6 +469,17 @@ def post_init(self, viewer=None, pos=None):
470469 # arrange node widgets
471470 self .arrange_widgets (v_offset = height / 2 )
472471
472+ def post_init (self , viewer = None , pos = None ):
473+ """
474+ Called after node has been added into the scene.
475+ Adjust the node layout and form after the node has been added.
476+
477+ Args:
478+ viewer (NodeGraphQt.widgets.viewer.NodeViewer): not used
479+ pos (tuple): cursor position.
480+ """
481+ self .draw_node ()
482+
473483 # set initial node position.
474484 if pos :
475485 self .xy_pos = pos
@@ -522,7 +532,7 @@ def name(self, name=''):
522532 AbstractNodeItem .name .fset (self , name )
523533 self ._text_item .setPlainText (name )
524534 if self .scene ():
525- self .post_init ()
535+ self .draw_node ()
526536
527537 @AbstractNodeItem .color .setter
528538 def color (self , color = (100 , 100 , 100 , 255 )):
0 commit comments