
    G@d                         d Z ddlZddlmZ ddlZddlmZmZ ddl	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  G d
 de
          ZdS )zMain interpreter status widget.    N)QTimerSignal)BaseTimerStatus)
is_pynsistrunning_in_mac_app)get_list_conda_envs)get_interpreter_info)get_list_pyenv_envs)WorkerManagerc                        e Zd ZdZdZdZ e            Z	 d fd	Zd Z	 fdZ
d Zd	 Zd
 Zd Zd Zd Zd ZddZ xZS )InterpreterStatus?Status bar widget for displaying the current conda environment.interpreter_statusmain_interpreterNc                 h   || _         t                                          |           || _        g | _        i | _        i | _        d| _        t          j	        | _
        t                      r2| j
                            dd                                          | _
        t          d          | _        t!          |           | _        | j                            d           | j        j                            | j                   | j                                         |                                  dS )r    zpythonw.exez
python.exe   )max_threadsi`  N)_interpretersuper__init__mainenv_actionspath_to_envenvsvaluesys
executabledefault_interpreterr   replacelowerr   _worker_managerr   _get_envs_timersetIntervaltimeoutconnectget_envsstart)selfparenticoninterpreter	__class__s       Mlib/python3.11/site-packages/spyder/plugins/maininterpreter/widgets/status.pyr   zInterpreterStatus.__init__%   s   '   		
#&> << 	5 (,'?'G'G|(- (--2UWW $  -;;;  &d||((///$,,T];;;""$$$ 	    c                    |                      | j                  }t          j        |          s|                                  nt          j        | j                  sQt          j        t          j        |d                    s|                                  n7|                                  n"| j        | j        v r| 	                                 | j
        S )z{
        Switch to default interpreter if current env was removed or
        update Python version of current one.
        z
conda-meta)_get_env_dirr   ospisdir_on_interpreter_removedisfilejoinr'   r   update_interpreterr   )r)   env_dirs     r.   	get_valuezInterpreterStatus.get_valueC   s    
 ##D$566y!! 	*((****D-.. 	* 9SXg|<<==  ,,....   D$444'')))zr/   c                     | j                                          | j                                         t	                                          |           d S N)r#   stopr"   terminate_allr   
closeEvent)r)   eventr-   s     r.   r>   zInterpreterStatus.closeEvent`   sK    !!###**,,,5!!!!!r/   c                     t           j        dk    rt          j        |          S t          j        t          j        |                    S )z.Get env directory from interpreter executable.nt)osnamer2   dirnamer)   r,   s     r.   r1   zInterpreterStatus._get_env_dirf   s7    7d??;{+++;s{;77888r/   c                     | j         | j        vr|                     | j                    t                      }t	                      }i ||S )z+Get the list of environments in the system.)r   r   _get_env_infor   r
   )r)   	conda_env	pyenv_envs      r.   	_get_envszInterpreterStatus._get_envsm   sT    
 #4+;;;t7888 ())	'))	)))y))r/   c                 z   t           j        dk    r|                                n|}	 | j        |         }no# t          $ rb | j        |k    rt                      st                      rd}nd|v rd}n	d|v rd}nd}t          |          }|| j        |<   ||f| j	        |<   Y nw xY w| j	        |         \  }}| d| dS )zGet environment information.rA   internalcondapyenvcustomz ())
rB   rC   r!   r   KeyErrorr   r   r   r	   r   )r)   pathrC   version__s        r.   rG   zInterpreterStatus._get_env_infoz   s    !w$tzz|||D	.#D)DD 	. 	. 	.(D00')) 1-7\\ 1 "DD*400G%)DT"#WoDIdOOO	.  ioG$$'$$$$s   6 A)B"!B"c                     |                      dd           |                      dd           |                      dd           dS )zh
        Actions to take when the current custom interpreter is removed
        outside Spyder.
        custom_interpreter rO   FdefaultTN)set_confr)   s    r.   r4   z)InterpreterStatus._on_interpreter_removed   sG     	*C000h&&&i&&&&&r/   c                     | j                                          | j                             | j                  }|j                            | j                   |                                 dS )z[
        Get the list of environments in a thread to keep them up to
        date.
        N)r"   r=   create_python_workerrJ   sig_finishedr&   update_envsr(   )r)   workers     r.   r'   zInterpreterStatus.get_envs   s\    
 	**,,,%::4>JJ##D$4555r/   c                 (   | | j         j        di | t          | j                                                   D ]B}| j         |         \  }}t          j        dk    r|                                n|}|| j        |<   C|                                  dS )z.Update the list of environments in the system.NrA    )	r   updatelistkeysrB   rC   r!   r   r7   )r)   r_   outputerrorenvrR   rS   s          r.   r^   zInterpreterStatus.update_envs   s    
 DI&&v&&&	(()) 	) 	)C IcNMD' $&7d??4::<<<D%(DT""!!!!!r/   c                 8    | j                                          dS )z1Request to open the main interpreter preferences.N)sig_open_preferences_requestedemitrZ   s    r.   open_interpreter_preferencesz.InterpreterStatus.open_interpreter_preferences   s    +0022222r/   c                     |r|| _         |                     | j                   | _        |                     | j                   dS )z,Set main interpreter and update information.N)r   rG   r   	set_valuerE   s     r.   r7   z$InterpreterStatus.update_interpreter   sD     	, +D''(9::
tz"""""r/   )NNr;   )__name__
__module____qualname____doc__IDCONF_SECTIONr   ri   r   r9   r>   r1   rJ   rG   r4   r'   r^   rk   r7   __classcell__)r-   s   @r.   r   r      s       II	B%L%+VXX"     <  :" " " " "9 9 9* * *% % %2' ' '  " " ""3 3 3# # # # # # # #r/   r   )rq   rB   os.pathrR   r2   r   qtpy.QtCorer   r   spyder.api.widgets.statusr   spyder.config.baser   r   spyder.utils.condar   spyder.utils.programsr	   spyder.utils.pyenvr
   spyder.utils.workersr   r   ra   r/   r.   <module>r}      s    & % 
			       



 ' & & & & & & & 6 5 5 5 5 5 = = = = = = = = 2 2 2 2 2 2 6 6 6 6 6 6 2 2 2 2 2 2 . . . . . .k# k# k# k# k# k# k# k# k# k#r/   