
    eg                         d dgZ ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZmZmZ d
dlmZ ej                   j"                  Zd Z G d d ej&                        Z G d dej*                        Z G d de
      Zy)NodeNodeGraphicsItem    N)OrderedDict   )	functions)printExc)GraphicsObject)QtCoreQtGui	QtWidgets   )Terminalc           	      |    t        | j                         D cg c]  \  }}t        |      |f c}}      S c c}}w N)dictitemsstr)dkvs      :/usr/lib/python3/dist-packages/pyqtgraph/flowchart/Node.pystrDictr      s-    3A#a&!3443s   8
c                      e Zd ZdZ ej
                  e      Z ej
                  e      Z ej
                  ee      Z	 ej
                  ee      Z
 ej
                  ee      Z ej
                  ee      Zd)dZd Zd*dZd+dZd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d,dZ%d Z&d Z'd Z(d Z)d  Z*d! Z+d" Z,d# Z-d$ Z.d% Z/d& Z0d' Z1d( Z2y)-r   a  
    Node represents the basic processing unit of a flowchart. 
    A Node subclass implements at least:
    
    1) A list of input / output terminals and their properties
    2) a process() function which takes the names of input terminals as keyword arguments and returns a dict with the names of output terminals as keys.

    A flowchart thus consists of multiple instances of Node subclasses, each of which is connected
    to other by wires between their terminals. A flowchart is, itself, also a special subclass of Node.
    This allows Nodes within the flowchart to connect to the input/output nodes of the flowchart itself.

    Optionally, a node class can implement the ctrlWidget() method, which must return a QWidget (usually containing other widgets) that will be displayed in the flowchart control panel. Some nodes implement fairly complex control widgets, but most nodes follow a simple form-like pattern: a list of parameter names and a single value (represented as spin box, check box, etc..) for each parameter. To make this easier, the CtrlNode subclass allows you to instead define a simple data structure that CtrlNode will use to automatically generate the control widget.     Nc                 h   t         j                  j                  |        || _        d| _        d| _        d| _        t               | _        t               | _	        t               | _
        || _        || _        || _        d| _        |y|j                         D ]  \  }} | j                   |fi |  y)a  
        ==============  ============================================================
        **Arguments:**
        name            The name of this specific node instance. It can be any 
                        string, but must be unique within a flowchart. Usually,
                        we simply let the flowchart decide on a name when calling
                        Flowchart.addNode(...)
        terminals       Dict-of-dicts specifying the terminals present on this Node.
                        Terminal specifications look like::
                        
                            'inputTerminalName': {'io': 'in'}
                            'outputTerminalName': {'io': 'out'} 
                            
                        There are a number of optional parameters for terminals:
                        multi, pos, renamable, removable, multiable, bypass. See
                        the Terminal class for more information.
        allowAddInput   bool; whether the user is allowed to add inputs by the
                        context menu.
        allowAddOutput  bool; whether the user is allowed to add outputs by the
                        context menu.
        allowRemove     bool; whether the user is allowed to remove this node by the
                        context menu.
        ==============  ============================================================  
        
        FN)r
   QObject__init___name_bypassbypassButton_graphicsItemr   	terminals_inputs_outputs_allowAddInput_allowAddOutput_allowRemove	exceptionr   addTerminal)selfnamer!   allowAddInputallowAddOutputallowRemoveoptss          r   r   zNode.__init__'   s    4 	%
 !$"}#+-'#//+ 	+JD$DT*T*	+    c                 `    |}d}|| j                   v rd||fz  }|dz  }|| j                   v r|S )zReturn an unused terminal namer   z%s.%d)r!   )r)   r*   name2is       r   nextTerminalNamezNode.nextTerminalNameT   sD    t~~%tQi'EFA t~~% r/   c                 ,     | j                   |fddi|S )zAdd a new input terminal to this Node with the given name. Extra
        keyword arguments are passed to Terminal.__init__.
        
        This is a convenience function that just calls addTerminal(io='in', ...)ioinr(   r)   r*   argss      r   addInputzNode.addInput]   s!      t6666r/   c                 ,     | j                   |fddi|S )zAdd a new output terminal to this Node with the given name. Extra
        keyword arguments are passed to Terminal.__init__.
        
        This is a convenience function that just calls addTerminal(io='out', ...)r5   outr7   r8   s      r   	addOutputzNode.addOutpute   s!    
  t77$77r/   c                    t        |t              r|j                         }n|}| j                  |   }|j	                          | j                  |= || j
                  v r| j
                  |= || j                  v r| j                  |= | j                         j                          | j                  j                  | |       y)zRemove the specified terminal from this Node. May specify either the 
        terminal's name or the terminal itself.
        
        Causes sigTerminalRemoved to be emitted.N)
