
    G@d#                     ^    d Z ddlZddlmZmZmZ ddlmZmZ ddl	m
Z
  G d de
          ZdS )a  
The MIT License (MIT)

Copyright (c) 2012-2014 Alexander Turkin
Copyright (c) 2014 William Hallatt
Copyright (c) 2015 Jacob Dawid
Copyright (c) 2016 Luca Weiss
Copyright (c) 2017- Spyder Project Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

See NOTICE.txt in the Spyder repository root for more detailed information.

Minimally adapted from waitingspinnerwidget.py of the
`QtWaitingSpinner Python Fork <https://github.com/z3ntu/QtWaitingSpinner>`_.
A port of `QtWaitingSpinner <https://github.com/snowwlex/QtWaitingSpinner>`_.
    N)QRectQtQTimer)QColorQPainter)QWidgetc                       e Zd Zddej        fdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej        fdZd Zd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d"S )#QWaitingSpinnerTFc                    t          j        | |           || _        || _        t	          t
          j                  | _        d| _        d| _	        d| _
        d| _        d| _        d| _        d| _        d| _        d| _        d	| _        d| _        t'          |           | _        | j        j                            | j                   |                                  |                                  |                                  |                     |           |                     t
          j                   |                                  d S )
N      Y@g-DT!	@g      T@Fg-DT!?   
      r   )r   __init___centerOnParent_disableParentWhenSpinningr   r   black_color
_roundness_minimumTrailOpacity_trailFadePercentage_trailSizeDecreasing_revolutionsPerSecond_numberOfLines_lineLength
_lineWidth_innerRadius_currentCounter_isSpinningr   _timertimeoutconnectrotate
updateSizeupdateTimerhidesetWindowModalitysetAttributeWA_TranslucentBackgroundshow)selfparentcenterOnParentdisableParentWhenSpinningmodalitys        =lib/python3.11/site-packages/spyder/widgets/waitingspinner.pyr   zQWaitingSpinner.__init__-   s%    	v&&&-*C' RX&&$:!$(!$)!%;"   Tll##DK000		 	x((("5666		    c           
         | j         sd S |                                  t          |           }|                    |                                 t
          j                   |                    t          j        d           | j	        | j
        k    rd| _	        |                    t
          j                   t          d| j
                  D ]}|                                 |                    | j        | j        z   | j        | j        z              t%          d|z            t%          | j
                  z  }|                    |           |                    | j        d           |                     || j	        | j
                  }|                     || j
        | j        | j        | j                  }| j        r| j
        |z
  | j
        z  }nd}|                    |           t7          dt9          | j         dz            t9          || j        z            t9          || j        z                      }|                    || j        | j        t
          j                    |!                                 d S )NTr   ih     r   )"r   updatePositionr   fillRectrectr   transparentsetRenderHintAntialiasingr   r   setPenNoPenrangesave	translater   r   floatr#   lineCountDistanceFromPrimarycurrentLineColorr   r   r   r   setBrushr   roundr   drawRoundedRectr   RelativeSizerestore)	r+   QPaintEventpainterirotateAngledistancecolorsfr6   s	            r0   
paintEventzQWaitingSpinner.paintEventN   sP    	F4..bn555h3T:::4#666#$D rx   q$-.. 	 	ALLNNNd/$2BBDDUX\XhDhiiia..51D+E+EEKNN;'''d/33388D<PRVReffH))(D4GIb*.*CT[R RE
 ( )H48KKU###E4?"2Q"677rD$4455rDO3446 6D ##dotI I IOO/	 	r1   c                 @   |                                   d| _        | j        r.| j        r'|                                                     d           | j                                        s | j                                         d| _        | 	                                 d S )NTFr   )
r4   r   parentWidgetr   
setEnabledr    isActivestartr   r*   r+   s    r0   rS   zQWaitingSpinner.startt   s     	2!@ 	2**5111{##%% 	%K#$D 		r1   c                 l   | j         sd S d| _         |                                 r.| j        r'|                                                     d           | j                                        r | j                                         d| _        |                                  | 	                                 d S )NFTr   )
r   rP   r   rQ   r    rR   stopr   r*   repaintrT   s    r0   rV   zQWaitingSpinner.stop   s     	F  	14#B 	1**4000;!! 	%K#$D 		r1   c                 J    || _         d| _        |                                  d S Nr   )r   r   r%   )r+   liness     r0   setNumberOfLinesz QWaitingSpinner.setNumberOfLines   s*    # r1   c                 <    || _         |                                  d S N)r   r$   )r+   lengths     r0   setLineLengthzQWaitingSpinner.setLineLength   s     !r1   c                 <    || _         |                                  d S r]   )r   r$   )r+   widths     r0   setLineWidthzQWaitingSpinner.setLineWidth   s    r1   c                 <    || _         |                                  d S r]   )r   r$   )r+   radiuss     r0   setInnerRadiuszQWaitingSpinner.setInnerRadius   s     "r1   c                     | j         S r]   )r   rT   s    r0   rL   zQWaitingSpinner.color   s
    {r1   c                     | j         S r]   )r   rT   s    r0   	roundnesszQWaitingSpinner.roundness   
    r1   c                     | j         S r]   r   rT   s    r0   minimumTrailOpacityz#QWaitingSpinner.minimumTrailOpacity       ((r1   c                     | j         S r]   r   rT   s    r0   trailFadePercentagez#QWaitingSpinner.trailFadePercentage   rm   r1   c                     | j         S r]   )r   rT   s    r0   revolutionsPersSecondz%QWaitingSpinner.revolutionsPersSecond   s    ))r1   c                     | j         S r]   )r   rT   s    r0   numberOfLineszQWaitingSpinner.numberOfLines   s    ""r1   c                     | j         S r]   )r   rT   s    r0   
