ó
‹²,]c           @   sZ  d  Z  d d l Z d d l j Z d d l m Z d d l m Z d d l	 m
 Z
 m Z m Z d d l m Z m Z m Z m Z 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 d d l  m! Z! d d l  m" Z# d d l$ m% Z% d d l& m' Z' d e f d „  ƒ  YZ( d e e f d „  ƒ  YZ) d S(   s   Working Directory PluginiÿÿÿÿN(   t   PYQT5(   t   getexistingdirectory(   t   QSizet   Signalt   Slot(   t   QButtonGroupt	   QGroupBoxt   QHBoxLayoutt   QLabelt   QToolBart   QVBoxLayout(   t   _t   get_conf_patht   get_home_dir(   t   SpyderPluginMixin(   t   PluginConfigPage(   t   to_text_string(   t   getcwd_or_home(   t   encoding(   t   icon_manager(   t   create_action(   t   PathComboBoxt   WorkingDirectoryConfigPagec           B   s   e  Z d  „  Z RS(   c         C   sÔ  t  t d ƒ ƒ } | j t ƒ t t d ƒ ƒ } t  t d ƒ ƒ } | j t ƒ t | ƒ } |  j t d ƒ d t d | ƒ} |  j t d ƒ d t d | ƒ} |  j t d	 ƒ d
 t t d ƒ d | ƒ} |  j d d t	 ƒ  ƒ } | j
 j | j ƒ | j
 j | j ƒ | j
 j | j ƒ t ƒ  }	 |	 j | ƒ |	 j | ƒ t ƒ  }
 |
 j | ƒ |
 j | ƒ |
 j | ƒ |
 j |	 ƒ | j |
 ƒ t ƒ  } | j | ƒ | j d ƒ | j | ƒ | j d ƒ |  j | ƒ d  S(   Nsƒ   The <b>current working directory</b> is the working directory for IPython consoles and the current directory for the File Explorer.s   Console directorys*   The working directory for new consoles is:sN   The current project directory or user home directory (if no project is active)s%   console/use_project_or_home_directoryt   button_groups   The current working directorys   console/use_cwds   the following directory:s   console/use_fixed_directorysC   The directory when a new console is open will be the specified patht    s   console/fixed_directoryi
   i   (   R   R   t   setWordWrapt   TrueR   R   t   create_radiobuttont   Falset   create_browsedirR   t   toggledt   connectt
   setEnabledt   setDisabledR   t	   addWidgetR
   t	   addLayoutt	   setLayoutt
   addSpacingt
   addStretch(   t   selft   about_labelt   console_groupt   console_labelt
   console_bgt   console_project_radiot   console_cwd_radiot   console_dir_radiot   console_dir_bdt   console_dir_layoutt   console_layoutt   vlayout(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyt
   setup_page&   sR    									(   t   __name__t
   __module__R3   (    (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyR   %   s   t   WorkingDirectoryc           B   sy  e  Z d  Z d Z e Z e e ƒ Z e e	 e
 ƒ Z e e ƒ Z e e ƒ Z e e ƒ Z e e	 ƒ Z e ƒ  Z e e	 ƒ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d	 „ Z d d
 „ Z d „  Z e ƒ  d „  ƒ Z  e ƒ  d „  ƒ Z! e ƒ  d „  ƒ Z" e ƒ  d „  ƒ Z# e e	 ƒ e e	 e ƒ e e	 e e ƒ e e	 e e e ƒ e e$ e$ d „ ƒ ƒ ƒ ƒ Z% RS(   s*   
    Working directory changer widget
    t
   workingdirc         K   sì  t  r" t t |  ƒ j | |  n  t j |  | ƒ t j |  | ƒ |  j ƒ  |  j |  j ƒ  ƒ |  j	 |  j ƒ  ƒ g  |  _
 d  |  _ t |  d d  t j d ƒ t d ƒ d |  j ƒ|  _ |  j |  j ƒ t |  d d  t j d ƒ t d ƒ d |  j ƒ|  _ |  j |  j ƒ |  j j |  j j ƒ |  j j |  j j ƒ |  j d ƒ } t |  d | ƒ|  _ |  j j t d ƒ ƒ |  j j j |  j ƒ |  j j  t! j |  j ƒ |  j j" |  j d	 ƒ ƒ |  j# | ƒ } | d  k r"|  j d
 ƒ rït$ ƒ  } q"|  j d d d ƒ} t% j& | ƒ s"t$ ƒ  } q"n  |  j | ƒ |  j j' | ƒ |  j j( ƒ  |  j _) |  j* ƒ  |  j+ |  j ƒ t |  d d  t j d ƒ t d ƒ d |  j, ƒ} |  j | ƒ t |  d d  t j d ƒ t d ƒ d |  j- ƒ} |  j | ƒ d  S(   Nt   previoust   Backt	   triggeredt   nextt   Nextt   working_dir_adjusttocontentst   adjust_to_contentss¼   This is the working directory for newly
opened consoles (Python/IPython consoles and
terminals), for the file explorer, for the
find in files plugin and for new files
created in the editort   working_dir_historys%   console/use_project_or_home_directorys   console/fixed_directoryt   defaultR   t   browset   DirOpenIcons   Browse a working directoryt   parentt   ups   Change to parent directory(.   R    t   superR6   t   __init__R	   R   t   initialize_plugint   setWindowTitlet   get_plugin_titlet   setObjectNamet   historyt   Nonet	   histindexR   t   imat   iconR   t   previous_directoryt   previous_actiont	   addActiont   next_directoryt   next_actiont   set_previous_enabledR   R    t   set_next_enabledt
   get_optionR   t   patheditt
   setToolTipt   open_dirt   chdirt	   activatedt   strt   setMaxCountt   load_wdhistoryR   t   ospt   isdirt   addItemst   currentTextt   selected_textt   refresh_pluginR"   t   select_directoryt   parent_directory(   R'   RC   t   workdirt   kwdst   adjustt	   wdhistoryt   browse_actiont   parent_action(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyRF   k   s^    
		
c         C   s
   t  d ƒ S(   s   Return widget titles   Current working directory(   R   (   R'   (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyRI   ²   s    c         C   s   t  j d ƒ S(   s   Return widget iconRB   (   RN   RO   (   R'   (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyt   get_plugin_icon¶   s    c         C   s   d S(   s   Setup actionsN(   NN(   RL   (   R'   (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyt   get_plugin_actionsº   s    c         C   sb   |  j  j |  j j ƒ |  j j j j j |  j ƒ d } |  j t	 | | ƒ ƒ |  j j
 |  ƒ d S(   s'   Register plugin in Spyder's main windowi   N(   t   redirect_stdioR   t   maint   redirect_internalshell_stdiot   consolet   shellt   refreshRe   t   setIconSizeR   t
   addToolBar(   R'   t   iconsize(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyt   register_plugin¾   s
    c         C   s„   t  ƒ  } |  j j | ƒ |  j ƒ  |  j j |  j d k	 oG |  j d k ƒ |  j j |  j d k	 o| |  j t	 |  j
 ƒ d k  ƒ d S(   s   Refresh widgeti    i   N(   R   RX   t   add_textt   save_wdhistoryRU   t   emitRM   RL   RV   t   lenRK   (   R'   t   curdir(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyRe   Æ   s    	
	c         C   s   d S(   s*   Apply configuration file's plugin settingsN(    (   R'   t   options(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyt   apply_plugin_settingsÐ   s    c         C   s   t  S(   s3   Perform actions before parent main window is closed(   R   (   R'   t
   cancelable(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyt   closing_pluginÔ   s    c         C   s}   t  j |  j ƒ rX t j |  j ƒ \ } } g  | D] } t j j | ƒ r1 | ^ q1 } n! | d k rp t	 ƒ  } n  | g } | S(   s4   Load history from a text file in user home directoryN(
   R`   t   isfilet   LOG_PATHR   t	   readlinest   ost   pathRa   RL   R   (   R'   Rh   Rk   R   t   name(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyR_   Ù   s    .	c         C   si   g  t  |  j j ƒ  ƒ D] } t |  j j | ƒ ƒ ^ q } y t j | |  j ƒ Wn t k
 rd n Xd S(   s2   Save history to a text file in user home directoryN(	   t   rangeRX   t   countR   t   itemTextR   t
   writelinesR„   t   EnvironmentError(   R'   t   indext   text(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyR{   ä   s    7c         C   sX   |  j  j t ƒ t |  j t d  ƒ t ƒ  ƒ } | rD |  j | ƒ n  |  j  j t ƒ d S(   s   Select directoryN(	   Rp   R|   R   R   Rq   R   R   R[   R   (   R'   t	   directory(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyRf   í   s    c         C   s)   |  j  d 8_  |  j d d d t ƒ d S(   s   Back to previous directoryi   R   R   t   browsing_historyN(   RM   R[   R   (   R'   (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyRP   ÷   s    c         C   s)   |  j  d 7_  |  j d d d t ƒ d S(   s   Return to next directoryi   R   R   R‘   N(   RM   R[   R   (   R'   (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyRS   ý   s    c         C   s)   |  j  t j j t ƒ  t j j ƒ ƒ d S(   s,   Change working directory to parent directoryN(   R[   R†   R‡   t   joinR   t   pardir(   R'   (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyRg     s    c         C   s;  | r t  j t | ƒ ƒ } n  | r7 |  j |  j } n | |  j k r^ |  j j | ƒ |  _ nX |  j d k ry g  |  _ n |  j |  j d  |  _ |  j j | ƒ t |  j ƒ d |  _ yP t	 j
 | ƒ | rß |  j j | ƒ n  | rø |  j j | ƒ n  |  j j ƒ  Wn$ t k
 r,|  j j |  j ƒ n X|  j ƒ  d S(   s"   Set directory as working directoryi   N(   R`   t   abspathR   RK   RM   RŽ   RL   t   appendR}   R†   R[   t   set_explorer_cwdR|   t   set_current_console_wdt   refresh_findinfilest   OSErrort   popRe   (   R'   R   R‘   t   refresh_explorert   refresh_console(    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyR[     s*    N(&   R4   R5   t   __doc__t   CONF_SECTIONR   t   CONFIGWIDGET_CLASSR   R„   R   R]   t   objectt   sig_option_changedt   boolRU   RV   Rp   R–   R˜   R—   RL   RF   RI   Rn   Ro   Ry   Re   R€   R   R‚   R_   R{   R   Rf   RP   RS   Rg   R   R[   (    (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyR6   [   s>   	G					
			
	(*   R   R†   t   os.pathR‡   R`   t   qtpyR    t   qtpy.compatR   t   qtpy.QtCoreR   R   R   t   qtpy.QtWidgetsR   R   R   R   R	   R
   t   spyder.config.baseR   R   R   t   spyder.pluginsR   t   spyder.plugins.configdialogR   t   spyder.py3compatR   t   spyder.utils.miscR   t   spyder.utilsR   R   RN   t   spyder.utils.qthelpersR   t   spyder.widgets.comboboxesR   R   R6   (    (    (    s>   lib/python2.7/site-packages/spyder/plugins/workingdirectory.pyt   <module>   s"   .6