;i`dgZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z dd l mZdd lmZdd lmZdd lmZmZmZGd deZGddeZdS) GraphicsItemN) OrderedDict)reduce)hypot)Optional)Element) functions) GraphicsScene)Point)QtCore QtWidgetsisQObjectAlivec8eZdZdZdfd ZfdZfdZxZS)LRUz?Limit size, evicting the least recently looked-up key when fullcH||_tj|i|dSN)maxsizesuper__init__)selfrargskwds __class__s XC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/graphicsItems/GraphicsItem.pyrz LRU.__init__s, $'$'''''ctt|}|||Sr)r __getitem__ move_to_end)rkeyvaluers rrzLRU.__getitem__s3##C((  rc||vr||t||t||jkr!t t |}||=dSdSr)r r __setitem__lenrnextiter)rr!r"oldestrs rr$zLRU.__setitem__ss $;;   S ! ! ! C''' t99t| # #$t**%%FV  $ #r)r)__name__ __module__ __qualname____doc__rrr$ __classcell__)rs@rrrsuEE(((((( rrcteZdZdZedZdZdZdZdZ dZ d1d Z d Z d Z d Zd1d Zd2dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ d Z!d1d!Z"d"Z#d#Z$d$Z%d%Z&d1d&Z'd'Z(d(Z)d)Z*d*Z+d1d+Z,d1d,Z-d-Z.d.e/e0e1fd/e2e3e1e4e1ffd0Z5dS)3raW **Bases:** :class:`object` Abstract class providing useful methods to GraphicsObject and GraphicsWidget. (This is required because we cannot have multiple inheritance with QObject subclasses.) A note about Qt's GraphicsView framework: The GraphicsView system places a lot of emphasis on the notion that the graphics within the scene should be device independent--you should be able to take the same graphics and display them on screens of different resolutions, printers, export to SVG, etc. This is nice in principle, but causes me a lot of headache in practice. It means that I have to circumvent all the device-independent expectations any time I want to operate in pixel coordinates rather than arbitrary scene coordinates. A lot of the code in GraphicsItem is devoted to this task--keeping track of view widgets and device transforms, computing the size and shape of a pixel in local item coordinates, etc. Note that in item coordinates, a pixel does not have to be square or even rectangular, so just asking how to increase a bounding rect by 2px can be a rather complex task. dcJt|ds7|jjD]*}t|tjr||j_n+t|dstdt|zddg|_ d|_ d|_ d|_ d|_ d|_dS)N _qtBaseClassz6Could not determine Qt base class for GraphicsItem: %sF)hasattrr __bases__ issubclassr QGraphicsItemr1 Exceptionstr_pixelVectorCache _viewWidget_viewBox_connectedView _exportOpts _cachedView)rbs rrzGraphicsItem.__init__5st^,, ^-  a!89923DN/Et^,, bTWZ[_W`W``aa a"& " rcj|j|}|dS|}t|dkrdSt j|d|_|}|t |sdS|S)a Return the view widget for this item. If the scene has multiple views, only the first view is returned. The return value is cached; clear the cached value with forgetViewWidget(). If the view has been deleted by Qt, return None. Nr)r9sceneviewsr%weakrefrefr)rrArBvs r getViewWidgetzGraphicsItem.getViewWidgetFs   #JJLLE}tKKMME5zzA~~t&{4::<<+=+=+?+?+BCCD       =!2!2=4rcd|_dSr)r9rs rforgetViewWidgetzGraphicsItem.forgetViewWidget]srct|j|} |}n#t$rYdSwxYw|2|}|dSt j||_n@t |dr/|drt j||_n|S)ac Return the first ViewBox or GraphicsView which bounds this item's visible space. If this item is not contained within a ViewBox, then the GraphicsView is returned. If the item is contained inside nested ViewBoxes, then the inner-most ViewBox is returned. The result is cached; clear the cache with forgetViewBox() NT implementsViewBox)r: parentItem RuntimeErrorrFrCrDr2rK)rpvbs r getViewBoxzGraphicsItem.getViewBox`s = A   AA#   44 9++--Bz#t(/ B 1l++ Y0G0G$+KNNDM }}s ! //cd|_dSr)r:rHs r forgetViewBoxzGraphicsItem.forgetViewBoxzs  rNc|,|}|dS|}|j||}|dkrdS|S)z Return the transform that converts local item coordinates to device coordinates (usually pixels). Extends deviceTransform to automatically determine the viewportTransform. Nr)rFviewportTransformr1deviceTransform determinant)rrUviewdts rrVzGraphicsItem.deviceTransform}sq  $%%''D|t $ 6 6 8 8    . .t5F G G >>  q 4Irc|}|dSt|drB|dr-||dS|S)zReturn the transform that maps from local coordinates to the item's ViewBox coordinates If there is no ViewBox, return the scene transform. Returns None if the item does not have a view.NrKrLr)rQr2rK itemTransforminnerSceneItemsceneTransformrrXs r viewTransformzGraphicsItem.viewTransformsy   <4 4 & & )4??9+E+E )%%d&9&9&;&;<4""$$!  rc |}|dS|||d||dddd |t jdd}n'|dkrtd||||| | f}||j dkr-ttt|j dS|j|d}|+||g|_ ttt|S|}t jt jdd|}||}|dkrdS |}|} n#td|zxYwt-j|} t| |t| | f}||j d<||j d<||j|<|j dS)asReturn vectors in local coordinates representing the width and height of a view pixel. If direction is specified, then return vectors parallel and orthogonal to it. Return (None, None) if pixel size is not yet defined (usually because the item has not yet been displayed) or if pixel size is below floating-point precision limit. NNNrr@z0Cannot compute pixel length for 0-length vector.zInvalid direction %s)rV setMatrixm11m12m21m22r QPointFmanhattanLengthr6xyr8tuplemapr _pixelVectorGlobalCachegetQLineFlength unitVector normalVectorfninvertQTransformp2) r directionrYr!pv directionrdirLineviewDirnormView normOrthodtis r pixelVectorszGraphicsItem.pixelVectorss ! ! # # :: RVVXXrvvxxBFFHHbffhh1aKKK  q!,,II  & & ( (A - -NOO Ovvxx26688RVVXXy{{}}ikkmmT $(+ + +UD$:1$=>>?? ? ) - -c4 8 8 >&)2YD "U2'' '8 -q 3 3Z@@&&// >>  q : @))++H --//II @2J>?? ?!"%% 3778$$'')) * *E#'')2D2D2G2G2I2I,J,J J$&q!$'q!,.$S)%a((s (H::IFc||\}}||dS|r|S|S)a0Return the length of one pixel in the direction indicated (in local coordinates) If ortho=True, then return the length of one pixel orthogonal to the direction indicated. Return None if pixel size is not yet defined (usually because the item has not yet been displayed). N)rr|)rrorthonormVorthoVs r pixelLengthzGraphicsItem.pixelLength sM )))44 v =FN4  #==?? "||~~rc:|}|dkrdSt|d|dt|d|dfS)Nrmrr@)rrrurv)rrEs r pixelSizezGraphicsItem.pixelSize.sr       :adffhh!))511Q46688+D+DEErc|}|dStj|}|t jddddSNrr@rVrrrxr r{r|rvts r pixelWidthzGraphicsItem.pixelWidth5[  ! ! # # :1   $ $vvfmAq!Q//0077999rc|}|dStj|}|t jddddSrrrs r pixelHeightzGraphicsItem.pixelHeight=rrc\|}|dS||S)z Return *obj* mapped from local coordinates to device coordinates (pixels). If there is no device mapping available, return None. N)rVrxrobjrs r mapToDevicezGraphicsItem.mapToDeviceGs/  ! ! # # :4vvc{{rc|}|dSt|tjrtj|}t j|}||S)z Return *obj* mapped from device coordinates (pixels) to local coordinates. If there is no device mapping available, return None. N)rV isinstancer QPointrsrrrxrs r mapFromDevicezGraphicsItem.mapFromDeviceQsb  ! ! # # :4 c6= ) ) &.%%C   $ $vvc{{rc\|}|dS||S)z Return *rect* mapped from local coordinates to device coordinates (pixels). If there is no device mapping available, return None. N)rVmapRectrrectrs rmapRectToDevicezGraphicsItem.mapRectToDevice^s1  ! ! # # :4zz$rc|}|dStj|}||S)z Return *rect* mapped from device coordinates (pixels) to local coordinates. If there is no device mapping available, return None. N)rVrrrrs rmapRectFromDevicezGraphicsItem.mapRectFromDevicehsA  ! ! # # :4   $ $zz$rc\|}|dS||Sr)r_rxrs r mapToViewzGraphicsItem.mapToViewss-    ! ! :4vvc{{rc\|}|dS||Sr)r_rrs r mapRectToViewzGraphicsItem.mapRectToViewys-    ! ! :4zz#rc|}|dStj|}||Sr)r_rrrxrs r mapFromViewzGraphicsItem.mapFromViews=    ! ! :4   $ $vvc{{rc|}|dStj|}||Sr)r_rrrrs rrhzGraphicsItem.mapRectFromViews=    ! ! :4   $ $zz#rcPt|j|Sr)r r1posrHs rrzGraphicsItem.poss!T&**400111rcv|||Sr)r mapFromParentrrHs rviewPoszGraphicsItem.viewPoss*~~d00<<===rc6|j|Sr)r1rMrHs rrMzGraphicsItem.parentItem ++D111rc|A|}|+||ur|||j||Sr)rAaddItemr1 setParentItem)rparentpscenes rrzGraphicsItem.setParentItemsX  \\^^F!djjll&&@&@t$$$ ..tV<<>## #$33D99 9rc |||}||d}|tjdddd}|tj||tjddzS)zReturn the rotation produced by this item's transform (this assumes there is no shear in the transform) If relativeItem is given, then the angle is determined relative to that item. Nrr@)rMr[rxr r{angleTop1rs)r relativeItemtrvecs rtransformAnglezGraphicsItem.transformAngles  ??,,L    - -a 0ffV]1Qq++,,{{6=36688FN1Q|j |j|j |jt#j||_|||||||dS)Nr;sigDeviceRangeChangedDevicesig RangeChangedTransformChanged)r2rSrIrQr;viewRangeChangedviewTransformChangedgetattr disconnect TypeErrorAttributeErrorrNrconnectsigDeviceTransformChangedsigRangeChangedsigTransformChangedrCrD _replaceView viewChanged)rrXoldViewrsignalslots rrzGraphicsItem._updateViews.t-..  F        *))++G 7?? F  !(2I!J!JRXXPRF"<"<"<"S!T"@"@"@"@$B[!\!^   GV,,77====!><@D#'D   t455 L*2243HIII.66t7PQQQQ$,,T-BCCC(001JKKK")+d"3"3D   ! ! # # #  % % ' ' ' '""" w'''''s(#C  C&%C&cdS)zkCalled when this item's view has changed (ie, the item has been added to or removed from a ViewBox)N)rrXrs rrzGraphicsItem.viewChangedrc||}|D]X}t|tr+||ur|B|||YdSr)rrrrQrr)rritemchilds rrzGraphicsItem._replaceViews <D__&& 2 2E%.. 2##%%00%%'''!!'51111  2 2rcdS)zh Called whenever the view coordinates of the ViewBox containing this item have changed. NrrHs rrzGraphicsItem.viewRangeChanged rrcd|_dS)z Called whenever the transformation matrix of the view has changed. (eg, the view range has changed or the view was resized) Invalidates the viewRect cache. N)r=rHs rrz!GraphicsItem.viewTransformChanged's  rc|}|z.GraphicsItem.childrenShape..>s1OOOQ$""1aggii00OOOr) allChildItemsroperatoradd)rshapess` r childrenShapezGraphicsItem.childrenShape<s:OOOO$:L:L:N:NOOOhlF+++rc||}g}|D]?}|||||@|S)z>Return list of the entire item tree descending from this item.)rrdextendr)rroottreechs rrzGraphicsItem.allChildItemsAsa <D//## 0 0B KKOOO KK**2.. / / / / rc2|i}|r ||_dSd|_dS)a This method is called by exporters to inform items that they are being drawn for export with a specific set of options. Items access these via self._exportOptions. When exporting is complete, _exportOptions is set to False. NF)r<)rexportoptss r setExportModezGraphicsItem.setExportModeLs4 <D  %#D    %D   rcPt|dr|gngS)NgetMenu)r2r)revents rgetContextMenuszGraphicsItem.getContextMenus_s'#*4#;#;C Crnodesreturnct)aaMethod to override to manually specify the SVG writer mechanism. Parameters ---------- nodes Dictionary keyed by the name of graphics items and the XML representation of the the item that can be written as valid SVG. Returns ------- tuple First element is the top level group for this item. The second element is a list of xml Elements corresponding to the child nodes of the item. None Return None if no XML is needed for rendering Raises ------ NotImplementedError override method to implement in subclasses of GraphicsItem See Also -------- pyqtgraph.exporters.SVGExporter._generateItemSvg The generic and default implementation )NotImplementedError)rrs r generateSvgzGraphicsItem.generateSvgbs B"!rr)F)6r)r*r+r,rryrrFrIrQrSrVr_rfrirrrrrrrrrrrrrhrrrMrrr]rrrrrrrrrrrrrdictr7rrrwlistr rrrrr(s   "c#hh   ".   4( ) ) )   4Y)Y)Y)Y)x    FFF::::::            222>>>222===222::: R R R R8(((:(:(:(xFFF 2 2 2 2      ))),,,  % % % %&DDD!"W %!" %g./ 0!"!"!"!"!"!"r)__all__rrC collectionsr functoolsrmathrtypingrxml.etree.ElementTreerrr rr r Qtr rrrobjectrrrrrs5  ######))))))))))))2222222222 +*[ "[ "[ "[ "[ "6[ "[ "[ "[ "[ "r