;iV:ddlZddlmZddlmZddlmZddlmZm Z m Z ddl m Z dd l m Z dd l m Z dd lmZdd lmZdd lmZmZddgZGdde e ZGdde ZdS)N) functions) invisibleEye)Point)QtCoreQtGui QtWidgets) BarGraphItem)GraphicsWidget)GraphicsWidgetAnchor) LabelItem) PlotDataItem)ScatterPlotItem drawSymbol LegendItem ItemSampleceZdZdZ d!dZd Zd Zd Zd Zd Z dZ dZ dZ dZ dZdZdZdZdZdZdZdZdZdZdZdZdZdZd ZdS)"ra Displays a legend used for describing the contents of a plot. LegendItems are most commonly created by calling :meth:`PlotItem.addLegend `. Note that this item should *not* be added directly to a PlotItem (via :meth:`PlotItem.addItem `). Instead, make it a direct descendant of the PlotItem:: legend.setParentItem(plotItem) NrT9ptr c Btj|tj|||jjt j|_|j ||j || |jg|_ ||_ ||_||_| |_d|_|@|t'jdd|j d|j d| ,t+| tst-d| |_n t0|_t3j|t3j||| |d|_|j| dS)a6 ============== =============================================================== **Arguments:** size Specifies the fixed size (width, height) of the legend. If this argument is omitted, the legend will automatically resize to fit its contents. offset Specifies the offset position relative to the legend's parent. Positive values offset from the left or top; negative values offset from the right or bottom. If offset is None, the legend must be anchored manually by calling anchor() or positioned by calling setPos(). horSpacing Specifies the spacing between the line symbol and the label. verSpacing Specifies the spacing between individual entries of the legend vertically. (Can also be negative to have them really close) pen Pen to use when drawing legend border. Any single argument accepted by :func:`mkPen ` is allowed. brush QBrush to use as legend background filling. Any single argument accepted by :func:`mkBrush ` is allowed. labelTextColor Pen to use when drawing legend text. Any single argument accepted by :func:`mkPen ` is allowed. labelTextSize Size to use when drawing legend text. Accepts CSS style string arguments, e.g. '9pt'. colCount Specifies the integer number of columns that the legend should be divided into. The number of rows will be calculated based on this argument. This is useful for plots with many curves displayed simultaneously. Default: 1 column. sampleType Customizes the item sample class of the `LegendItem`. ============== =============================================================== r NrzBOnly classes of type `GraphicsWidgets` are allowed as `sampleType`)penbrushlabelTextColor labelTextSizeoffset)r __init__r setFlagGraphicsItemFlagItemIgnoresTransformationsr QGraphicsGridLayoutlayoutsetVerticalSpacingsetHorizontalSpacing setLayoutitemssizerframe columnCountrowCount setGeometryrQRectF issubclass RuntimeError sampleTyperfnmkPenmkBrushoptsupdate) selfr'r horSpacing verSpacingrrrr(rcolCountr/kwargss VC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/graphicsItems/LegendItem.pyrzLegendItem.__init__ sB %%%%d+++ T*EFFF355  &&z222 ((444 t{###    #     V]1a1ty|LL M M M  !j.99 B"$ABBB(DOO(DO8C==Z&&,*          c||jurdSt|j}||_||D])\}}|j}|j}|||*|dS)zSet the new sample item claspesN)r/listr&clearitemtextaddItem updateSize)r5sampler&label plot_item plot_names r: setSampleTypezLegendItem.setSampleTypecs T_ $ $ FTZ    # / /MFE I I LLI . . . . r;c|jdS)z/Get the offset position relative to the parent.rr3r5s r:rzLegendItem.offsetusy""r;c||jd<t|jd}|ddkrdnd}|ddkrdnd}||f}||||dS)z/Set the offset position relative to the parent.rrr itemPos parentPosrN)r3ranchor)r5ranchorxanchoryrOs r: setOffsetzLegendItem.setOffsetyst$ (ty*++ayA~~!!1ayA~~!!17# FfV DDDDDr;c|jdS)z7Get the QPen used to draw the border around the legend.rrIrJs r:rzLegendItem.pensyr;cdtj|i|}||jd<|dS)z~Set the pen used to draw a border around the legend. Accepts the same arguments as :func:`~pyqtgraph.mkPen`. rN)r0r1r3r4)r5argskargsrs r:setPenzLegendItem.setPens5 h&&& % r;c|jdS)z2Get the QBrush used to draw the legend background.rrIrJs r:rzLegendItem.brushsy!!r;ctj|i|}|jd|krdS||jd<|dS)z}Set the brush used to draw the legend background. Accepts the same arguments as :func:`~pyqtgraph.mkBrush`. rN)r0r2r3r4)r5rUrVrs r:setBrushzLegendItem.setBrushsL  D*E** 9W  & & F" ' r;c|jdS)z(Get the QColor used for the item labels.rrIrJs r:rzLegendItem.labelTextColorsy)**r;ctj|i||jd<|jD]&\}}|d|jd'|dS)zmSet the color of the item labels. Accepts the same arguments as :func:`~pyqtgraph.mkColor`. rcolorN)r0mkColorr3r&setAttrr4)r5rUrVrCrDs r:setLabelTextColorzLegendItem.setLabelTextColorsg ')j$&@%&@&@ "#!Z @ @MFE MM'49-=#> ? ? ? ? r;c|jdS)z1Get the `labelTextSize` used for the item labels.rrIrJs r:rzLegendItem.labelTextSizesy))r;c||jd<|jD]&\}}|d|jd'|dS)zhSet the `size` of the item labels. Accepts the CSS style string arguments, e.g. '8pt'. rr'N)r3r&r_r4)r5r'_rDs r:setLabelTextSizezLegendItem.setLabelTextSizesT &* /"  > >HAu MM&$)O"< = = = = r;ctj||}|jdVt|jd}|ddkrdnd}|ddkrdnd}||f}|||||S)zSet the parent.rNrr rL)r setParentItemr3rrO)r5pretrrPrQrOs r:rfzLegendItem.setParentItems*433 9X  *49X.//F!!9>>aaqG!!9>>aaqGw'F KK&K H H H r;c>t||jdd|jd}t||jr|}n||}|j||f||||dS)a[ Add a new entry to the legend. ============== ======================================================== **Arguments:** item A :class:`~pyqtgraph.PlotDataItem` from which the line and point style of the item will be determined or an instance of ItemSample (or a subclass), allowing the item display to be customized. title The title to display for this item. Simple HTML allowed. ============== ======================================================== rleftr)r]justifyr'N)rr3 isinstancer/r&append_addItemToLayoutrB)r5r?namerDrCs r:rAzLegendItem.addItems$di0@&A"(ty/IKKK dDO , , +FF__T**F 65/*** fe,,, r;c|j}|j}|r|dz}|jdz}||krAtd|dD]}|j||sn |dz|krd}|dz }|j||||j|||dzt |j|dz|_dS)Nr rr)r"r)r*rangeitemAtrAmax)r5rCrDcolrownCols r:rnzLegendItem._addItemToLayoutsk%%''k""$$   1HC!# $;;Qa((  {))#s33E7d??C1HC FC--- E3a000DM3733 r;c||jkr||_tjt|j|z |_t |jdz ddD]}|j ||jD]\}}| ||| dSdS)z:change the orientation of all items of the legend r N) r)mathceillenr&r*rqr"countremoveAtrnrB)r5r)irCrDs r:setColumnCountzLegendItem.setColumnCounts $* * **D  Ic$*oo &CDDDM4;,,..2B;; ( ( $$Q''''!% 5 5 %%fe4444 OO      + *r;cjfd|jD} |ddS#t$rYdSwxYw)zReturn the labelItem inside the legend for a given plotItem The label-text can be changed via labelItem.setText c4g|]\}}|jk||fS)r?).0itlabplotItems r: z'LegendItem.getLabel.. s-JJJWRbg6I6ICy6I6I6Ir;rr N)r& IndexError)r5routs ` r:getLabelzLegendItem.getLabelsV KJJJ JJJ q6!9    44 s $ 22c|D][}|j|||}|r||\dSN)r" removeItemclosescene)r5rUr?rs r:_removeItemFromLayoutz LegendItem._removeItemFromLayoutsj ' 'D K " "4 ( ( ( JJLLL JJLLE '  &&& ' 'r;c|jD]b\}}|j|us |j|krI|j||f||||dScdS)aRemoves one item from the legend. ============== ======================================================== **Arguments:** item The item to remove or its name. ============== ======================================================== N)r&r?r@removerrB)r5r?rCrDs r:rzLegendItem.removeItems"Z  MFE{d""ejD&8&8 !!65/222**65999!!! '9  r;c|jD]\}}|||g|_|dS)z!Remove all items from the legend.N)r&rrB)r5rCrDs r:r>zLegendItem.clear*sM!Z 6 6MFE  & &vu 5 5 5 5  r;c|jdSd}d}t|jD]}d}d}t|jD][}|j||}|r<||dzz }t||}\t||}||z }| dd||dS)Nr) r'rqr"r*r)rrwidthrsheightr+)r5rrru row_height col_widthrtr?s r:rBzLegendItem.updateSize2s 9 F--//00 ! !CJIT[446677 @ @{))#s33@!11I!$Z!?!?Jy))E j FF Auf---r;cxtjdd||S)Nr)rr,rrrJs r: boundingRectzLegendItem.boundingRectDs(}Q4::<<???r;c|jri||jd||jd||dSdS)Nrr)r(rWr3rZdrawRectr)r5rgrUs r:paintzLegendItem.paintGsl : , HHTYu% & & & JJty) * * * JJt((** + + + + + , ,r;cX|tjjjdSr) acceptDragsrQt MouseButton LeftButton)r5evs r: hoverEventzLegendItem.hoverEventMs" vy,788888r;c0|tjjjkri|||z }|||zdSdSr) buttonrrrracceptposlastPos autoAnchor)r5rdposs r:mouseDragEventzLegendItem.mouseDragEventPsq 99;;&)/: : : IIKKK6688bjjll*D OODHHJJ- . . . . . ; :r;) NNrrNNNTrr N)__name__ __module__ __qualname____doc__rrGrrRrrWrrZrr`rrdrfrArnrrrrr>rBrrrrrr;r:rrs  JKBF=AA!A!A!A!F$###EEE   """   +++   ***      .444,       ' ' '   $@@@,,, 999/////r;c*eZdZdZdZdZdZdZdS)rzMClass responsible for drawing a single item in a LegendItem (sans label) c<tj|||_dSr)r rr?)r5r?s r:rzItemSample.__init__[s%%% r;c0tjddddS)Nr)rr,rJs r:rzItemSample.boundingRect_s}Q2r***r;c |jj}|dr||jj|j}|sKtj}| tj dd| dddSt|jts.|t!j|d|dddd|dd|d d|t!j|d |t!j|d|t-jtjd dtjdd tjddg|d d}|t|jt2r|jjj}|d d t9|||d t!j|dt!j|dt|jt:rY|t!j|d|tjd d dddSdS)N antialiasr rr r fillLevel fillBrushrsymbol r'r) r?r3get setRenderHint RenderHint Antialiasing isVisiblerqicon drawPixmaprQPointpixmaprlrrWr0r1drawLinerZr2 drawPolygonr QPolygonFQPointFrscatter translaterr rr,)r5rgrUr3visibleiconrs r:rzItemSample.paintbsy~ 88K  7 OOAL5 6 6 6)%%'' %D LLq!,,dkk"b.A.A B B B F$)_55 / HHRXd5k** + + + JJq"b" % % %d++7HH[$//; 2:d;&788999$u+../// eo^Ar**FN2q,A,A^B++-..///(D))  $)\22 .y(- KKB    q&$v,e0E0Ez$w-00 2 2 2 di . . 4 JJrz$w-00 1 1 1 JJv}Q2r22 3 3 3 3 3 4 4r;c|tjjjkr4|j}|j| || dS)zJUse the mouseClick event to toggle the visibility of the plotItem N) rrrrrr?r setVisiblerr4)r5eventrs r:mouseClickEventzItemSample.mouseClickEventsh <<>>VY2= = =i))++G I W - - -  r;N)rrrrrrrrrr;r:rrWs[+++!4!4!4Fr;)ryrr0iconsrrrrrr r r r rrrr__all__rrrr;r:rsH  ))))))))))&&&&&&******666666 &&&&&&88888888  &C/C/C/C/C/%~C/C/C/L 6666666666r;