
    G@d(                        d Z ddlZddl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 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  ej        e           Z! G d d          Z" G d d          Z# G d d          Z$ G d de          Z% G d de          Z& G d de          Z' G d de          Z(dS )z
Working Directory widget.
    N)getexistingdirectory)QSizeSignalSlot)QSizePolicyQWidget)on_conf_change)_)PluginMainContainer)ApplicationToolbar)get_home_dir)getcwd_or_home)APP_TOOLBAR_STYLESHEET)PathComboBoxc                       e Zd ZdZdZdZdZdS )WorkingDirectoryActionsprevious_actionnext_actionbrowse_actionparent_actionN)__name__
__module____qualname__PreviousNextBrowseParent     Ilib/python3.11/site-packages/spyder/plugins/workingdirectory/container.pyr   r   &   s"         HDFFFFr   r   c                       e Zd ZdZdS )WorkingDirectoryToolbarSectionsmain_sectionN)r   r   r   Mainr   r   r    r"   r"   -   s        DDDr   r"   c                       e Zd ZdZdS )WorkingDirectoryToolbarItems
path_comboN)r   r   r   r   r   r   r    r&   r&   1   s        LLLr   r&   c                       e Zd ZdZdS )WorkingDirectoryToolbarworking_directory_toolbarN)r   r   r   IDr   r   r    r)   r)   7   s        	$BBBr   r)   c                   *     e Zd Z fdZd Zd Z xZS )WorkingDirectoryComboBoxc                     t                                          |dt          j        d           |                     d           d S )NFT)adjust_to_contentsid_
elide_text   )super__init__r&   r   setMinimumWidthselfparent	__class__s     r    r4   z!WorkingDirectoryComboBox.__init__=   sO    $,9	 	 	
 	
 	
 	S!!!!!r   c                 "    t          dd          S )z6Recommended size when there are toolbars to the right.i  
   )r   r7   s    r    sizeHintz!WorkingDirectoryComboBox.sizeHintH   s    S"~~r   c                 T    |                      |                                            dS )z7Set current path as the tooltip of the widget on hover.N)
setToolTipcurrentText)r7   events     r    
enterEventz#WorkingDirectoryComboBox.enterEventL   s&    ((**+++++r   )r   r   r   r4   r=   rB   __classcell__r9   s   @r    r-   r-   ;   sV        	" 	" 	" 	" 	"  , , , , , , ,r   r-   c                   "     e Zd ZdZ fdZ xZS )WorkingDirectorySpacerworking_directory_spacerc                     t                                          |           |                     t          j        t          j                   |                     t          t                               d S N)	r3   r4   setSizePolicyr   	Expanding	PreferredsetStyleSheetstrr   r6   s     r    r4   zWorkingDirectorySpacer.__init__T   s^        	;0+2GHHH 	356677777r   )r   r   r   r+   r4   rC   rD   s   @r    rF   rF   Q   s=        	#B8 8 8 8 8 8 8 8 8r   rF   c                      e Zd ZdZ ee          Z	 d Zd Z e	d          d             Z
d Z e            dd	            Z e            d
             Z e            d             Z e            d             Zd Z ee           eee           eeee          dd                                    Zd ZddZdS )WorkingDirectoryContainerz,Container for the working directory toolbar.c                    |                      dg           | _        d | _        t          d          }t	          | |          | _        t          |           | _        t          |           }| j        	                    |           | j        
                    |           | j                            |                      d                     | j                                        | j        _        | j        j                            | j                   | j        j        t$                                       | j                   |                     t(          j        t          d          t          d          |                     d          | j                  | _        |                     t(          j        t          d          t          d          |                     d          | j                  | _        |                     t(          j        t          d	          t          d	          |                     d
          | j                  }|                     t(          j        t          d          t          d          |                     d          | j                  }|| j        ||fD ])}|                      || j        tB          j"                   *d S )NhistoryzCurrent working directoryworking_dir_historyBackprevious)texttipicon	triggeredr   nextzBrowse a working directoryDirOpenIconzChange to parent directoryup)section)#get_confrR   	histindexr
   r)   toolbarr-   patheditrF   setWindowTitlesetObjectNamesetMaxCountr@   selected_textopen_dirconnectchdir	activatedrN   create_actionr   r   create_icon_previous_directoryr   r   _next_directoryr   r   _select_directoryr   _parent_directoryadd_item_to_toolbarr"   r$   )r7   titlespacerr   r   items         r    setupzWorkingDirectoryContainer.setupp   s   }}Y33 -...tU;;066'-- 	##E***""5)))!!$--0E"F"FGGG&*m&?&?&A&A# 	&&tz222$,,TZ888  $11#,6&		!!*--.  2  
  
  --#(6&		!!&))* . 
 
 **#*/00.//!!-00, + 
 
 **#*/00.//!!$'', + 
 
 T]M=I 	 	D$$7< %    	 	r   c                     | j                             | j        d uo
| j        dk               | j                            | j        d uo| j        t	          | j                  dz
  k                d S )Nr      )r   
