
    G@d!                         d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
 ddlmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ  G d
 dee          Z G d de          ZdS )zStatus bar widgets.    )PYQT5)QtQSizeQTimerSignal)QFontQIcon)QHBoxLayoutQLabelQWidget)SpyderAPIError)SpyderWidgetMixin)QStylePalette)create_waitspinnerc                   ~     e Zd ZdZdZ	 dZ	  e            Z	 	 	 d fd	Zd Z	d Z
d Zd	 Z fd
Zd Zd Zd Z xZS )StatusBarWidgetaR  
    Base class for status bar widgets.

    These widgets consist by default of an icon, a label and a spinner,
    which are organized from left to right on that order.

    You can also add any other QWidget to this layout by setting the
    CUSTOM_WIDGET_CLASS class attribute. It'll be put between the label
    and the spinner.
    NTFc                    t           r$t                                          ||           n+t          j        | |           t	          j        | |           || _        || _        || _        || _        d| _	        d| _
        d| _        d| _        d| _        |                                  |                     |                                            dS )au  
        Base class for status bar widgets.

        These are composed of the following widgets, which are arranged
        in a QHBoxLayout from left to right:

        * Icon
        * Label
        * Custom QWidget
        * Spinner

        Parameters
        ----------
        show_icon: bool
            Show an icon in the widget.
        show_label: bool
            Show a label in the widget.
        show_spinner: bool
            Show a spinner.

        Notes
        -----
        1. To use an icon, you need to redefine the ``get_icon`` method.
        2. To use a label, you need to call ``set_value``.
        )class_parentN)r   super__init__r   r   _parent	show_icon
show_labelshow_spinnervalue
label_iconlabel_valuespinnercustom_widget
set_layoutsetStyleSheet_stylesheet)selfparentr   r   r   	__class__s        9lib/python3.11/site-packages/spyder/api/widgets/status.pyr   zStatusBarWidget.__init__2   s    6  	BGGV&9999T6***&t&AAAA"$(
!4++--.....    c                 d   | j         r]|                                 | _        d| _        t	          dd          | _        t          |           | _        |                                  | j	        rt          |           | _
        |                     d           t          t                                                      t          j                  | _        | j
                            t"          j        t"          j        z             | j
                            | j                   | j        rHt-          | j        t.                    st1          d          |                     | j                  | _        | j        r/t9          d|           | _        | j                                         t?          |           }|                     d           | j         r|!                    | j                   | j	        r|!                    | j
                   | j        r|!                    | j                   | j        r|!                    | j                   |"                    d           |#                    dddd           |                    t"          j                   | $                                 dS )	zSet layout for default widgets.N    )weightz/Any custom status widget must subclass QWidget!   )sizer$   r   )%r   get_icon_icon_pixmapr   
_icon_sizer   r   set_iconr   r   	set_valuer   defaultFamilyNormal	text_fontsetAlignmentr   
AlignRightAlignVCentersetFontCUSTOM_WIDGET_CLASS
issubclassr   r   r   r   r   r   r   hider
   