isinstancer   r*   r!   closer"   r#   graphicsItemupdateTerminalssigTerminalRemovedemit)r)   termr*   s      r   removeTerminalzNode.removeTerminall   s    
 dH%99;DD>>$'D 	

NN4 4<<T"4== d#++-$$T40r/   c                    |j                         }| j                  | j                  | j                  fD ]  }||vr||   ||<   ||=  | j	                         j                          | j                  j                  ||       y)zjCalled after a terminal has been renamed        
        
        Causes sigTerminalRenamed to be emitted.N)r*   r!   r"   r#   rA   rB   sigTerminalRenamedrD   )r)   rE   oldNamenewNamer   s        r   terminalRenamedzNode.terminalRenamed   s}     ))+..$,,> 	Aa7AgJ'
		 	++-$$T73r/   c                 R   | j                  |      }t        | |fi |}|| j                  |<   |j                         r|| j                  |<   n|j                         r|| j                  |<   | j                         j                          | j                  j                  | |       |S )zAdd a new terminal to this Node with the given name. Extra
        keyword arguments are passed to Terminal.__init__.
                
        Causes sigTerminalAdded to be emitted.)r3   r   r!   isInputr"   isOutputr#   rA   rB   sigTerminalAddedrD   )r)   r*   r.   rE   s       r   r(   zNode.addTerminal   s    
 $$T*d+d+#t<<>!%DLL]]_"&DMM$++-""4.r/   c                     | j                   S )zCReturn dict of all input terminals.
        Warning: do not modify.)r"   r)   s    r   inputszNode.inputs   s     ||r/   c                     | j                   S )zDReturn dict of all output terminals.
        Warning: do not modify.)r#   rQ   s    r   outputszNode.outputs   s     }}r/   c                     i S )a_  Process data through this node. This method is called any time the flowchart 
        wants the node to process data. It will be called with one keyword argument
        corresponding to each input terminal, and must return a dict mapping the name
        of each output terminal to its new value.
        
        This method is also called with a 'display' keyword argument, which indicates
        whether the node should update its display (if it implements any) while processing
        this data. This is primarily used to disable expensive display operations
        during batch processing.
         )r)   kargss     r   processzNode.process   s	     	r/   c                 R    | j                   t        |       | _         | j                   S )zReturn the GraphicsItem for this node. Subclasses may re-implement
        this method to customize their appearance in the flowchart.)r    r   rQ   s    r   rA   zNode.graphicsItem   s)     %!1$!7D!!!r/   c                 R    || j                   vrt        |      | j                   |   S )z'Return the terminal with the given name)r!   KeyError)r)   items     r   __getitem__zNode.__getitem__   s)     t~~%4. >>$''r/   c                     | j                   S )zReturn the name of this node.)r   rQ   s    r   r*   z	Node.name   s    zzr/   c                 b    | j                   }|| _         | j                  j                  | |       y)z;Rename this node. This will cause sigRenamed to be emitted.N)r   
