ó
‹²,]c           @   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 ƒ d e ƒn  d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z e d k r‡e ƒ  n  d S(    s   Status bar widgets.iÿÿÿÿN(   t   Qtt   QTimer(   t   QHBoxLayoutt   QLabelt   QWidget(   t   dependencies(   t   _(   t   get_font(   t   to_text_stringt   nts   >=0.3t   psutils+   CPU and memory usage info in the status bart   required_versiont   StatusBarWidgetc           B   s   e  Z d  Z d „  Z RS(   s   Status bar widget base.c         C   s‘   t  t |  ƒ j | ƒ t d d ƒ |  _ |  j j |  j ƒ  j ƒ  ƒ |  j j t	 ƒ t
 ƒ  } | j d d d d ƒ |  j | ƒ | j |  ƒ d S(   s   Status bar widget base.t   optiont	   rich_fonti    N(   t   superR   t   __init__R   t
   label_fontt   setPointSizet   fontt	   pointSizet   setBoldt   TrueR   t   setContentsMarginst	   setLayoutt   addPermanentWidget(   t   selft   parentt	   statusbart   layout(    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR       s    	(   t   __name__t
   __module__t   __doc__R   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR      s   t   BaseTimerStatusc           B   sP   e  Z d  Z d Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   s?   Status bar widget base for widgets that update based on timers.c         C   s&  t  t |  ƒ j | | ƒ t |  j ƒ |  _ t ƒ  |  _ |  j |  j ƒ |  j j	 t
 j ƒ |  j j |  j ƒ |  j j ƒ  } |  j j | j d ƒ ƒ |  j ƒ  } | j |  j ƒ | j |  j ƒ | j d ƒ |  j ƒ  rt ƒ  |  _ |  j j j |  j ƒ |  j j d ƒ n d |  _ |  j ƒ  d S(   s?   Status bar widget base for widgets that update based on timers.s   000%i   iÐ  N(   R   R!   R   R   t   TITLEt   labelt   valuet
   setToolTipt   TIPt   setAlignmentR    t
   AlignRightt   setFontR   t   fontMetricst   setMinimumWidtht   widthR   t	   addWidgett
   addSpacingt   is_supportedR   t   timert   timeoutt   connectt   update_labelt   startt   Nonet   hide(   R   R   R   t   fmR   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR   9   s$    	c         C   s&   |  j  d k	 r" |  j  j | ƒ n  d S(   s   Set timer interval (ms).N(   R0   R5   t   setInterval(   R   t   interval(    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt   set_intervalW   s    c         C   s
   t  ‚ d S(   s.   Raise ImportError if feature is not supported.N(   t   NotImplementedError(   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt   import_test\   s    c         C   s+   y |  j  ƒ  t SWn t k
 r& t SXd S(   s$   Return True if feature is supported.N(   R<   R   t   ImportErrort   False(   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR/   `   s
    
c         C   s
   t  ‚ d S(   s(   Return value (e.g. CPU or memory usage).N(   R;   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt	   get_valueh   s    c         C   s-   |  j  ƒ  r) |  j j d |  j ƒ  ƒ n  d S(   s1   Update status label widget, if widget is visible.s   %d %%N(   t	   isVisibleR$   t   setTextR?   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR3   l   s    N(   R   R   R    R5   R"   R&   R   R:   R<   R/   R?   R3   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR!   3   s   					t   MemoryStatusc           B   s8   e  Z d  Z e d ƒ Z e d ƒ Z d „  Z d „  Z RS(   s*   Status bar widget for system memory usage.s   Memory:sT   Memory usage status: requires the `psutil` (>=v0.3) library on non-Windows platformsc         C   s   d d l  m } d S(   s.   Raise ImportError if feature is not supported.iÿÿÿÿ(   t   memory_usageN(   t   spyder.utils.systemRC   (   R   RC   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR<   y   s    c         C   s   d d l  m } | ƒ  S(   s   Return memory usage.iÿÿÿÿ(   RC   (   RD   RC   (   R   RC   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR?   }   s    (   R   R   R    R   R"   R&   R<   R?   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyRB   r   s
   	t	   CPUStatusc           B   s8   e  Z d  Z e d ƒ Z e d ƒ Z d „  Z d „  Z RS(   s'   Status bar widget for system cpu usage.s   CPU:s8   CPU usage status: requires the `psutil` (>=v0.3) libraryc         C   s/   d d l  m } | j d d ƒ s+ t ‚ n  d S(   s.   Raise ImportError if feature is not supported.iÿÿÿÿ(   t   programsR
   s   >=0.2.0N(   t   spyder.utilsRF   t   is_module_installedR=   (   R   RF   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR<   ‰   s    c         C   s   d d l  } | j d d ƒ S(   s   Return CPU usage.iÿÿÿÿNR9   i    (   R
   t   cpu_percent(   R   R
   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR?   ‘   s    (   R   R   R    R   R"   R&   R<   R?   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyRE   ƒ   s
   	t   ReadWriteStatusc           B   s    e  Z d  Z d „  Z d „  Z RS(   s3   Status bar widget for current file read/write mode.c         C   s   t  t |  ƒ j | | ƒ t t d ƒ ƒ |  _ t ƒ  |  _ |  j j t j	 ƒ |  j j
 |  j ƒ |  j ƒ  } | j |  j ƒ | j |  j ƒ | j d ƒ d S(   s3   Status bar widget for current file read/write mode.s   Permissions:i   N(   R   RJ   R   R   R   R#   t	   readwriteR'   R    R(   R)   R   R   R-   R.   (   R   R   R   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR      s    c         C   s/   | r d n d } |  j  j | j d ƒ ƒ d S(   s   Update read/write file status.t   Rt   RWi   N(   RK   RA   t   ljust(   R   t   readonlyRK   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt   readonly_changed¯   s    (   R   R   R    R   RP   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyRJ   š   s   	t	   EOLStatusc           B   s    e  Z d  Z d „  Z d „  Z RS(   s3   Status bar widget for the current file end of line.c         C   s   t  t |  ƒ j | | ƒ t t d ƒ ƒ |  _ t ƒ  |  _ |  j j t j	 ƒ |  j j
 |  j ƒ |  j ƒ  } | j |  j ƒ | j |  j ƒ | j d ƒ d S(   s3   Status bar widget for the current file end of line.s   End-of-lines:i   N(   R   RQ   R   R   R   R#   t   eolR'   R    R(   R)   R   R   R-   R.   (   R   R   R   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR   ¸   s    c         C   s:   t  | ƒ } |  j j i d d 6d d 6j | d ƒ ƒ d S(   s   Update end of line status.t   CRLFR	   t   LFt   posixt   CRN(   R   RR   RA   t   get(   R   t   os_name(    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt   eol_changedÊ   s    (   R   R   R    R   RY   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyRQ   µ   s   	t   EncodingStatusc           B   s    e  Z d  Z d „  Z d „  Z RS(   s0   Status bar widget for the current file encoding.c         C   s   t  t |  ƒ j | | ƒ t t d ƒ ƒ |  _ t ƒ  |  _ |  j j t j	 ƒ |  j j
 |  j ƒ |  j ƒ  } | j |  j ƒ | j |  j ƒ | j d ƒ d S(   s0   Status bar widget for the current file encoding.s	   Encoding:i   N(   R   RZ   R   R   R   R#   t   encodingR'   R    R(   R)   R   R   R-   R.   (   R   R   R   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR   Ó   s    c         C   s)   |  j  j t | ƒ j ƒ  j d ƒ ƒ d S(   s    Update encoding of current file.i   N(   R[   RA   t   strt   upperRN   (   R   R[   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt   encoding_changedå   s    (   R   R   R    R   R^   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyRZ   Ð   s   	t   CursorPositionStatusc           B   s    e  Z d  Z d „  Z d „  Z RS(   s6   Status bar widget for the current file cursor postion.c         C   sÞ   t  t |  ƒ j | | ƒ t t d ƒ ƒ |  _ t t d ƒ ƒ |  _ t ƒ  |  _ t ƒ  |  _ |  j j	 |  j
 ƒ |  j j	 |  j
 ƒ |  j ƒ  } | j |  j ƒ | j |  j ƒ | j |  j ƒ | j |  j ƒ |  j | ƒ d S(   s6   Status bar widget for the current file cursor postion.s   Line:s   Column:N(   R   R_   R   R   R   t
   label_linet   label_columnt   columnt   lineR)   R   R   R-   R   (   R   R   R   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR   í   s    c         C   s4   |  j  j d | d ƒ |  j j d | d ƒ d S(   s   Update cursos position.s   %-6di   s   %-4dN(   Rc   RA   Rb   (   R   Rc   t   index(    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt   cursor_position_changed  s    (   R   R   R    R   Re   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyR_   ê   s   	c          C   s¾   d d l  m }  d d l m } | d d ƒ } |  ƒ  } | j d ƒ | j d d ƒ | j ƒ  } g  } x< t t t	 t
 t t f D]" } | | | ƒ } | j | ƒ q€ W| j ƒ  | j ƒ  d  S(	   Niÿÿÿÿ(   t   QMainWindow(   t   qapplicationt	   test_timei   s   Status widgets testi„  i,  (   t   qtpy.QtWidgetsRf   t   spyder.utils.qthelpersRg   t   setWindowTitlet   resizet	   statusBarRJ   RQ   RZ   R_   RB   RE   t   appendt   showt   exec_(   Rf   Rg   t   appt   winR   t   swidgetst   klasst   swidget(    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt   test	  s    	
t   __main__(   R    t   ost   qtpy.QtCoreR    R   Ri   R   R   R   t   spyderR   t   spyder.config.baseR   t   spyder.config.guiR   t   spyder.py3compatR   t   namet   PSUTIL_REQVERt   addR   R!   RB   RE   RJ   RQ   RZ   R_   Rv   R   (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/status.pyt   <module>   s,   
?	