setEnabledr_   r   lenrR   r<   s    r    update_actionsz(WorkingDirectoryContainer.update_actions   s    ''N$&=4>A+=	? 	? 	?##N$& 7T\!2!2Q!66	
 	
 	
 	
 	
r   rR   )optionc                     || _         d S rI   )rR   )r7   values     r    on_history_updatez+WorkingDirectoryContainer.on_history_update   s    r   c                 Z   t                      }|                     d          rt                      }nx|                     d          rc|                     d          }t          j        |          s:|                     dd           |                     dd           t                      }|S )z
        Get the working directory from our config system or return the user
        home directory if none can be found.

        Returns
        -------
        str:
            The initial working directory.
        z%startup/use_project_or_home_directoryzstartup/use_fixed_directoryzstartup/fixed_directoryTF)r   r^   ospisdirset_conf)r7   workdirs     r    _get_init_workdirz+WorkingDirectoryContainer._get_init_workdir   s     ..==@AA 		)"nnGG]]899 	)mm$=>>G 9W%% )EtLLL;UCCC&..r   Nc                     |^| j                             d           t          | t          d          t	                                }| j                             d           |r|                     |           dS dS )z
        Select working directory.

        Parameters
        ----------
        directory: str, optional
            The directory to change to.

        Notes
        -----
        If directory is None, a get directory dialog will be used.
        NFzSelect directoryT)sig_redirect_stdio_requestedemitr   r
   r   rh   )r7   	directorys     r    rn   z+WorkingDirectoryContainer._select_directory   s     -225999,$%%   I
 -224888 	"JJy!!!!!	" 	"r   c                 T    | xj         dz  c_         |                     dd           dS )zSelect the previous directory.rv    Tr   browsing_historyNr_   rh   r<   s    r    rl   z-WorkingDirectoryContainer._previous_directory   0     	!

R$
77777r   c                 T    | xj         dz  c_         |                     dd           dS )zSelect the next directory.rv   r   Tr   Nr   r<   s    r    rm   z)WorkingDirectoryContainer._next_directory   r   r   c                     |                      t          j        t                      t          j                             dS )z'Change working directory to parent one.N)rh   r   joinr   pardirr<   s    r    ro   z+WorkingDirectoryContainer._parent_directory   s0     	

38N,,cj99:::::r   c                 4    | j                                         S )z
        Get the current working directory.

        Returns
        -------
        str:
            The current working directory.
        )ra   r@   r<   s    r    get_workdirz%WorkingDirectoryContainer.get_workdir   s     }((***r   FTc                    |r!t          j        t          |                    }|r| j        | j                 }n|| j        v r | j                            |          | _        na| j        g | _        n| j        d| j        dz            | _        | j                            |           t          | j                  dz
  | _        	 t          	                    d|            t          j        |           | j                            |           |                                  |r| j                            |           dS dS # t"          $ r# | j                            | j                   Y dS w xY w)a  
        Set `directory` as working directory.

        Parameters
        ----------
        directory: str
            The new working directory.
        browsing_history: bool, optional
            Add the new `directory` to the browsing history. Default is False.
        emit: bool, optional
            Emit a signal when changing the working directory.
            Default is True.
        Nrv   zSetting cwd to )r   abspathrN   rR   r_   indexappendrx   loggerdebugosrh   ra   add_textry   sig_current_directory_changedr   OSErrorpop)r7   r   r   r   s       r    rh   zWorkingDirectoryContainer.chdir	  s   "  	4C	NN33I  	3T^4II$,&&!\//	::DNN~%!#|,?T^a-?,?@L	*** ..2DN		-LL6966777HYM""9---!!! C277	BBBBBC C 	- 	- 	-LT^,,,,,,	-s   A;E )E0/E0c                 h      fdt           j                                                  D             S )z
        Get the current history list.

        Returns
        -------
        list
            List of string paths.
        c                 ^    g | ])}t          j                            |                    *S r   )rN   ra   itemText).0r   r7   s     r    
<listcomp>z9WorkingDirectoryContainer.get_history.<locals>.<listcomp>@  s=     1 1 1uDM**51122 1 1 1r   )rangera   countr<   s   `r    get_historyz%WorkingDirectoryContainer.get_history7  sD    1 1 1 1,,..//1 1 1 	1r   c                 >   |                      d|           |r| j                            |           ||                                 }n>t                              d           |}t          j        |          st                      }| 	                    |           dS )z
        Set the current history list.

        Parameters
        ----------
        history: list
            List of string paths.
        cli_workdir: str or None
            Working directory passed on the command line.
        rR   Nz(Setting cwd passed from the command line)
r   ra   addItemsr   r   r   r   r   r   rh   )r7   rR   cli_workdirr   s       r    set_historyz%WorkingDirectoryContainer.set_historyC  s     	i))) 	,M""7+++,,..GGLLCDDD!G 9W%% )&..

7r   rI   )FT)r   r   r   __doc__r   rN   r   rt   ry   r	   r}   r   r   rn   rl   rm   ro   r   boolrh   r   r   r   r   r    rP   rP   `   s       66 %+F3KK!8 8 8t
 
 
 ^9%%%  &%
  2 
TVV" " " V"2 
TVV8 8 V8
 
TVV8 8 V8
 
TVV; ; V;	+ 	+ 	+ 
T#YY	T#t__	T#tT)- )- )-  _ Y)-V
1 
1 
1     r   rP   ))r   loggingr   os.pathpathr   qtpy.compatr   qtpy.QtCorer   r   r   qtpy.QtWidgetsr   r   spyder.api.config.decoratorsr	   spyder.api.translationsr
   !spyder.api.widgets.main_containerr   spyder.api.widgets.toolbarsr   spyder.config.baser   spyder.utils.miscr   spyder.utils.stylesheetr   spyder.widgets.comboboxesr   	getLoggerr   r   r   r"   r&   r)   r-   rF   rP   r   r   r    <module>r      s[   
  				       - , , , , , + + + + + + + + + + / / / / / / / / 8 7 7 7 7 7 % % % % % % A A A A A A : : : : : : + + + + + + , , , , , , : : : : : : 2 2 2 2 2 2 
	8	$	$
                             % % % % %0 % % %, , , , ,| , , ,,
8 
8 
8 
8 
8W 
8 
8 
8| | | | | 3 | | | | |r   