sigRenamedrD   )r)   r*   rI   s      r   renamezNode.rename   s&    **
T7+r/   c           	          t               }| j                         j                         D ]:  }|t        |j                         D cg c]  }|j	                          c}      z  }< |S c c}w )z@Return the list of nodes which provide direct input to this node)setrR   valuesinputTerminalsnode)r)   nodestr2   s       r   dependentNodeszNode.dependentNodes   s]    %%' 	AASA,<,<,>?q!&&(?@@E	A @s   A(c                 >    d| j                         t        |       fz  S )Nz<Node %s @%x>)r*   idrQ   s    r   __repr__zNode.__repr__   s    $))+r$x!888r/   c                      y)a  Return this Node's control widget. 
        
        By default, Nodes have no control widget. Subclasses may reimplement this 
        method to provide a custom widget. This method is called by Flowcharts
        when they are constructing their Node list.NrV   rQ   s    r   
ctrlWidgetzNode.ctrlWidget   s     r/   c                     || _         | j                  | j                  j                  |       | j                          y)a  Set whether this node should be bypassed.
        
        When bypassed, a Node's process() method is never called. In some cases,
        data is automatically copied directly from specific input nodes to 
        output nodes instead (see the bypass argument to Terminal.__init__). 
        This is usually called when the user disables a node from the flowchart 
        control panel.
        N)r   r   
setCheckedupdate)r)   byps     r   bypasszNode.bypass   s4     (((-r/   c                     | j                   S )z/Return True if this Node is currently bypassed.)r   rQ   s    r   
isBypassedzNode.isBypassed   s    ||r/   c                     d}|j                         D ]O  \  }}| j                  |   }|j                         }t        j                  ||      sd}|j                  |d       Q |rd|vr| j                          yyy)zSet the values on input terminals. For most nodes, this will happen automatically through Terminal.inputChanged.
        This is normally only used for nodes with no connected inputs.FT)rX   _updatesHandled_N)r   r"   valuefneqsetValuerq   )r)   r9   changedr   r   rE   oldVals          r   setInputzNode.setInput   sz     JJL 	,DAq<<?DZZ\F55#MM!UM+	, )5KKM 67r/   c                 |    i }| j                         j                         D ]  \  }}|j                         ||<    |S )zBReturn a dict of all input values currently assigned to this node.)rR   r   rx   r)   valsnrh   s       r   inputValueszNode.inputValues  s=    KKM'') 	 DAqggiDG	 r/   c                 |    i }| j                         j                         D ]  \  }}|j                         ||<    |S )zDReturn a dict of all output values currently generated by this node.)rT   r   rx   r   s       r   outputValueszNode.outputValues  s=    LLN((* 	 DAqggiDG	 r/   c                      y)zDCalled whenever one of this node's terminals is connected elsewhere.NrV   r)   	localTerm
