
    G@d*                     D   d Z ddlZddlZddlmZ ddlZddlZddlZddl	m
Z
m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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    Z"dZ#g d\  Z$Z%Z&d Z'd Z(d Z) G d de          Z*d Z+e,dk    r e+             dS dS )zu
Restart Spyder

A helper script that allows to restart (and also reset) Spyder from within the
running application.
    N)QtQTimer)QColorQIcon)QApplicationQMessageBoxQWidget)create_splash_screen)_running_in_mac_app
is_pynsist)get_image_path)
to_unicode)qapplication)CONFntg?)         c                 x   t          |           } t          j                    }|xj        t          j        z  c_        t          j        d                    |           t          j        t          j        |          }|	                                \  }}t          |          }|                                 | |v }|S )zBCheck if a process is running on windows systems based on the pid.ztasklist /fi "PID eq {0}")stdoutstderrstartupinfo)str
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWPopenformatPIPESTDOUTcommunicater   kill)pidr   process
stdoutdata
stderrdatachecks         2lib/python3.11/site-packages/spyder/app/restart.py_is_pid_running_on_windowsr+   *   s    
c((C (**K:::;BB3GG&0o&0&7+68 8 8G %0022J
J''JLLNNN:EL    c                 T    	 t          j        | d           dS # t          $ r Y dS w xY w)z?Check if a process is running on unix systems based on the pid.r   TF)osr$   OSErrorr%   s    r*   _is_pid_running_on_unixr1   >   sC     	Q t    uus    
''c                 ^    t           j        dk    rt          |           S t          |           S )z/Check if a process is running based on the pid.r   )r.   namer+   r1   r0   s    r*   is_pid_runningr4   J   s+     
w$)#...&s+++r,   c                   <     e Zd ZdZ fdZd Zd Zd ZddZ xZ	S )		Restarterz`Widget in charge of displaying the splash information screen and the
       error messages.
    c                 Z   t          t          |                                            g d| _        t	          |           | _        t                      | _        |                     d           | j        	                                 | j        j
                            | j                   d S )N) ...z...r:   r9   F)superr6   __init__ellipsisr   timer_ellipsisr
   splash
setVisibleshowtimeoutconnectanimate_ellipsis)self	__class__s    r*   r<   zRestarter.__init__X   s    i'')))999 %Tll*,, 	#++D,ABBBBBr,   c                     | j                             |t          t          j        t          j        z  t          j        z            t          t          j                             dS )zShow message on splash screen.N)	r?   showMessageintr   AlignBottomAlignCenterAlignAbsoluter   white)rE   texts     r*   _show_messagezRestarter._show_messagef   sX     #BNR^$C$&$4%5 !6 !6 &rx 0 0	2 	2 	2 	2 	2r,   c                     | j                             d          }dt          |          z  | j        z   |z   }| j                             |           |                     |           dS )z5Animate dots at the end of the splash screen message.r    N)r=   poplensplash_textappendrO   )rE   r=   rN   s      r*   rD   zRestarter.animate_ellipsism   sd    =$$Q''S]]"T%55@X&&&4     r,   c                     || _         |                     |           | j                            d           t	          d          D ])}t          j        d           t          j                     *dS )z1Sets the text in the bottom of the Splash screen.i  (   gQ?N)	rT   rO   r>   startrangetimesleepr   processEvents)rE   rN   __s      r*   set_splash_messagezRestarter.set_splash_messaget   sx    4   !!#&&& )) 	) 	)BJt&((((	) 	)r,   Nc                    t           t          d          t          t          d          t          t          d          i}t           t          d          t          t          d          t          t          d          i}|r3|                                }||         d                    |          z   }n||         }||         }| j                                         t          j	        | ||t          j
                   t          |          )a7  Launch a message box with a predefined error message.

        Parameters
        ----------
        error_type : int [CLOSE_ERROR, RESET_ERROR, RESTART_ERROR]
            Possible error codes when restarting/resetting spyder.
        error : Exception
            Actual Python exception error caught.
        zKIt was not possible to close the previous Spyder instance.
Restart aborted.z<Spyder could not reset to factory defaults.
Restart aborted.z9It was not possible to restart Spyder.
Operation aborted.zSpyder exit errorzSpyder reset errorzSpyder restart errorz

{0})CLOSE_ERRORr   RESET_ERRORRESTART_ERROR__repr__r    r?   hider   warningOkRuntimeError)rE   
error_typeerrormessagestitlesemessagetitles           r*   launch_error_messagezRestarter.launch_error_message   s      $H "I "I $A "B "B!1 &: $; $;	< q!455q!566#9!:!:<  	+  Az*Y-=-=a-@-@@GGz*Gz"D%+.AAA7###r,   )N)
__name__
__module____qualname____doc__r<   rO   rD   r^   ro   __classcell__)rF   s   @r*   r6   r6   S   s         C C C C C2 2 2! ! !
) 
) 
)$ $ $ $ $ $ $ $r,   r6   c            	         t           j                                        } t          j        dd          rwt          t          j        dd                    }t          t          d |                    d                              }t          |          dk    r|d         | d<   n|| d<   n
d	| d<   d	| d<   t                      }t                      }t          t          d
                    }|                    |           |                    t!          d                     |                     dd           }|                     dd           }|                     dd           }|                     dd          }	t%          j        t%          j        t%          j        t%          j        t*                                                  }
