B
    nôb\"  ã               @   s  d Z ddl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 ejd	ks‚d
Ze
jdedƒed G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdd„ Zed kreƒ  dS )!zStatus bar widgets.é    N)ÚQtÚQTimer)ÚQHBoxLayoutÚQLabelÚQWidget)Údependencies)Ú_)Úget_font)Úto_text_stringÚntz>=0.3Úpsutilz+CPU and memory usage info in the status bar)Zrequired_versionc                   s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚStatusBarWidgetzStatus bar widget base.c                sj   t t| ƒ |¡ tdd| _| j |  ¡  ¡ ¡ | j d¡ t	ƒ }| 
dddd¡ |  |¡ | | ¡ dS )zStatus bar widget base.Z	rich_font)ZoptionTr   N)Úsuperr   Ú__init__r	   Ú
label_fontZsetPointSizeZfontZ	pointSizeZsetBoldr   ZsetContentsMarginsÚ	setLayoutZaddPermanentWidget)ÚselfÚparentÚ	statusbarÚlayout)Ú	__class__© ú4lib/python3.7/site-packages/spyder/widgets/status.pyr       s    
zStatusBarWidget.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   )r   r   r      s   r   c                   sP   e Zd ZdZdZdZ‡ fdd„Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Z‡  ZS )ÚBaseTimerStatusz?Status bar widget base for widgets that update based on timers.Nc                sÔ   t t| ƒ ||¡ t| jƒ| _tƒ | _|  | j¡ | j 	t
j¡ | j | j¡ | j ¡ }| j | d¡¡ |  ¡ }| | j¡ | | j¡ | d¡ |  ¡ rÂtƒ | _| jj | j¡ | j d¡ nd| _|  ¡  dS )z?Status bar widget base for widgets that update based on timers.z000%é   iÐ  N)r   r   r   r   ÚTITLEÚlabelÚvalueZ
setToolTipÚTIPÚsetAlignmentr   Ú
AlignRightÚsetFontr   ZfontMetricsZsetMinimumWidthÚwidthr   Ú	addWidgetÚ
addSpacingÚis_supportedr   ÚtimerZtimeoutZconnectÚupdate_labelÚstartZhide)r   r   r   Zfmr   )r   r   r   r   9   s$    