remoteTerms      r   	connectedzNode.connected      r/   c                      y)zJCalled whenever one of this node's terminals is disconnected from another.NrV   r   s      r   disconnectedzNode.disconnected  r   r/   c                    | j                         }	 | j                         r| j                  |      }n | j                  di t	        |      }|'|r | j
                  di | n | j                  di | | j                         j                         D ]  \  }}|j                  d        | j                          y#  | j                         j                         D ]  \  }}|j                  d        | j                  t        j                                |r| j                   j#                  |        Y yY yxY w)aM  Collect all input values, attempt to process new output values, and propagate downstream.
        Subclasses should call update() whenever thir internal state has changed
        (such as when the user interacts with the Node's control widget). Update
        is automatically called when the inputs to the node are changed.
        NTrV   )r   ru   processBypassedrX   r   	setOutputsetOutputNoSignalrR   r   setValueAcceptableclearExceptionrT   r{   setExceptionsysexc_infosigOutputChangedrD   )r)   signalr   r<   r   rh   s         r   rq   zNode.update  s    !	1 **40"dll3WT]3"DNN)S)*D**1S1{{}**, +!$$T*+!	1||~++- !!

4 !clln-%%**40 s   B-C   A9D=c                     i }t        | j                         j                               D ]K  }|j                         }|d||j	                         <   )|j                  |d      ||j	                         <   M |S )a&  Called when the flowchart would normally call Node.process, but this node is currently bypassed.
        The default implementation looks for output terminals with a bypass connection and returns the
        corresponding values. Most Node subclasses will _not_ need to reimplement this method.N)listrT   rd   bypassValuer*   get)r)   r9   resultrE   rr   s        r   r   zNode.processBypassed<  sq     ..01 	:D""$C{&*tyy{#&*hhsD&9tyy{#	: r/   c                 ^     | j                   di | | j                  j                  |        y )NrV   )r   r   rD   )r)   r   s     r   r   zNode.setOutputI  s)    &&""4(r/   c                     |j                         D ]:  \  }}| j                         |   }|j                  |       |j                  d       < y NT)r   rT   r{   r   )r)   r   r   r   rE   s        r   r   zNode.setOutputNoSignalN  sG    JJL 	*DAq<<>!$DMM! ##D)	*r/   c                 2    || _         | j                          y r   )r'   recolor)r)   excs     r   r   zNode.setExceptionY  s    r/   c                 &    | j                  d        y r   )r   rQ   s    r   r   zNode.clearException]  s    $r/   c           	      <   | j                   H| j                         j                  t        j                  t        j
                  ddd                   y | j                         j                  t        j                  t        j
                  ddd      d             y )Nr         )r'   rA   setPenr   QPenQColorrQ   s    r   r   zNode.recolor`  sh    >>!&&uzz%,,q!Q2G'HI&&uzz%,,sAq2I1'MNr/   c                    | j                         j                         }|j                         |j                         f| j	                         d}| j
                  | j                  z  }t        | j                  j                               t        | j                  j                               z   D ]+  }||j                  |j                  z  |j                  z  z  }- |r| j                         |d<   |S )a  Return a dictionary representing the current state of this node
        (excluding input / output values). This is used for saving/reloading
        flowcharts. The default implementation returns this Node's position,
        bypass state, and information about each of its terminals. 
        
        Subclasses may want to extend this method, adding extra keys to the returned
        dict.)posrs   r!   )rA   r   xyru   r$   r%   r   r"   rd   r#   