t-          ||||	g          sd}t/          |          t1          j        |          }t1          j        |          }t1          j        |          }t1          j        |	          }	d|v r|                    d           dD ] }d| }||v r|                    |           !d|vr#|rd|vr|ddgz   }n|                    d           d|v rddg}ndg}t9          t:          j                  r| d         }d| dg}nt?                      rLt%          j        |
          }t%          j         |dd          }t%          j         |d          }d| dd| dg}nE|rt%          j         |
d          }nt%          j         |
d
dd          }dt:          j         dd| dg}tB           }tB          rd nd!}tE          tG          |tH          z                      D ]?}tK          |          s nHtM          j'        tH                     tQ          j)                     @|*                    tV          "           |	ri|                    t!          d#                     	 tY          j-        d$                     ||z             || %          }|.                                 |j/        }n3# t`          $ r&}|*                    tb          |&           Y d }~nd }~ww xY wd'}tE          tG          |tH          z                      D ]?}tK          |          s ntM          j'        tH                     tQ          j)                     @	 |2                                 |*                    tb          "           n3# tf          $ r&}|*                    tb          |&           Y d }~nd }~ww xY w|                    t!          d(                     	 tY          j-        d$                     ||z             || %           d S # t`          $ r'}|*                    th          |&           Y d }~d S d }~ww xY w))Nmainhigh_dpi_custom_scale_factorhigh_dpi_custom_scale_factors;r   r   QT_SCALE_FACTORQT_SCREEN_SCALE_FACTORSr8   spyderzClosing SpyderSPYDER_ARGS
SPYDER_PIDSPYDER_IS_BOOTSTRAPSPYDER_RESETFalsez<This script can only be called from within a Spyder instancez--debug)minimalverbosez--debug-info=z--new-instancez--z--resetEXECUTABLEPATH"Pythonzpythonw.exezSpyder.launch.pywzbootstrap.pyappzstart.pyZ      )rh   zResetting Spyder to defaultsrQ   )shellenv)rh   ri      
Restarting)5r.   environcopyr   getr   listfiltersplitrS   r   r6   r   r   setWindowIconr^   r   rR   ospdirnameabspath__file__anyrg   astliteral_evalremoverU   r   sys
executabler   join
IS_WINDOWSrY   rI   
SLEEP_TIMEr4   rZ   r[   r   r\   ro   r`   r   r   r#   r%   	Exceptionra   r$   r/   rb   )r   factorsfr   	restarterAPP_ICONspyder_argsr%   is_bootstrapreset
spyder_dirri   argslevelarg
args_resetexecommandpynsist_installationpynsist_pythonpynsist_scriptscriptr   	wait_timecounterp	pid_resets                              r*   rv   rv      sl   
 *//

Cx677 	,dhv'FGGHHgmmC001122q66Q;;%&qTC!""-4C)**!#)+%&
 ..CI^H--..Hh  #3!4!4555 ''-..K
'',
%
%C770$77LGGNG,,E S[S[5J5J)K)KLLMMJS,677 "N5!!! #L11L

3

CK((DU##E DI'  %e%%$;;KK t## 	*D,,4!122DDKK())) t||I&

[
 #.)) 9"#s:::,	 9"{:66"6-PP"68KLL(~(((*?n*?*?*?@ 	GXj.99FFXj(E:FFF(s~(((-f---8 NE
 !(bIY34455 ? ?c"" 	E
:"$$$$ 	&&+&>>>  G$$Q'E%F%FGGG	 'J*>!?!?',#7 7 7A
 MMOOOII	  	P 	P 	P**k*OOOOOOOO	P 	SZ!78899 	G 	GG!),, Jz"""&((((G
 ..+.FFFF	  < < <..+5: / < < < < < < < <<   <111N'D.11CHHHHHH N N N&&-u&MMMMMMMMMNsH   .-Q7 7
R'R""R'U 
U1U,,U1-W 
W7W22W7__main__)-rs   r   r.   os.pathpathr   r   r   rZ   qtpy.QtCorer   r   
qtpy.QtGuir   r   qtpy.QtWidgetsr   r   r	   spyder.app.utilsr
   spyder.config.baser   r   r   spyder.utils.image_path_managerr   spyder.utils.encodingr   spyder.utils.qthelpersr   spyder.config.managerr   r3   r   r   r`   ra   rb   r+   r1   r4   r6   rv   rp    r,   r*   <module>r      s    


 				           



  # " " " " " " " $ $ $ $ $ $ $ $ = = = = = = = = = = 2 1 1 1 1 1 @ @ @ @ @ @ @ @ @ @ : : : : : : , , , , , , / / / / / / & & & & & & W_

*3)) '[-  (	 	 	, , ,J$ J$ J$ J$ J$ J$ J$ J$ZMN MN MN` zDFFFFF r,   