;i[ddlmZmZddlZddlmZddlmZddl m Z m Z ddl m Z dd l m Z dd lmZdd lmZd d gZGdd e ZGdd eZdS))atan2degreesN) functions)Point)QtCoreQtGui) GraphicsItem)GraphicsObject)TextItem)ViewBox InfiniteLine InfLineLabelcBeZdZdZejeZejeZejeZ ejeeZ d$dZ dZ dZ d Zd Zd Zd%dZdZdZdZdZdZdZdZdZdZdZdZdZd&dZdZdZ dZ!d Z"d!Z#d"Z$d#Z%dS)'ra **Bases:** :class:`GraphicsObject ` Displays a line of infinite length. This line may be dragged to indicate a position in data coordinates. =============================== =================================================== **Signals:** sigDragged(self) sigPositionChangeFinished(self) sigPositionChanged(self) sigClicked(self, ev) =============================== =================================================== NZFrr c d|_| |_tj|| ddg|_n||_d|_||d|_ddg|_| ||tdd}| ||d}| ||/| d|jn| || |_|j|_g|_d|_| | D] } |j|  ddg|_d|_d|_||in|}t1|fd|i||_dSdS) a8 =============== ================================================================== **Arguments:** pos Position of the line. This can be a QPointF or a single value for vertical/horizontal lines. angle Angle of line in degrees. 0 is horizontal, 90 is vertical. pen Pen to use when drawing line. Can be any arguments that are valid for :func:`mkPen `. Default pen is transparent yellow. hoverPen Pen to use when the mouse cursor hovers over the line. Only used when movable=True. movable If True, the line can be dragged to a new position by the user. bounds Optional [min, max] bounding values. Bounds are only valid if the line is vertical or horizontal. hoverPen Pen to use when drawing line when hovering over it. Can be any arguments that are valid for :func:`mkPen `. Default pen is red. label Text to be displayed in a label attached to the line, or None to show no label (default is None). May optionally include formatting strings to display the line value. labelOpts A dict of keyword arguments to use when constructing the text label. See :class:`InfLineLabel `. span Optional tuple (min, max) giving the range over the view to draw the line. For example, with a vertical line, use span=(0.5, 1) to draw only on the top half of the view. markers List of (marker, position, size) tuples, one per marker to display on the line. See the addMarker method. name Name of the item =============== ================================================================== NFr)rd)rr)colorwidthr text) _boundingRect_namer __init__maxRangemoving setMovable mouseHoveringpsetAnglersetPossetPen setHoverPenpenrspan currentPenmarkers_maxMarkerSize addMarker _endPoints_bounds _lastViewSizerlabel) selfposangler'movableboundshoverPenr0 labelOptsr(r*namems XC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/graphicsItems/InfiniteLine.pyrzInfiniteLine.__init__%sB" %%% >!4LDMM"DM     "Q e ;!**C C ;!C C     9DHNN4D4D  E E E E   X & & & (    # #"""a& !  '/YI%dDDD)DDDJJJ  c>||_||dS)z,Set whether the line is movable by the user.Nr4setAcceptHoverEventsr1r9s r:r zInfiniteLine.setMovableus#  !!!$$$$$r;cb||_||dS)z:Set the (minimum, maximum) allowable values when dragging.N)rsetValuevalue)r1r5s r: setBoundszInfiniteLine.setBoundszs)  djjll#####r;c |jddS)zDReturn the (minimum, maximum) values allowed when dragging. N)rr1s r:r5zInfiniteLine.boundss}QQQr;ctj|i||_|js"|j|_|dSdS)zySet the pen for drawing the line. Allowable arguments are any that are valid for :func:`mkPen `.N)fnmkPenr'r!r)update)r1argskwargss r:r%zInfiniteLine.setPensI8T,V,,! "hDO KKMMMMM  r;ct|dkrEt|dtjp$t|dto d|dvpd|v}t j|i||_|s1|j|j |j r"|j|_ | dSdS)aSet the pen for drawing the line while the mouse hovers over it. Allowable arguments are any that are valid for :func:`mkPen `. If the line is not movable, then hovering is also disabled. Added in version 0.9.9.r rrN)len isinstancer QPendictrGrHr6setWidthr'rr!r)rI)r1rJrKwidthSpecifieds r:r&zInfiniteLine.setHoverPenst99>O&tAw ;;N&tAw55L'T!W:L1 '&0 $1&11  5 M " "48>>#3#3 4 4 4   "mDO KKMMMMM  r;?$@c\tj}|dkr*|tjddddd|vrjtjt ddt ddt ddg}|||d|vrjtjt ddt ddt ddg}|||d|vrjtjt ddt ddt ddg}|||d |vrjtjt ddt ddt ddg}|||d |vrjtjt ddt ddt ddg}|||d |vrjtjt ddt ddt ddg}||||j |||ftd |j D|_ | d S)aAdd a marker to be displayed on the line. ============= ========================================================= **Arguments** marker String indicating the style of marker to add: ``'<|'``, ``'|>'``, ``'>|'``, ``'|<'``, ``'<|>'``, ``'>|<'``, ``'^'``, ``'v'``, ``'o'`` position Position (0.0-1.0) along the visible extent of the line to place the marker. Default is 0.5. size Size of the marker in pixels. Default is 10.0. ============= ========================================================= ogr z<|rSrz|>z>|z|<^vc$g|] }|ddz S)rg@).0r9s r: z*InfiniteLine.addMarker..s "C"C"C1Q4"9"C"C"Cr;N)r QPainterPath addEllipserQRectF QPolygonFr addPolygon closeSubpathr*appendmaxr+rI)r1markerpositionsizepathr"s r:r,zInfiniteLine.addMarkers!## S== OOFM$a;; < < < 6>>sAadA OPPA OOA          6>>sAa uT1~~ NOOA OOA          6>>sD!1!15A;;dD@Q@Q RSSA OOA          6>>sC%1++uT3?O?O PQQA OOA          &==q$sAa NOOA OOA          &==q$tQq# OPPA OOA          T8T2333!"C"Cdl"C"C"CDD r;cJg|_d|_|dS)z, Remove all markers from this line. rN)r*r+rIrEs r: clearMarkerszInfiniteLine.clearMarkerss$  r;c||_|||j|dS)z Takes angle argument in degrees. 0 is horizontal; 90 is vertical. Note that the use of value() and setValue() changes if the line is not vertical or horizontal. N)r3resetTransform setRotationrI)r1r3s r:r#zInfiniteLine.setAnglesD   $$$ r;ct|tttjfr(tj|dkst|}nrt|t jr)|| g}n/|j dkr|dg}n|j dkrd|g}ntd|j dkrc|j d$t|d|j d|d<|j d$t|d|j d|d<nm|j dkrb|j d$t|d|j d|d<|j d$t|d|j d|d<|j|kr^||_|t#j|t'|j|j|dSdS)Nrrz4Must specify 2D coordinate for non-orthogonal lines.r )rNlisttuplenpndarrayndimrQPointFxyr3 Exceptionrrdminr"viewTransformChangedr r$rsigPositionChangedemit)r1r2newPoss r:r$zInfiniteLine.setPoss cD%4 5 5 Xbgclla>O>O#YYFF V^ , , Xeeggsuuww'FFzRqqS VWWW :  }Q+q 4=+;<<q }Q+q 4=+;<<q Z1__}Q+q 4=+;<<q }Q+q 4=+;<<q 6V  DF  % % ' ' '  !$df 6 6 6  # ( ( . . . . .  r;c|jdSNrr"rEs r:getXPoszInfiniteLine.getXPosvayr;c|jdS)Nr rrEs r:getYPoszInfiniteLine.getYPosrr;c|jSNrrEs r:getPoszInfiniteLine.getPoss v r;c|jdzdkr|S|jdzdkr|S|S)zReturn the value of the line. Will be a single number for horizontal and vertical lines, and a list of [x,y] values for diagonal lines.rr)r3rrrrEs r:rBzInfiniteLine.value sP :c>Q  <<>> ! Z^r ! !<<>> !;;== r;c0||dS)zSet the position of the line. If line is horizontal or vertical, v can be a single value. Otherwise, a 2D coordinate must be specified (list, tuple and QPointF are all acceptable).N)r$r1rXs r:rAzInfiniteLine.setValues Ar;c^|j||fkr||f|_|dSdSr)r(rI)r1mnmxs r:setSpanzInfiniteLine.setSpan%s7 9R RDI KKMMMMM ! r;c|}|tjS|t dd\}}|dn|}t |jdz |j dz }|j |zdz|z}tj|}| | | ||}| ||jdzz} | ||jdzz} || || |}|} |j|ks |j| kr"||_| |_|| | f|_||_|jS)Nr r) directionr)viewRectrr_ pixelVectorsrrvrdr'rr6r+ setBottomsetTopleftr(setLeftsetRight normalized getViewBoxrgr.r/prepareGeometryChanger- _lastViewRect) r1vr_orthopxpwwbrlengthrrightvss r:_computeBoundingRectz!InfiniteLine._computeBoundingRect*s ]]__ :=?? "$$uQ{{$;;5-QQUWWYY !!A%t}':':'<'>5??333 t|   ! ! F[[]] uT1~~&&ffU5!__%% VVE$NN # #Eks""$$ceeggsuuww//00 E  %Zddffsuuww24466!11 a11R((( 2:do335566777 [[]]#|  OD#t NN2    A KK1    GGD$    JJt       r;?c|dkrdSdS)Nr)rrrZ)r1axisfrac orthoRanges r: dataBoundszInfiniteLine.dataBounds}s 19945r;c|jrR|tjjjkr'|rad|_|| | z |_ ||_ | |jsdS||j | |z|j||r'd|_|j|dSdSdSdSNTF)r4buttonrr MouseButton LeftButtonisStartrr2 mapToParent buttonDownPos cursorOffset startPositionacceptr$ sigDraggedr{isFinishsigPositionChangeFinishedr1evs r:mouseDragEventzInfiniteLine.mouseDragEvents, < :BIIKK69+@+KKKzz|| 0" $(HHJJ1A1A"BRBRBTBT1U1U$U!%)XXZZ" IIKKK;  KK)D,<,???& ?((<..C::&&'2GG'2GG:#q(('2GG'2G $''$''' 4    r;c|sdS|j}||j||dS)N)rB) isVisiblerrBsetTextrupdatePosition)r1rBs r:rzInfLineLabel.valueChangedsg~~  F !! T[''e'44555 r;c8|jd|j}t|d}t|d}|jjdzdkr|}|rt|tsdStj }| ||||j|d|}tj }||||tj}t+|dkrWt-|d}|j||d}|j||d}||f|_|jS)Nrrrr )rrrrrrr3rrrNrr r]moveTolineTo itemTransformraddRect intersectedtoSubpathPolygons QTransformrMro mapFromItem) r1lrpt1pt2viewr"rpathsls r: getEndpointszInfLineLabel.getEndpointss ?1  %''))B 1%%C A&&Cy#q((((~~''(z$/H/H('<&((  I++D11!488;;')) 4,,..///q));;E>U1XA)//ad;;C)//ad;;C"CjDOr;cvd|_|\}}|dS||jz|d|jz zz}|||j}|N||j| dkrdnddSdS)Nrr r) rrrr$rr setAnchorrcenterrv)r1rrptrs r:rzInfLineLabel.updatePositions&$$&&S ; F 4= 3!DM/#: : BY   ! ! > NN4r;c`tj|||r|dSdSr)r setVisiblerrs r:rzInfLineLabel.setVisible)s?D!$$$           r;c>||_||dS)zFSet whether this label is movable by dragging along the line. Nr=r?s r:r zInfLineLabel.setMovable.s%  !!!$$$$$r;c<||_|dS)a Set the relative position (0.0-1.0) of this label within the view box and along the line. For horizontal (angle=0) and vertical (angle=90) lines, a value of 0.0 places the text at the bottom or left of the view, respectively. N)rr)r1r"s r: setPositionzInfLineLabel.setPosition4s#  r;c<||_|dS)zSet the text format string for this label. May optionally contain "{value}" to include the lines current value (the text will be reformatted whenever the line is moved). N)rr)r1rs r: setFormatzInfLineLabel.setFormat>s#   r;c\|jr|tjjjkr|r?d|_|| |_ |j |_ | |jsdS||}tj|j |z|j z dd|_ ||r d|_dSdSdSdS)NTgrF)r4rrrrrr_moving _posToRelr _cursorOffsetr_startPositionrr2rG clip_scalarrr)r1rrels r:rzInfLineLabel.mouseDragEventGs  < %BIIKK69+@+KKKzz|| 4# %)^^B4D4D4F4F%G%G"&*m# IIKKK< ..**CN4+>+DtGY+Y[]_abbDM    ! ! !{{}} %$  % %KK % %r;c|jrU|tjjjkr+||j|_d|_dSdSdSr) rrrrrrrr$rrs r:rzInfLineLabel.mouseClickEventXsX ; 299;;&)*?*KKK IIKKK /DMDKKK  KKr;c|s2|jr-|tjjjdSdSdSr)rr4rrrrrrs r:rzInfLineLabel.hoverEvent^sOyy{{ =t| = NN690; < < < < < = = = =r;c~tj||tj|dSr)r ryrr rEs r:ryz!InfLineLabel.viewTransformChangedbs<)$/// %d+++++r;c|\}}|dS||}||z ||z z Sr~)rrru)r1r2rrs r:r"zInfLineLabel._posToRelgsh$$&&S ;1s###%%''!ceeggceeggo66r;)rFrSN)rrrrrrrrrr rrrrrryr"rZr;r:rrs>68 J J J   %%% %%%"   ===,,, 77777r;)mathrrnumpyrqrrrGrrrr r r r r__all__rrrZr;r:r.s(&&&&&&****** > *jjjjj>jjjZ p7p7p7p7p78p7p7p7p7p7r;