
    Je!                         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y)zStatus bar widgets.    )PYQT5)QtQSizeQTimerSignal)QFontQIcon)QHBoxLayoutQLabelQWidget)SpyderAPIError)SpyderWidgetMixin)QStylePalette)create_waitspinnerc                   x     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.
    Nc                 l   t         rt        | 	  ||       n-t        j                  | |       t	        j                  | |       || _        || _        || _        || _        d| _	        d| _
        d| _        d| _        d| _        | j                          | j                  | j!                                y)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        ;/usr/lib/python3/dist-packages/spyder/api/widgets/status.pyr   zStatusBarWidget.__init__2   s    6 GV&9T6*&&t&A"$(
!4++-.    c                 d   | j                   rM| j                         | _        d| _        t	        dd      | _        t        |       | _        | j                          | j                  rt        |       | _
        | j                  d       t        t               j                         t        j                        | _        | j                  j!                  t"        j$                  t"        j&                  z         | j                  j)                  | j                         | j*                  rEt-        | j*                  t.              st1        d      | j+                  | j2                        | _        | j6                  r,t9        d|       | _        | j:                  j=                          t?        |       }|jA                  d       | j                   r|jC                  | j                         | j                  r|jC                  | j                         | j4                  r|jC                  | j4                         | j6                  r|jC                  | j:                         |jE                  d       |jG                  dddd       |j!                  t"        j&                         | jI                          y)	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   s    >>DJDL#BmDO$TlDOMMO ??%d|DNN2 #57#8#8#:*/,,8DN))"--"//*IJ$$T^^4 ##d66@$E  "&!9!9$,,!GD -2dCDLLL T"!>>T__-??T--.T//0T\\*!!!!Q1-BOO, 	r'   c                 "   | j                   r| j                  }| j                   j                  |du       |Wt        |t              rF|j                  | j                        | _        | j                   j                  | j                         yyyy)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   so    ??::DOO&&t4'78JtU$;#{{4??;))$,,7 %< r'   c                 b    | j                   r#|| _        | j                   j                  |       yy)zSet formatted text value.N)r   r   setText)r#   r   s     r&   r3   zStatusBarWidget.set_value   s+    DJ$$U+ r'   c                     | j                         }|r`| j                  r| j                  j                  |       | j                  r| j                  j                  |       | j                  |       yy)zUpdate tooltip for widget.N)get_tooltipr   
setToolTipr   )r#   tooltips     r&   rB   zStatusBarWidget.update_tooltip   sZ    ""$  ++G4**73OOG$ r'   c                 `    t         t        |   |       | j                  j	                          y)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4U;r'   c                      y)Return the widget tooltip text.r*    r#   s    r&   rM   zStatusBarWidget.get_tooltip   s    r'   c                      y)rX   NrY   rZ   s    r&   r.   zStatusBarWidget.get_icon   s    r'   c                 d    dj                  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   s5    '(.'4'C'C)6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      sh    	 
B  (K @D#./`3l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.
    c                    d| _         t        | 	  |       d| _        | j                  j                         }| j                  j                  |j                  d             t        |       | _         | j                   j                  j                  | j                         | j                   j                  | j                         y)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: D\


""4#5#56

(r'   c                 X    | j                   j                          t        |   |       y N)rm   stopr   
closeEventrT   s     r&   rz   zBaseTimerStatus.closeEvent   s    

5!r'   c                     | j                   B|r&| j                   j                  | j                         n| j                   j                          t        t
        |   |       y)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   sC    ::!

  0

!ot/6r'   c                 x    | j                         r*| j                  j                  | j                                yy)z1Update status label widget, if widget is visible.N)	isVisibler   rK   	get_valuerZ   s    r&   rt   zBaseTimerStatus.update_status   s,    >>$$T^^%56 r'   c                 b    || _         | j                  | j                  j                  |       yy)zSet timer interval (ms).N)rn   rm   setInterval)r#   intervals     r&   set_intervalzBaseTimerStatus.set_interval   s*    !::!JJ""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
-"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      sJ      1 1 # 7 7 1 7 . 5og0 od1"o 1"r'   