;igddgZddlZddlmZddlmZddlmZddl m Z dd l m Z m Z mZd d lmZe jjZd ZGd de jZGddejZGdde ZdS)NodeNodeGraphicsItemN) OrderedDict) functions)printExc)GraphicsObject)QtCoreQtGui QtWidgets)TerminalcXtd|DS)Nc6g|]\}}t||fS)str).0kvs LC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/flowchart/Node.py zstrDict..s&333A#a&&!333)dictitems)ds rstrDictrs' 33333 4 44rceZdZdZejeZejeZejeeZ ejeeZ ejeeZ ejeeZ d-dZ dZd.dZd/d Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d0dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2dS)1ra 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. NFTc~tj|||_d|_d|_d|_t|_t|_ t|_ ||_ ||_ ||_ d|_|dS|D]\}}|j|fi|dS)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)selfnamer% allowAddInputallowAddOutput allowRemoveoptss rr z Node.__init__'s4 %%%   !$"}} #  +-'   F#//++ + +JD$ D T * *T * * * * + +rcJ|}d}||jvrd||fz}|dz }||jv|S)zReturn an unused terminal namer z%s.%d)r%)r-r.name2is rnextTerminalNamezNode.nextTerminalNameTsF t~%%tQi'E FAt~%% rInputc "|j|fddi|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', ...)ioinr,r-r.argss raddInputz Node.addInput]s$  t666666rOutputc "|j|fddi|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', ...)r9outr;r<s r addOutputzNode.addOutputes$  t777$777rcvt|tr|}n|}|j|}||j|=||jvr|j|=||jvr|j|=||j ||dS)zRemove the specified terminal from this Node. May specify either the terminal's name or the terminal itself. Causes sigTerminalRemoved to be emitted.N) isinstancerr.r%closer&r' graphicsItemupdateTerminalssigTerminalRemovedemit)r-termr.s rremoveTerminalzNode.removeTerminalls dH % % (99;;DDD>$'D N4 4<   T" 4=  d# ++--- $$T400000rc|}|j|j|jfD]}||vr||||<||=||j||dS)zjCalled after a terminal has been renamed Causes sigTerminalRenamed to be emitted.N)r.r%r&r'rFrGsigTerminalRenamedrI)r-rJoldNamenewNamers rterminalRenamedzNode.terminalRenameds))++.$, >  Aa7AgJ'  ++--- $$T733333rc \||}t||fi|}||j|<|r ||j|<n|r ||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.) r6rr%isInputr&isOutputr'rFrGsigTerminalAddedrI)r-r.r2rJs rr,zNode.addTerminals $$T**d++d++#t <<>> '!%DL   ]]__ '"&DM$  ++--- ""4... rc|jS)zCReturn dict of all input terminals. Warning: do not modify.)r&r-s rinputsz Node.inputss |rc|jS)zDReturn dict of all output terminals. Warning: do not modify.)r'rVs routputsz Node.outputss }rc iS)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)r-kargss rprocessz Node.processs  rcF|jt||_|jS)zReturn the GraphicsItem for this node. Subclasses may re-implement this method to customize their appearance in the flowchart.)r$rrVs rrFzNode.graphicsItems&   %!1$!7!7D !!rcL||jvrt||j|S)z'Return the terminal with the given name)r%KeyError)r-items r __getitem__zNode.__getitem__s* t~ % %4.. >$' 'rc|jS)zReturn the name of this node.)r!rVs rr.z Node.names zrcX|j}||_|j||dS)z;Rename this node. This will cause sigRenamed to be emitted.N)r! sigRenamedrI)r-r.rNs rrenamez Node.renames.*  T7+++++rct}|D]0}|td|Dz}1|S)z@Return the list of nodes which provide direct input to this nodec6g|]}|Sr)node)rr5s rrz'Node.dependentNodes..s ???q!&&((???r)setrWvaluesinputTerminals)r-nodests rdependentNodeszNode.dependentNodessd%%'' A AA S??A,<,<,>,>???@@ @EE rcNd|t|fzS)Nz )r.idrVs r__repr__z Node.__repr__s $))++r$xx!888rcdS)aReturn 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.NrrVs r ctrlWidgetzNode.ctrlWidgets trc~||_|j|j||dS)aSet 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# setCheckedupdate)r-byps rbypassz Node.bypasss<   (   ( ( - - - rc|jS)z/Return True if this Node is currently bypassed.)r"rVs r isBypassedzNode.isBypasseds |rc d}|D]T\}}|j|}|}tj||sd}||dU|rd|vr|dSdSdS)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)r\_updatesHandled_N)rr&valuefneqsetValuerv)r-r=changedrrrJoldVals rsetInputz Node.setInputsJJLL , ,DAq<?DZZ\\F5##  MM!UM + + + +  )55 KKMMMMM  55rci}|D]\}}|||<|S)zBReturn a dict of all input values currently assigned to this node.)rWrr}r-valsnrms r inputValueszNode.inputValuessFKKMM''))  DAqggiiDGG rci}|D]\}}|||<|S)zDReturn a dict of all output values currently generated by this node.)rYrr}rs r outputValueszNode.outputValues sFLLNN((**  DAqggiiDGG rcdS)zDCalled whenever one of this node's terminals is connected elsewhere.Nrr- localTerm remoteTerms r connectedzNode.connected rcdS)zJCalled whenever one of this node's terminals is disconnected from another.Nrrs r disconnectedzNode.disconnectedrrc|} |r||}n|jdit |}||r|jdi|n |jdi||D]\}}| d| dS#| D]\}}| d| tj|r|j|YdSYdSxYw)aMCollect 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. NTr)rrzprocessBypassedr\r setOutputsetOutputNoSignalrWrsetValueAcceptableclearExceptionrYr setExceptionsysexc_infosigOutputChangedrI)r-signalrrArrms rrvz Node.updates !! 1   4**400"dl33WT]]332"DN))S))))*D*11S111{{}}**,, + +!$$T****    ! ! ! ! ! 1||~~++-- ! !! 4      clnn - - - 1%**4000000 1 1 1s B8CBEc(i}t|D][}|}|d||<0||d||<\|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)listrYrj bypassValuer.get)r-r=resultrJrws rrzNode.processBypassed<s..0011 : :D""$$C{&*tyy{{##&*hhsD&9&9tyy{{## rc T|jdi||j|dS)Nr)rrrI)r-rs rrzNode.setOutputIs8&&&&& ""4(((((rc |D]I\}}||}|||dJdSNT)rrYrr)r-rrrrJs rrzNode.setOutputNoSignalNsdJJLL * *DAq<<>>!$D MM!     # #D ) ) ) ) * *rc<||_|dSN)r+recolor)r-excs rrzNode.setExceptionYs rc0|ddSr)rrVs rrzNode.clearException]s $rc N|jO|tjtjddddS|tjtjdddddS)Nr)r+rFsetPenr QPenQColorrVs rrz Node.recolor`s > !      & &uz%,q!Q2G2G'H'H I I I I I      & &uz%,sAq2I2I1'M'M N N N N Nrc|}||f|d}|j|jz}t|j t|j zD]}||j |j z|j zz}|r||d<|S)aReturn 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.)posrxr%)rFrxyrzr(r)rr&rjr' _renamable _removable _multiable saveTerminals)r-rstate termsEditablerJs r saveStatezNode.saveStatefs!!%%''#%%''*doo6G6GHH+d.BB ,,..//$t}7K7K7M7M2N2NN Q QD T_t>P PMM  6!%!3!3!5!5E+  rc|dd}|j|||ddd|vr||ddSdS)z]Restore the state of this node from a structure previously generated by saveState(). r)rrrxFr%N)rrFsetPosrxrestoreTerminals)r-rrs r restoreStatezNode.restoreStatewsiiu%%""C(( EIIh../// %    ! !% "4 5 5 5 5 5 rct}|jD]\}}|||<|Sr)rr%rr)r-termsrrms rrzNode.saveTerminalssD N((** ' 'DAq E!HH rc t|jD]}||vr|||D]y\}}||jvr||}|jdi|$ t |}|j|fi|C#tdt|dt|dYwxYwdS)NzError restoring terminal z (z):r) rr%keysrKrsetOptsrr,rr)r-rr.r2rJs rrzNode.restoreTerminalss ,,..// * *D5  ##D)))++-- W WJD$t~%%Dz $$t$$$ Wt}}  ...... WD 3t9999UVVVVV W Ws <B2Cc|jD]}|t|_t|_t|_dSr)r%rjrErr&r'r-rms rclearTerminalszNode.clearTerminalssS&&((  A GGIIII$"}} #  rc|||}|'||d|_|}||d|j |dS)zACleans up after the node--removes terminals, graphicsItem, widgetN) disconnectAllrrFscene removeItemr$rs setParent sigClosedrI)r-r`ws rrEz Node.closes    "" ::<< # JJLL # #D ) ) )! OO   = KK    D!!!!!rcf|jD]}|dSr)r%rjrrs rrzNode.disconnectAlls<&&((  A OO      r)NFFT)r7)r?)T)3__name__ __module__ __qualname____doc__r SignalobjectrrrdrMrTrHr r6r>rBrKrPr,rWrYr\rFrar.rernrqrsrxrzrrrrrrvrrrrrrrrrrrrErrrrrrs { {%v}V,, f%%Ivv..J&vv66$v}VV44&vv66*+*+*+*+Z77778888111. 4 4 4"    """(((,,,999            1111@   ))) * * *   OOO "666 W W W &&& " " "rc8eZdZfdZfdZfdZdZxZS)TextItemcZt||||_dSr)superr on_update)r-textparentr __class__s rr zTextItem.__init__s( v&&&"rct||j|dSdSr)r focusOutEventrr-evrs rrzTextItem.focusOutEventsA b!!! > % NN      & %rc4|tjjjks,|tjjjkr|j|dSt|dSr) keyr QtKey Key_Enter Key_Returnrr keyPressEventrs rrzTextItem.keyPressEventsq 6688vy}. . ."&&((fim>V2V2V~)    b!!!!!rc|tjjjkrT|tjjj|tjj j dS|tjjj kr+|tjjj dSdSr) buttonr r MouseButton LeftButtonsetTextInteractionFlagsTextInteractionFlagTextEditorInteractionsetFocus FocusReasonMouseFocusReason RightButtonNoTextInteractionr-rs rmousePressEventzTextItem.mousePressEvents 99;;&)/: : :  ( ()F)\ ] ] ] MM&)/@ A A A A A YY[[FI1= = =  ( ()F)X Y Y Y Y Y> =r)rrrr rrr __classcell__)rs@rrrs##### """""ZZZZZZZrrceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdS)rc,tj|tjddd|_tjdddd|_tjdddd|_tjdddd|_tjdddd|_ d|_ ||_ |j j |j jz|j jz|j jz}||t%jdddd|_t+|j ||j|_|jt5jd d d |j|jd z |jd z z dd |_d |_ |!d|_"|#dS) Nrr)widthrFd2@ )$r r r~mkPenpen selectPenmkBrushbrush hoverBrush selectBrushhoveredrhGraphicsItemFlag ItemIsMovableItemIsSelectableItemIsFocusableItemSendsGeometryChangessetFlagsr QRectFboundsrr. labelChangednameItemsetDefaultTextColorr rmoveByr boundingRect _titleOffset _nodeOffsetrGmenu buildMenu)r-rhflagss rr zNodeGraphicsItem.__init__s%%%8Aa??#c#A666ZS#s33 *S#sC88:c3S99  %3d6K6\\_c_t`EEHLH]Hvv emAq#s33  !1!149JKK  ))%,r2r*B*BCCC T[..003dm6P6P6R6R6X6X6Z6Z[]6]]_`aaa   rc<||_|dS)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)rrGr- new_offsets rsetTitleOffsetzNodeGraphicsItem.setTitleOffsets$' rc|jS)zk This method returns the current title offset in use. :returns: The offset in px. )rrVs r titleOffsetzNodeGraphicsItem.titleOffsets   rc<||_|dS)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)rrGrs rsetTerminalOffsetz"NodeGraphicsItem.setTerminalOffsets$& rc|jS)zn This method returns the current terminal offset in use. :returns: The offset in px. )rrVs rterminalOffsetzNodeGraphicsItem.terminalOffset s rc|j}||jkr|j||}|j|dz |jdz z ddS)Nrr)r toPlainTextrhr.rerrr)r-rOrs rrzNodeGraphicsItem.labelChangeds-++-- dinn&& & & I  W % % %""$$ V\\^^B.1K1K1M1M1S1S1U1UVX1XXZ[\\\\\rcZtj|i||_|dSr)r~rrrv)r-r=kwargss rrzNodeGraphicsItem.setPen!s)8T,V,, rc<||_|dSr)rrv)r-rs rsetBrushzNodeGraphicsItem.setBrush%s  rci|_|j}|j}t t |t |}|j||jzz}|j |ks.|j || |j}| D]Z\}}| }|||d|||f|j|<||jz }[|j}| D]\}}| }||||||j|||f|j|<||jz }dS)Nr)r%rhrWrYmaxlenrrrheight setHeightrvrrF setParentItem setAnchor setZValuezValuer) r-inprAmaxNode newHeightrr5rmr`s rrGz NodeGraphicsItem.updateTerminals*si  i!!c#hhC))%0@(@@ {!!##y00 K ! !) , , , KKMMM  IIKK " "DAq>>##D   t $ $ $ NN1a !"D DN1  ! !AA  IIKK " "DAq>>##D   t $ $ $ NN4;;== ) ) ) NN4;,,.. 2 2 2!"D DN1  ! !AA  " "rc<|jddddS)N)radjustedrVs rrzNodeGraphicsItem.boundingRectPs{##BAq111rc||j|r5||j||jnV||j|jr||jn||j| |j dSr) rr isSelectedrr+rr rrdrawRectr)r-pr=s rpaintzNodeGraphicsItem.paintSs  ??   ' HHT^ $ $ $ JJt' ( ( ( ( HHTX   | ' 4?++++ 4:&&& 4;rc.|dSr)ignorers rrz NodeGraphicsItem.mousePressEventcs rc|tjjjkrm||}|d|s*|r|dSdSdS|tjjj kr+|| |dSdSr) rr rrracceptr= setSelectedrvrraiseContextMenu)r-rsels rmouseClickEventz NodeGraphicsItem.mouseClickEventgs 99;;&)/: : : IIKKK//##C   T " " " 4??,,      YY[[FI1= = = IIKKK  ! !" % % % % %> =rcx|tjjjkr|||||z|| z dSdSr) rr rrrrDrr mapToParentlastPosrs rmouseDragEventzNodeGraphicsItem.mouseDragEventss 99;;&)/: : : IIKKK KK 4#3#3BFFHH#=#==d>N>Nrzz||>\>\\ ] ] ] ] ] ; :rc|sZ|tjjjr1|tjjjd|_nd|_|dS)NTF) isExit acceptClicksr rrr acceptDragsr rvrs r hoverEventzNodeGraphicsItem.hoverEventxshyy{{ !rvy/D/OPP ! NN690; < < <DLL DL rcX|tjjjks,|tjjjkr=||jjsdS|j dS| dSr) rr rr Key_Delete Key_BackspacerDrhr*rErBrs rrzNodeGraphicsItem.keyPressEvents} 6688vy}/ / /26688vy}?Z3Z3Z IIKKK9)  IOO      IIKKKKKrc||jjkr9|jD]\}}|d t j|||S)Nr )GraphicsItemChangeItemPositionHasChangedr%r nodeMovedr itemChange)r-changevalrrms rrYzNodeGraphicsItem.itemChanges` T,C C C,,.. ! !1!    (vs;;;rc|jSr)rrVs rgetMenuzNodeGraphicsItem.getMenus yrc p||||}|}|t jt|t| dSr) raddParentContextMenusr] screenPospopupr QPointintrr)r-rrrs rrFz!NodeGraphicsItem.raiseContextMenusvzz||11$ KKllnn 6=SUUWWs35577||<<=====rcntj|_|jt dd|jt dd|j}|jjs| d|jt dd|j }|jj s| d|jt dd|jj }|jj s| ddSdS)Nz Context Menurz Add inputFz Add outputz Remove node)r QMenursetTitle translate addActionaddInputFromMenurhr( setEnabledaddOutputFromMenur)rEr*)r-as rrzNodeGraphicsItem.buildMenus O%%  9^V<<=== I   . E EtG\ ] ]y' LL    I   ., G GI_ ` `y( LL    I   .- H H$)/ Z Zy% LL       rc@|jddddS)NT renamable removable multiable)rhr>rVs rriz!NodeGraphicsItem.addInputFromMenus% TTTJJJJJrc@|jddddS)NTFrn)rhrBrVs rrkz"NodeGraphicsItem.addOutputFromMenus% ddeLLLLLrN)rrrr rr!r#r%rrr+rGrr@rrHrLrQrrYr]rFrrirkrrrrrsn   D!!!   ]]] !"!"!"L222     & & &^^^ <<< >>>    KKKMMMMMr)__all__r collectionsrrr~debugrgraphicsItems.GraphicsObjectr rr r r rQCoreApplicationrgrrrQGraphicsTextItemrrrrrrzs] % & ######999999))))))))))  # - 555\\\\\6>\\\~ ZZZZZy*ZZZ4^M^M^M^M^M~^M^M^M^M^Mr