setSpacing	addWidget
addSpacingsetContentsMarginsupdate_tooltip)r#   layouts     r&   r    zStatusBarWidget.set_layoutb   sm    > 	DJDL#BmmDO$TllDOMMOOO ? 	5%d||DNN2 #577#8#8#:#:*/,8 8 8DN))"-"/*IJJJ$$T^444 # 	Hd6@@ $E   "&!9!9$,!G!GD  	 -2dCCCDLL T""!> 	.T_---? 	/T-... 	1T/000 	+T\***!!!!Q1---BO,,, 	r'   c                    | j         rz| j        }| j                             |du           |Wt          |t                    rD|                    | j                  | _        | j                             | j                   dS dS dS dS )z'Set the icon for the status bar widget.N)	r   r/   
setVisible
isinstancer	   pixmapr1   r0   	setPixmap)r#   icons     r&   r2   zStatusBarWidget.set_icon   s    ? 	8:DO&&t4'7888JtU$;$;#{{4?;;))$,77777	8 	8  r'   c                 Z    | j         r#|| _        | j                             |           dS dS )zSet formatted text value.N)r   r   setText)r#   r   s     r&   r3   zStatusBarWidget.set_value   s;     	,DJ$$U+++++	, 	,r'   c                     |                                  }|rY| j        r| j                            |           | j        r| j                            |           |                     |           dS dS )zUpdate tooltip for widget.N)get_tooltipr   
setToolTipr   )r#   tooltips     r&   rB   zStatusBarWidget.update_tooltip   s    ""$$ 	% 5 ++G444 4**7333OOG$$$$$	% 	%r'   c                     t          t          |                               |           | j                                         dS )z-Override Qt method to allow for click signal.N)r   r   mousePressEventsig_clickedemitr#   eventr%   s     r&   mouseReleaseEventz!StatusBarWidget.mouseReleaseEvent   s<    ot$$44U;;;r'   c                     dS )Return the widget tooltip text.r*    r#   s    r&   rM   zStatusBarWidget.get_tooltip   s    rr'   c                     dS )rX   NrY   rZ   s    r&   r.   zStatusBarWidget.get_icon   s    tr'   c                 \    d                     t          j        t          j                  }|S )NzMQToolTip {{background-color: {background_color};color: {color};border: none}})background_colorcolor)formatr   COLOR_ACCENT_2COLOR_TEXT_1)r#   
stylesheets     r&   r"   zStatusBarWidget._stylesheet   s4    '(.'4'C)6 )/ ) ) 	 r'   )NTTF)__name__
__module____qualname____doc__IDr;   r   rR   r   r    r2   r3   rB   rV   rM   r.   r"   __classcell__r%   s   @r&   r   r      s        	 	 
B  &((K @D#./ ./ ./ ./ ./ ./`3 3 3l8 8 8, , ,% % %                   r'   r   c                   J     e Zd ZdZd	 fd	Z fdZ fdZd Zd Zd Z	 xZ
S )
BaseTimerStatuszH
    Base class for status bar widgets that update based on timers.
    Nc                    d| _         t                                          |           d| _        | j                                        }| j                            |                    d                     t          |           | _         | j         j	        
                    | j                   | j                             | j                   dS )z>Base class for status bar widgets that update based on timers.Ni  z000%)timerr   r   	_intervalr   fontMetricssetMinimumWidthwidthr   timeoutconnectupdate_statusstart)r#   r$   fmr%   s      r&   r   zBaseTimerStatus.__init__   s    
    ))++((&)9)9::: D\\

""4#5666
(((((r'   c                 |    | j                                          t                                          |           d S N)rm   stopr   
closeEventrT   s     r&   rz   zBaseTimerStatus.closeEvent   s3    
5!!!!!r'   c                     | j         ;|r | j                             | j                   n| j                                          t	          t
          |                               |           dS )z<Override Qt method to stops timers if widget is not visible.N)rm   ru   rn   ry   r   rk   rE   )r#   r   r%   s     r&   rE   zBaseTimerStatus.setVisible   sd    :! "
  0000
!!!ot$$//66666r'   c                     |                                  r.| j                            |                                            dS dS )z1Update status label widget, if widget is visible.N)	isVisibler   rK   	get_valuerZ   s    r&   rt   zBaseTimerStatus.update_status   sE    >> 	7$$T^^%5%566666	7 	7r'   c                 Z    || _         | j        | j                            |           dS dS )zSet timer interval (ms).N)rn   rm   setInterval)r#   intervals     r&   set_intervalzBaseTimerStatus.set_interval   s5    !:!J""8,,,,, "!r'   c                     t           )zReturn formatted text value.)NotImplementedErrorrZ   s    r&   r~   zBaseTimerStatus.get_value   s    !!r'   rx   )rc   rd   re   rf   r   rz   rE   rt   r   r~   rh   ri   s   @r&   rk   rk      s         ) ) ) ) ) )" " " " "
7 7 7 7 77 7 7
- - -" " " " " " "r'   rk   N)rf   qtpyr   qtpy.QtCorer   r   r   r   
qtpy.QtGuir   r	   qtpy.QtWidgetsr
   r   r   spyder.api.exceptionsr   spyder.api.widgets.mixinsr   spyder.utils.paletter   spyder.utils.qthelpersr   r   rk   rY   r'   r&   <module>r      s/           1 1 1 1 1 1 1 1 1 1 1 1 # # # # # # # # 7 7 7 7 7 7 7 7 7 7 1 0 0 0 0 0 7 7 7 7 7 7 . . . . . . 5 5 5 5 5 5o o o o og0 o o od1" 1" 1" 1" 1"o 1" 1" 1" 1" 1"r'   