_renamable
_removable
_multiablesaveTerminals)r)   r   statetermsEditablerE   s        r   	saveStatezNode.saveStatef  s     !%%'#%%'*doo6GH++d.B.BB,,./$t}}7K7K7M2NN 	QDT__t>PPM	Q!%!3!3!5E+r/   c                     |j                  dd      } | j                         j                  |  | j                  |j                  dd             d|v r| j	                  |d          yy)z]Restore the state of this node from a structure previously generated
        by saveState(). r   )r   r   rs   Fr!   N)r   rA   setPosrs   restoreTerminals)r)   r   r   s      r   restoreStatezNode.restoreStatew  sd     iiu%"""C(EIIh./%!!%"45  r/   c                     t               }| j                  j                         D ]  \  }}|j                         ||<    |S r   )r   r!   r   r   )r)   termsr   rh   s       r   r   zNode.saveTerminals  s=    NN((* 	'DAqE!H	'r/   c           
         t        | j                  j                               D ]  }||vs| j                  |        |j	                         D ]J  \  }}|| j                  v r| |   } |j
                  di | ,	 t        |      } | j                  |fi | L y #  t        dt        |      dt        |      d       Y vxY w)NzError restoring terminal z (z):rV   )
r   r!   keysrF   r   setOptsr   r(   r   r   )r)   r   r*   r.   rE   s        r   r   zNode.restoreTerminals  s    ,,./ 	*D5 ##D)	*  ++- 		WJD$t~~%Dz$t$Wt}   ..		WWD	3t9UVs   <B&Cc                     | j                   j                         D ]  }|j                           t               | _         t               | _        t               | _        y r   )r!   rd   r@   r   r"   r#   r)   rh   s     r   clearTerminalszNode.clearTerminals  sB    &&( 	AGGI	$"}#r/   c                 L   | j                          | j                          | j                         }|j                         |j                         j	                  |       d| _        | j                         }||j                  d       | j                  j                  |        y)zACleans up after the node--removes terminals, graphicsItem, widgetN)
disconnectAllr   rA   scene
removeItemr    rn   	setParent	sigClosedrD   )r)   r\   ws      r   r@   z
Node.close  s      "::<#JJL##D)!OO=KKD!r/   c                 b    | j                   j                         D ]  }|j                           y r   )r!   rd   r   r   s     r   r   zNode.disconnectAll  s(    &&( 	AOO	r/   )NFFT)Input)Output)T)3__name__
__module____qualname____doc__r
   Signalobjectr   r   r`   rH   rO   rC   r   r3   r:   r=   rF   rK   r(   rR   rT   rX   rA   r]   r*   ra   ri   rl   rn   rs   ru   r~   r   r   r   r   rq   r   r   r   r   r   r   r   r   r   r   r   r@   r   rV   r/   r   r   r      s8   { %v}}V,f%Ivv.J&vv6$v}}VV4&vv6*+Z781.4"

"(,91@)
	* O"6W &"r/   c                   8     e Zd Z fdZ fdZ fdZd Z xZS )TextItemc                 4    t         |   ||       || _        y r   )superr   	on_update)r)   textparentr   	__class__s       r   r   zTextItem.__init__  s    v&"r/   c                 ^    t         |   |       | j                  | j                          y y r   )r   focusOutEventr   r)   evr   s     r   r   zTextItem.focusOutEvent  s)    b!>>%NN &r/   c                 2   |j                         t        j                  j                  j                  k(  s5|j                         t        j                  j                  j
                  k(  r| j                  | j                          y t        | !  |       y r   )	keyr
   QtKey	Key_Enter
Key_Returnr   r   keyPressEventr   s     r   r   zTextItem.keyPressEvent  s^    668vyy}}..."&&(fiimm>V>V2V~~) b!r/   c                    |j                         t        j                  j                  j                  k(  rg| j                  t        j                  j                  j                         | j                  t        j                  j                  j                         y |j                         t        j                  j                  j                  k(  r4| j                  t        j                  j                  j                         y y r   )buttonr
   r   MouseButton
LeftButtonsetTextInteractionFlagsTextInteractionFlagTextEditorInteractionsetFocusFocusReasonMouseFocusReasonRightButtonNoTextInteractionr)   r   s     r   mousePressEventzTextItem.mousePressEvent  s    99;&))//:::(()F)F)\)\]MM&))//@@AYY[FII11===(()F)F)X)XY >r/   )r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r     s    #
"Zr/   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)r   c                 v   t        j                  |        t        j                  ddd      | _        t        j                  dddd      | _        t        j                  dddd      | _        t        j                  dddd      | _        t        j                  dddd      | _	        d| _
        || _        | j                  j                  | j                  j                  z  | j                  j                  z  | j                  j                   z  }| j#                  |       t%        j&                  dddd      | _        t+        | j                  j-                         | | j.                        | _        | j0                  j3                  t5        j6                  d	d	d	             | j0                  j9                  | j(                  j;                         d
z  | j0                  j=                         j;                         d
z  z
  d       d| _        d| _         | jC                          d | _"        | jG                          y )Nr      r   )widthr      Fd   2          @      )$r	   r   ry   mkPenpen	selectPenmkBrushbrush
hoverBrushselectBrushhoveredrf   GraphicsItemFlagItemIsMovableItemIsSelectableItemIsFocusableItemSendsGeometryChangessetFlagsr
   QRectFboundsr   r*   labelChangednameItemsetDefaultTextColorr   r   moveByr   boundingRect_titleOffset_nodeOffsetrB   menu	buildMenu)r)   rf   flagss      r   r   zNodeGraphicsItem.__init__  s   % 88Aa?#c#A6ZZS#s3
**S#sC8::c3S9	%%33d6K6K6\6\\_c_t_t  `E  `E  E  HL  H]  H]  Hv  Hv  v 	emmAq#s3 !149J9JK))%,,r2r*BCT[[..03dmm6P6P6R6X6X6Z[]6]]_`a 	r/   c                 2    || _         | j                          y)a  
        This method sets the rendering offset introduced after the title of the node.
        This method automatically updates the terminal labels. The default for this value is 25px.

        :param new_offset: The new offset to use in pixels at 100% scale.
        N)r  rB   r)   
new_offsets     r   setTitleOffsetzNodeGraphicsItem.setTitleOffset  s     'r/   c                     | j                   S )zk
        This method returns the current title offset in use.

        :returns: The offset in px.
        )r  rQ   s    r   titleOffsetzNodeGraphicsItem.titleOffset  s        r/   c                 2    || _         | j                          y)a  
        This method sets the rendering offset introduced after every terminal of the node.
        This method automatically updates the terminal labels. The default for this value is 12px.

        :param new_offset: The new offset to use in pixels at 100% scale.
        N)r  rB   r  s     r   setTerminalOffsetz"NodeGraphicsItem.setTerminalOffset  s     &r/   c                     | j                   S )zn
        This method returns the current terminal offset in use.

        :returns: The offset in px.
        )r  rQ   s    r   terminalOffsetzNodeGraphicsItem.terminalOffset	  s     r/   c                 z   | j                   j                         }|| j                  j                         k7  r| j                  j	                  |       | j                         }| j                   j                  |j                         dz  | j                   j                         j                         dz  z
  d       y )Nr   r   )r  toPlainTextrf   r*   ra   r  r   r   )r)   rJ   r  s      r   r  zNodeGraphicsItem.labelChanged  s    --++-diinn&&IIW% ""$V\\^B.1K1K1M1S1S1UVX1XXZ[\r/   c                 X    t        j                  |i || _        | j                          y r   )ry   r   r   rq   )r)   r9   kwargss      r   r   zNodeGraphicsItem.setPen!  s     88T,V,r/   c                 2    || _         | j                          y r   )r  rq   )r)   r  s     r   setBrushzNodeGraphicsItem.setBrush%  s    
r/   c                    i | _         | j                  j                         }| j                  j                         }t	        t        |      t        |            }| j                  || j                  z  z   }| j                  j                         |k(  s+| j                  j                  |       | j                          | j                  }|j                         D ]X  \  }}|j                         }|j                  |        |j                  d|       ||f| j                   |<   || j                  z  }Z | j                  }|j                         D ]  \  }}|j                         }|j                  |        |j!                  | j#                                |j                  | j                  j%                         |       ||f| j                   |<   || j                  z  } y )Nr   )r!   rf   rR   rT   maxlenr  r  r  height	setHeightrq   r   rA   setParentItem	setAnchor	setZValuezValuer   )	r)   inpr<   maxNode	newHeightr   r2   rh   r\   s	            r   rB   z NodeGraphicsItem.updateTerminals*  s   ii ii!c#hC) %%0@0@(@@	 {{!!#y0KK!!),KKM IIK 	"DAq>>#Dt$NN1a !"D	DNN1!!!A	" IIK 	"DAq>>#Dt$NN4;;=)NN4;;,,.2!"D	DNN1!!!A	"r/   c                 >    | j                   j                  dddd      S )N   )r  adjustedrQ   s    r   r  zNodeGraphicsItem.boundingRectP  s    {{##BAq11r/   c                    |j                  | j                         | j                         r7|j                  | j                         |j	                  | j
                         n^|j                  | j                         | j                  r|j	                  | j                         n|j	                  | j                         |j                  | j                         y r   )r   r   
isSelectedr   r'  r  r  r  r  drawRectr  )r)   pr9   s      r   paintzNodeGraphicsItem.paintS  s    	??HHT^^$JJt''(HHTXX||

4??+

4::&	

4;;r/   c                 $    |j                          y r   )ignorer   s     r   r   z NodeGraphicsItem.mousePressEventc  s    
		r/   c                    |j                         t        j                  j                  j                  k(  rV|j                          | j                         }| j                  d       |s"| j                         r| j                          y y y |j                         t        j                  j                  j                  k(  r"|j                          | j                  |       y y r   )r   r
   r   r   r   acceptr9  setSelectedrq   r   raiseContextMenu)r)   r   sels      r   mouseClickEventz NodeGraphicsItem.mouseClickEventg  s    99;&))//:::IIK//#CT"4??, -3 YY[FII11===IIK!!"% >r/   c                 N   |j                         t        j                  j                  j                  k(  rp|j                          | j                  | j                         | j                  |j                               z   | j                  |j                               z
         y y r   )
r   r
   r   r   r   r@  r   r   mapToParentlastPosr   s     r   mouseDragEventzNodeGraphicsItem.mouseDragEvents  sl    99;&))//:::IIKKK
4#3#3BFFH#==d>N>Nrzz|>\\] ;r/   c                 .   |j                         sn|j                  t        j                  j                  j
                        r;|j                  t        j                  j                  j
                         d| _        nd| _        | j                          y )NTF)	isExitacceptClicksr
   r   r   r   acceptDragsr  rq   r   s     r   
hoverEventzNodeGraphicsItem.hoverEventx  sY    yy{rvyy/D/D/O/OPNN69900;;<DL DLr/   c                 |   |j                         t        j                  j                  j                  k(  s5|j                         t        j                  j                  j
                  k(  rB|j                          | j                  j                  sy | j                  j                          y |j                          y r   )r   r
   r   r   
Key_DeleteKey_Backspacer@  rf   r&   r@   r>  r   s     r   r   zNodeGraphicsItem.keyPressEvent  si    668vyy}}///2668vyy}}?Z?Z3ZIIK99))IIOOIIKr/   c                     || j                   j                  k(  r5| j                  j                         D ]  \  }}|d   j	                           t        j                  | ||      S )Nr   )GraphicsItemChangeItemPositionHasChangedr!   r   	nodeMovedr	   
itemChange)r)   changevalr   rh   s        r   rU  zNodeGraphicsItem.itemChange  sY    T,,CCC,,. !1! !((vs;;r/   c                     | j                   S r   )r  rQ   s    r   getMenuzNodeGraphicsItem.getMenu  s    yyr/   c           	      (   | j                         j                  | | j                         |      }|j                         }|j	                  t        j                  t        |j                               t        |j                                            y r   )
r   addParentContextMenusrY  	screenPospopupr
   QPointintr   r   )r)   r   r  r   s       r   rB  z!NodeGraphicsItem.raiseContextMenu  sX    zz|11$Klln

6==SUUWs3557|<=r/   c                    t        j                         | _        | j                  j                  t	        dd             | j                  j                  t	        dd      | j                        }| j                  j                  s|j                  d       | j                  j                  t	        dd      | j                        }| j                  j                  s|j                  d       | j                  j                  t	        dd      | j                  j                        }| j                  j                  s|j                  d       y y )NzContext Menur   z	Add inputFz
Add outputzRemove node)r   QMenur  setTitle	translate	addActionaddInputFromMenurf   r$   
setEnabledaddOutputFromMenur%   r@   r&   )r)   as     r   r  zNodeGraphicsItem.buildMenu  s    OO%			9^V<=II	. EtG\G\]yy''LLII	., GI_I_`yy((LLII	.- H$))//Zyy%%LL &r/   c                 @    | j                   j                  ddd       y )NT	renamable	removable	multiable)rf   r:   rQ   s    r   re  z!NodeGraphicsItem.addInputFromMenu  s    		TTTJr/   c                 @    | j                   j                  ddd       y )NTFrj  )rf   r=   rQ   s    r   rg  z"NodeGraphicsItem.addOutputFromMenu  s    		ddeLr/   N)r   r   r   r   r  r  r  r!  r  r   r'  rB   r  r<  r   rD  rH  rM  r   rU  rY  rB  r  re  rg  rV   r/   r   r   r     sv     D! ]
!"L2  
&^
<>
 KMr/   )__all__r   collectionsr    r   ry   debugr   graphicsItems.GraphicsObjectr	   r   r
   r   r   r   QCoreApplicationrc  r   r   r   QGraphicsTextItemr   r   rV   r/   r   <module>rv     su   %
& 
 #   9 ) ) ##--	5\6>> \~Zy** Z4^M~ ^Mr/   