zBaseTimerStatus.__init__c             C   s   | j dk	r| j  |¡ dS )zSet timer interval (ms).N)r+   ZsetInterval)r   Úintervalr   r   r   Úset_intervalW   s    
zBaseTimerStatus.set_intervalc             C   s   t ‚dS )z.Raise ImportError if feature is not supported.N)ÚNotImplementedError)r   r   r   r   Úimport_test\   s    zBaseTimerStatus.import_testc             C   s&   y|   ¡  dS  tk
r    dS X dS )z$Return True if feature is supported.TFN)r1   ÚImportError)r   r   r   r   r*   `   s
    zBaseTimerStatus.is_supportedc             C   s   t ‚dS )z(Return value (e.g. CPU or memory usage).N)r0   )r   r   r   r   Ú	get_valueh   s    zBaseTimerStatus.get_valuec             C   s    |   ¡ r| j d|  ¡  ¡ dS )z1Update status label widget, if widget is visible.z%d %%N)Z	isVisibler"   ÚsetTextr3   )r   r   r   r   r,   l   s    zBaseTimerStatus.update_label)r   r   r   r   r    r#   r   r/   r1   r*   r3   r,   r   r   r   )r   r   r   3   s   r   c               @   s0   e Zd ZdZedƒZedƒZdd„ Zdd„ ZdS )	ÚMemoryStatusz*Status bar widget for system memory usage.zMemory:zTMemory usage status: requires the `psutil` (>=v0.3) library on non-Windows platformsc             C   s   ddl m} dS )z.Raise ImportError if feature is not supported.r   )Úmemory_usageN)Úspyder.utils.systemr6   )r   r6   r   r   r   r1   y   s    zMemoryStatus.import_testc             C   s   ddl m} |ƒ S )zReturn memory usage.r   )r6   )r7   r6   )r   r6   r   r   r   r3   }   s    zMemoryStatus.get_valueN)	r   r   r   r   r   r    r#   r1   r3   r   r   r   r   r5   r   s
   r5   c               @   s0   e Zd ZdZedƒZedƒZdd„ Zdd„ ZdS )	Ú	CPUStatusz'Status bar widget for system cpu usage.zCPU:z8CPU usage status: requires the `psutil` (>=v0.3) libraryc             C   s    ddl m} | dd¡st‚dS )z.Raise ImportError if feature is not supported.r   )Úprogramsr   z>=0.2.0N)Zspyder.utilsr9   Zis_module_installedr2   )r   r9   r   r   r   r1   ‰   s    zCPUStatus.import_testc             C   s   ddl }|jddS )zReturn CPU usage.r   N)r.   )r   Zcpu_percent)r   r   r   r   r   r3   ‘   s    zCPUStatus.get_valueN)	r   r   r   r   r   r    r#   r1   r3   r   r   r   r   r8   ƒ   s
   r8   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚReadWriteStatusz3Status bar widget for current file read/write mode.c                sr   t t| ƒ ||¡ ttdƒƒ| _tƒ | _| j tj	¡ | j 
| j¡ |  ¡ }| | j¡ | | j¡ | d¡ dS )z3Status bar widget for current file read/write mode.zPermissions:r   N)r   r:   r   r   r   r!   Ú	readwriter$   r   r%   r&   r   r   r(   r)   )r   r   r   r   )r   r   r   r      s    zReadWriteStatus.__init__c             C   s"   |rdnd}| j  | d¡¡ dS )zUpdate read/write file status.ÚRZRWé   N)r;   r4   Úljust)r   Úreadonlyr;   r   r   r   Úreadonly_changed¯   s    z ReadWriteStatus.readonly_changed)r   r   r   r   r   r@   r   r   r   )r   r   r:   š   s   r:   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )Ú	EOLStatusz3Status bar widget for the current file end of line.c                sr   t t| ƒ ||¡ ttdƒƒ| _tƒ | _| j tj	¡ | j 
| j¡ |  ¡ }| | j¡ | | j¡ | d¡ dS )z3Status bar widget for the current file end of line.zEnd-of-lines:r   N)r   rA   r   r   r   r!   Úeolr$   r   r%   r&   r   r   r(   r)   )r   r   r   r   )r   r   r   r   ¸   s    zEOLStatus.__init__c             C   s&   t |ƒ}| j dddœ |d¡¡ dS )zUpdate end of line status.ZCRLFZLF)r   ÚposixZCRN)r
   rB   r4   Úget)r   Zos_namer   r   r   Úeol_changedÊ   s    zEOLStatus.eol_changed)r   r   r   r   r   rE   r   r   r   )r   r   rA   µ   s   rA   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚEncodingStatusz0Status bar widget for the current file encoding.c                sr   t t| ƒ ||¡ ttdƒƒ| _tƒ | _| j tj	¡ | j 
| j¡ |  ¡ }| | j¡ | | j¡ | d¡ dS )z0Status bar widget for the current file encoding.z	Encoding:r   N)r   rF   r   r   r   r!   Úencodingr$   r   r%   r&   r   r   r(   r)   )r   r   r   r   )r   r   r   r   Ó   s    zEncodingStatus.__init__c             C   s   | j  t|ƒ ¡  d¡¡ dS )z Update encoding of current file.é   N)rG   r4   ÚstrÚupperr>   )r   rG   r   r   r   Úencoding_changedå   s    zEncodingStatus.encoding_changed)r   r   r   r   r   rK   r   r   r   )r   r   rF   Ð   s   rF   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚCursorPositionStatusz6Status bar widget for the current file cursor postion.c                s    t t| ƒ ||¡ ttdƒƒ| _ttdƒƒ| _tƒ | _tƒ | _| j 	| j
¡ | j 	| j
¡ |  ¡ }| | j¡ | | j¡ | | j¡ | | j¡ |  |¡ dS )z6Status bar widget for the current file cursor postion.zLine:zColumn:N)r   rL   r   r   r   Z
label_lineZlabel_columnÚcolumnÚliner&   r   r   r(   r   )r   r   r   r   )r   r   r   r   í   s    zCursorPositionStatus.__init__c             C   s,   | j  d|d  ¡ | j d|d  ¡ dS )zUpdate cursos position.z%-6dé   z%-4dN)rN   r4   rM   )r   rN   Úindexr   r   r   Úcursor_position_changed  s    z,CursorPositionStatus.cursor_position_changed)r   r   r   r   r   rQ   r   r   r   )r   r   rL   ê   s   rL   c              C   sŒ   ddl m}  ddlm} |dd}| ƒ }| d¡ | dd¡ | ¡ }g }x,ttt	t
ttfD ]}|||ƒ}| |¡ q\W | ¡  | ¡  d S )	Nr   )ÚQMainWindow)Úqapplicationé   )Z	test_timezStatus widgets testi„  i,  )Úqtpy.QtWidgetsrR   Zspyder.utils.qthelpersrS   ZsetWindowTitleZresizeZ	statusBarr:   rA   rF   rL   r5   r8   ÚappendZshowZexec_)rR   rS   ZappÚwinr   ZswidgetsÚklassZswidgetr   r   r   Útest	  s    


rY   Ú__main__)r   ÚosZqtpy.QtCorer   r   rU   r   r   r   Zspyderr   Zspyder.config.baser   Zspyder.config.guir	   Zspyder.py3compatr
   ÚnameZPSUTIL_REQVERÚaddr   r   r5   r8   r:   rA   rF   rL   rY   r   r   r   r   r   Ú<module>   s,   
?