lineLengthzQWaitingSpinner.lineLength       r1   c                     | j         S )zg
        Return whether the length and thickness of the trailing lines
        are decreasing.
        r   rT   s    r0   isTrailSizeDecreasingz%QWaitingSpinner.isTrailSizeDecreasing   s    
 ((r1   c                     | j         S r]   )r   rT   s    r0   	lineWidthzQWaitingSpinner.lineWidth   ri   r1   c                     | j         S r]   )r   rT   s    r0   innerRadiuszQWaitingSpinner.innerRadius   s      r1   c                     | j         S r]   )r   rT   s    r0   
isSpinningzQWaitingSpinner.isSpinning   rw   r1   c                 L    t          dt          d|                    | _        d S )N        r   )maxminr   )r+   rh   s     r0   setRoundnesszQWaitingSpinner.setRoundness   s!    c3ui#8#899r1   c                 .    t          |          | _        d S r]   )r   r   )r+   rL   s     r0   setColorzQWaitingSpinner.setColor   s    Ummr1   c                 <    || _         |                                  d S r]   )r   r%   )r+   revolutionsPerSeconds     r0   setRevolutionsPerSecondz'QWaitingSpinner.setRevolutionsPerSecond   s"    %9"r1   c                     || _         d S r]   ro   )r+   trails     r0   setTrailFadePercentagez&QWaitingSpinner.setTrailFadePercentage   s    $)!!!r1   c                     || _         dS )zd
        Set whether the length and thickness of the trailing lines
        are decreasing.
        Nry   )r+   values     r0   setTrailSizeDecreasingz&QWaitingSpinner.setTrailSizeDecreasing   s    
 %*!!!r1   c                     || _         d S r]   rk   )r+   rl   s     r0   setMinimumTrailOpacityz&QWaitingSpinner.setMinimumTrailOpacity   s    $7!!!r1   c                 |    | xj         dz  c_         | j         | j        k    rd| _         |                                  d S )Nr3   r   )r   r   updaterT   s    r0   r#   zQWaitingSpinner.rotate   s@    !4#666#$D r1   c                 p    t          | j        | j        z   dz            }|                     ||           d S Nr   )intr   r   setFixedSize)r+   sizes     r0   r$   zQWaitingSpinner.updateSize   s;    D%(88A=>>$%%%%%r1   c                 t    | j                             t          d| j        | j        z  z                       d S )Ni  )r    setIntervalr   r   r   rT   s    r0   r%   zQWaitingSpinner.updateTimer   sR    DD,?,0,F-G %H !I !I 	J 	J 	J 	J 	Jr1   c                    |                                  r| j        r|                     t          |                                                                  dz  |                                 dz  z
            t          |                                                                  dz  |                                 dz  z
                       d S d S d S r   )rP   r   mover   ra   heightrT   s    r0   r4   zQWaitingSpinner.updatePosition   s     	.4#7 	.IIc$++--33559**,,*+ , ,$++--4466:++--!+, - -. . . . .	. 	. 	. 	.r1   c                 &    ||z
  }|dk     r||z  }|S rY    )r+   currentprimarytotalNrOfLinesrK   s        r0   r@   z,QWaitingSpinner.lineCountDistanceFromPrimary   s$    W$a<<&Hr1   c                    t          |          }|dk    r|S |dz  }t          t          j        |dz
  |z  dz                      }||k    r|                    |           ny|                                |z
  }	|	t          |dz             z  }
|                                |
|z  z
  }t          dt          d|                    }|                    |           |S )Nr   r   r3   g      ?r   )	r   r   mathceil	setAlphaFalphaFr?   r   r   )r+   countDistancer   trailFadePerc
minOpacity
colorinputrL   	minAlphaFdistanceThreshold	alphaDiffgradientresultAlphas               r0   rA   z QWaitingSpinner.currentLineColor   s    z""AL&		>A+=*NQV*V W WXX,,,OOI&&&&2I 5):Q)>#?#??H,,..8m+CCKc3sK#8#899KOOK(((r1   N)%__name__
__module____qualname__r   NonModalr   rN   rS   rV   r[   r_   rb   re   rL   rh   rl   rp   rr   rt   rv   rz   r|   r~   r   r   r   r   r   r   r   r   r#   r$   r%   r4   r@   rA   r   r1   r0   r
   r
   ,   s       .2+02;   B$ $ $L       
          ) ) )) ) )* * *# # #     ) ) )  ! ! !     : : :  X $ $ $ $  * * ** * *8 8 8  & & &J J J. . .      r1   r
   )__doc__r   qtpy.QtCorer   r   r   
qtpy.QtGuir   r   qtpy.QtWidgetsr   r
   r   r1   r0   <module>r      s      D  ) ) ) ) ) ) ) ) ) ) ' ' ' ' ' ' ' ' " " " " " "\ \ \ \ \g \ \ \ \ \r1   