;i=ddlZddlmZddlmZddlmZddlmZm Z ddl m Z dd l m Z dd l m Z dd lmZdd lmZd dgZGdd eZGdde ZdS)N)atan2) functions)Point)QtCoreQtGui)GraphicsObject)Symbols)TextItem)UIGraphicsItem)ViewBox TargetItem TargetLabelceZdZdZejeZejeZ dfd Z fdZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZddZxZS)rzDraws a draggable target symbol (circle plus crosshair). The size of TargetItem will remain fixed on screen even as the view is zoomed. Includes an optional text label. N crosshairTc Zt||_d|_d|_d|_|d}|||d}|||d}|||d}| ||j |_ |j |_ d|_tdd|_|tdd}||t%|t&r1 t(||_nN#t,$rt-dwxYwt%|t.jr||_nt3d ||_||j|| | dS) aF Parameters ---------- pos : list, tuple, QPointF, QPoint, Optional Initial position of the symbol. Default is (0, 0) size : int Size of the symbol in pixels. Default is 10. pen : QPen, tuple, list or str Pen to use when drawing line. Can be any arguments that are valid for :func:`~pyqtgraph.mkPen`. Default pen is transparent yellow. brush : QBrush, tuple, list, or str Defines the brush that fill the symbol. Can be any arguments that is valid for :func:`~pyqtgraph.mkBrush`. Default is transparent blue. movable : bool If True, the symbol can be dragged to a new position by the user. hoverPen : QPen, tuple, list, or str Pen to use when drawing symbol when hovering over it. Can be any arguments that are valid for :func:`~pyqtgraph.mkPen`. Default pen is red. hoverBrush : QBrush, tuple, list or str Brush to use to fill the symbol when hovering over it. Can be any arguments that is valid for :func:`~pyqtgraph.mkBrush`. Default is transparent blue. symbol : QPainterPath or str QPainterPath to use for drawing the target, should be centered at ``(0, 0)`` with ``max(width, height) == 1.0``. Alternatively a string which can be any symbol accepted by :func:`~pyqtgraph.ScatterPlotItem.setSymbol` label : bool, str or callable, optional Text to be displayed in a label attached to the symbol, or None to show no label (default is None). May optionally include formatting strings to display the symbol value, or a callable that accepts x and y as inputs. If True, the label is ``x = {: >.3n}\ny = {: >.3n}`` False or None will result in no text being displayed labelOpts : dict A dict of keyword arguments to use when constructing the text label. See :class:`TargetLabel` and :class:`~pyqtgraph.TextItem` FN)rr)rrr)rrr2)rrrdrz&symbol name found in available SymbolszUnknown type provided as symbol)super__init__movablemoving_label mouseHoveringsetPen setHoverPensetBrush setHoverBrushpen currentPenbrush currentBrush_shaper_possetPos isinstancestrr _pathKeyErrorr QPainterPath TypeErrorscalesetPathsetLabel) selfpossizesymbolr"hoverPenr$ hoverBrushrlabel labelOpts __class__s VC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/graphicsItems/TargetItem.pyrzTargetItem.__init__sh    " ;C C  $H """ =#E e  +J :&&&( J !QKK ;1++C C fc " " ? I$V_  I I IGHHH I  2 3 3 ?DJJ=>> >  TZ    eY'''''s D&&Ec t|}n*#t$rt$rtd|wxYw|j|krI||_t |j|j|dSdS)aMethod to set the position to ``(x, y)`` within the plot view Parameters ---------- args : tuple or list or QtCore.QPointF or QtCore.QPoint or Point or float Two float values or a container that specifies ``(x, y)`` position where the TargetItem should be placed Raises ------ TypeError If args cannot be used to instantiate a Point z%Could not make Point from arguments: N)rr. Exceptionr'rr(sigPositionChangedemit)r2argsnewPosr:s r;r(zTargetItem.setPos{s ND\FF     N N NLDLLMM M N 9  DI GGNN49 % % %  # ( ( . . . . .  s '4ctj|i||_|js"|j|_|dSdS)zSet the brush that fills the symbol. Allowable arguments are any that are valid for :func:`~pyqtgraph.mkBrush`. N)fnmkBrushr$rr%updater2r@kwargss r;r zTargetItem.setBrushsJZ000 !  $ D  KKMMMMM  ctj|i||_|jr"|j|_|dSdS)zSet the brush that fills the symbol when hovering over it. Allowable arguments are any that are valid for :func:`~pyqtgraph.mkBrush`. N)rCrDr7rr%rErFs r;r!zTargetItem.setHoverBrushsJ*d5f55    $D  KKMMMMM  rHctj|i||_|js"|j|_|dSdS)ztSet the pen for drawing the symbol. Allowable arguments are any that are valid for :func:`~pyqtgraph.mkPen`.N)rCmkPenr"rr#rErFs r;rzTargetItem.setPensI8T,V,,! "hDO KKMMMMM  rHctj|i||_|jr"|j|_|dSdS)zSet the pen for drawing the symbol when hovering over it. Allowable arguments are any that are valid for :func:`~pyqtgraph.mkPen`.N)rCrKr6rr#rErFs r;rzTargetItem.setHoverPensI$1&11   "mDO KKMMMMM  rHcN|SN)shape boundingRectr2s r;rPzTargetItem.boundingRectszz||((***rHc||j||j||dSrN)rr#r r%drawPathrO)r2p_s r;paintzTargetItem.paintsK !!! 4$%%% 4::<<     rHc8||jkr||_d|_dSrN)r+r&)r2paths r;r0zTargetItem.setPaths" 4:  DJDKtrHc|j8|}||jS||_||jSrN)r& generateShaper+prepareGeometryChange)r2ss r;rOzTargetItem.shapesK ; ""$$Ayz!DK  & & ( ( ({rHc*|}||j|_dS|t jdd|t jddz }t j|}|t jdd}tj }| | | t| | }||||j|j|||jS)Nr r)deviceTransformr+r&maprQPointFrCinvertQTransformr QTransform translatexyr rotateRadiansr/)r2dtvdtidevPostrvas r;rZzTargetItem.generateShapes*  ! ! # # :*DK4 FF6>!Q'' ( (266&.A2F2F+G+G G!"%%q!,,--     VXXZZ,,, 13355!##%%   TZ(((wwrvvdj))***rHcT|jr,|tjjjkrdS||rH|| | z |_ d|_ |j sdS| |j | |z|r#d|_ |j|dSdSNTF)rbuttonrQt MouseButton LeftButtonacceptisStartr3 mapToView buttonDownPos symbolOffsetrr(isFinishsigPositionChangeFinishedr?r2evs r;mouseDragEventzTargetItem.mouseDragEvents| ryy{{fi.C.NNN F ::<<  $ T^^Br?ryrzs r;mouseClickEventzTargetItem.mouseClickEvents~ ; 6299;;&)*?*KKK IIKKKDK  # ( ( . . .  * / / 5 5 5 5 5  6 6KKrHc|j|urdS||_|r|j|_|j|_n|j|_|j|_|dSrN)rr7r%r6r#r$r"rE)r2hovers r; setMouseHoverzTargetItem.setMouseHovers^   & & F"  ' $D "mDOO $ D "hDO rHc|jrT|s@|tjjjr|ddS|ddSrn)risExit acceptDragsrrprqrrrrzs r; hoverEventzTargetItem.hoverEventsj < & &"..AVAa2b2b &   t $ $ $ $ $   u % % % % %rHcdtj|d|_|dSrN)r viewTransformChangedr&rErQs r;rzTargetItem.viewTransformChanged s++D111  rHc|jS)zProvides the current position of the TargetItem Returns ------- Point pg.Point of the current position of the TargetItem )r'rQs r;r3zTargetItem.poss yrHc|jS)zProvides the TargetLabel if it exists Returns ------- TargetLabel or None If a TargetLabel exists for this TargetItem, return that, otherwise return None )rrQs r;r8zTargetItem.labels {rHcn|sZ|jJ|j1|j|jd|_dS|durd}|in|}|j1|j|jt|fd|i||_dS)aMethod to call to enable or disable the TargetLabel for displaying text Parameters ---------- text : Callable or str, optional Details how to format the text, by default None If None, do not show any text next to the TargetItem If Callable, then the label will display the result of ``text(x, y)`` If a fromatted string, then the output of ``text.format(x, y)`` will be displayed If a non-formatted string, then the text label will display ``text``, by default None labelOpts : dict, optional These arguments are passed on to :class:`~pyqtgraph.TextItem` NTzx = {: .3n} y = {: .3n}text)rscene removeItemr)r2rr9s r;r1zTargetItem.setLabel%s  D{&4;+<+<+>+>+J !!##..t{;;;DKKKt||1'/YI{& !!##..t{;;;%dCCCCCDKKKrH) NrrNNNNTNN)NN)__name__ __module__ __qualname____doc__rSignalobjectr>ryrr(r r!rrrPrVr0rOrZr|rrrrr3r8r1 __classcell__r:s@r;rrs 'v.. - f 5 5   `(`(`(`(`(`(D/////4+++!!!     + + +666 666   &&&     DDDDDDDDrHcReZdZdZ d fd ZdZdZdZfd Zd Z d Z xZ S) raA TextItem that attaches itself to a TargetItem. This class extends TextItem with the following features : * Automatically positions adjacent to the symbol at a fixed position. * Automatically reformats text when the symbol location has changed. Parameters ---------- target : TargetItem The TargetItem to which this label will be attached to. text : str or callable, Optional Governs the text displayed, can be a fixed string or a format string that accepts the x, and y position of the target item; or be a callable method that accepts a tuple (x, y) and returns a string to be displayed. If None, an empty string is used. Default is None offset : tuple or list or QPointF or QPoint Position to set the anchor of the TargetLabel away from the center of the target in pixels, by default it is (20, 0). anchor : tuple or list or QPointF or QPoint Position to rotate the TargetLabel about, and position to set the offset value to see :class:`~pyqtgraph.TextItem` for more information. kwargs : dict kwargs contains arguments that are passed onto :class:`~pyqtgraph.TextItem` constructor, excluding text parameter rrg?c ~t|tr||_nt|ttfrt||_not|t jt jfr:t|| |_ntdtj dd|i|| |||_|||jj|j|dS)Nz'Offset parameter is the wrong data typeanchor)r)roffsettuplelistrQPointr`rdrer.rr setParentItemtarget setFormatr>connect valueChanged)r2rrrrrGr:s r;rzTargetLabel.__init__as fe $ $ G DKK  . . G.DKK  ? @ @ G FHHJJ77DKKEFF F111&111 6"""  t &..t/@AAA rHc|jSrN)_formatrQs r;formatzTargetLabel.formatzs |rHct|sttj|}|r%|dd|ddnB|||ddn|dd||_|dS)a Method to set how the TargetLabel should display the text. This method should be called from TargetItem.setLabel directly. Parameters ---------- text : Callable or str Details how to format the text. If Callable, then the label will display the result of ``text(x, y)`` If a fromatted string, then the output of ``text.format(x, y)`` will be displayed If a non-formatted string, then the text label will display ``text`` rr NformattableTextTF) callablerstring Formatterparse setPropertysetTextrr)r2rparseds r;rzTargetLabel.setFormat}s~~ 7&*,,2248899F ;&)A,2  !2D9999 T"""  !2E::::   . 6 6 6  rHcz|j\}}|drJ||jt |t |dSt|jr+||||dSdS)Nr)rr3propertyrrrfloatr)r2rdres r;rzTargetLabel.valueChangeds{  1 ==* + + - LL,,U1XXuQxx@@ A A A A A dl # # - LLa++ , , , , , - -rHc|}t|tr~|}t j|j|dz|j|dz}| |t S)Nrr ) getViewBoxr)r viewPixelSizerr`rrdrer(rr)r2viewboxr scaledOffsetr:s r;rz TargetLabel.viewTransformChangeds//## gw ' ' &#1133M!> -"22DKMMOOmTUFV4VL KK % % %ww++---rHcP||SrN) parentItemrrzs r;rzTargetLabel.mouseClickEvents   00444rHc||}|jr,|tjjjkrdS||rH| | | z |_ d|_ |j sdS||j | | z|r#d|_ |j|dSdSrn)rrrorrprqrrrsrtr3rurvrwrr(rxryr?)r2r{ targetItems r;r|zTargetLabel.mouseDragEvents__&& ! RYY[[FI4I4T%T%T F ::<< %&0nn&6&6  ""::'J #!%J    F*1DNN266884L4LLMMM ;;== < %J   0 5 5d ; ; ; ; ; < rs9 ******$$$$$$******  'tDtDtDtDtDtDtDtDn u<u<u<u<u<(u<u<u<u<u