
    Jew*                     :   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jB                  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+        yy)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                 v   t        |       } t        j                         }|xj                  t        j                  z  c_        t        j
                  dj                  |       t        j                  t        j                  |      }|j                         \  }}t        |      }|j                          | |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         4/usr/lib/python3/dist-packages/spyder/app/restart.py_is_pid_running_on_windowsr+   )   s    
c(C ((*K::::;BB3G&0oo&0&7&7+68G %002J
J'JLLN:EL    c                 P    	 t        j                  | d       y# t        $ r Y y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   =   s/     	Q   s    	%%c                 T    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   I   s%     
ww$)#..&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                 .   t         t        |           g d| _        t	        |       | _        t               | _        | j                  d       | j                  j                          | j
                  j                  j                  | j                         y )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__W   sm    i')9 %Tl*, 	##++D,A,ABr,   c                     | j                   j                  |t        t        j                  t        j
                  z  t        j                  z        t        t        j                               y)zShow message on splash screen.N)	r?   showMessageintr   AlignBottomAlignCenterAlignAbsoluter   white)rE   texts     r*   _show_messagezRestarter._show_messagee   sG     #BNNR^^$C$&$4$4%5 !6 &rxx 0	2r,   c                     | j                   j                  d      }dt        |      z  | j                  z   |z   }| j                   j	                  |       | j                  |       y)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_ellipsisl   sT    ==$$Q'S]"T%5%55@X&4 r,   c                     || _         | j                  |       | j                  j                  d       t	        d      D ]+  }t        j                  d       t        j                          - y)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_messages   sY    4 !!#& ) 	)BJJt&&(	)r,   c                    t         t        d      t        t        d      t        t        d      i}t         t        d      t        t        d      t        t        d      i}|r(|j	                         }||   dj                  |      z   }n||   }||   }| j                  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 $A "B!1 &: $;	< q!45q!56#9!:<  Az*Y-=-=a-@@Gz*Gz"D%+..A7##r,   )N)
__name__
__module____qualname____doc__r<   rO   rD   r^   ro   __classcell__)rF   s   @r*   r6   r6   R   s"    C2!
)$r,   r6   c            	      
   t         j                  j                         } t        j                  dd      r`t        t        j                  dd            }t        t        d |j                  d                  }t        |      dk(  r	|d   | d<   n|| d<   n
d	| d<   d	| d<   t               }t               }t        t        d
            }|j                  |       |j                  t!        d             | j#                  dd       }| j#                  dd       }| j#                  dd       }| j#                  dd      }	t%        j&                  t%        j&                  t%        j&                  t%        j(                  t*                                }
t-        ||||	g      sd}t/        |      t1        j2                  |      }t1        j2                  |      }t1        j2                  |      }t1        j2                  |	      }	d|v r|j5                  d       dD ]  }d| }||v s|j5                  |        d|vr|rd|vr|ddgz   }n|j7                  d       d|v rddg}ndg}t9        t:        j<                        r| d   }d| dg}nt?               rOt%        j&                  |
      }t%        j@                  |dd      }t%        j@                  |d      }d| dd| dg}nK|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 nEtM        jN                  tH               tQ        jR                          > |jU                  tV        "       |	r|j                  t!        d#             	 tY        jZ                  d$jA                  ||z         || %      }|j]                          |j^                  }d'}tE        tG        |tH        z              D ]<  }tK              s nVtM        jN                  tH               tQ        jR                          > 	 je                          |jU                  tb        "       |j                  t!        d(             	 tY        jZ                  d$jA                  ||z         || %       y # t`        $ r!}|jU                  tb        |&       Y d }~d }~ww xY w# tf        $ r!}|jU                  tb        |&       Y d }~d }~ww xY w# t`        $ r!}|jU                  th        |&       Y d }~y 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      s   
 **//
Cxx67dhhv'FGHgmmC012q6Q;%&qTC!"-4C)*!#)+%&
 .CI^H-.Hh  #3!45 ''-.K
'',
%C770$7LGGNG,E S[[S[[5J)KLMJS,67N5!! ##L1L


3
CK(DU#E DI' eW%$;KK t#D,4!122DKK() t|I&
[
 #..)"#se1:,	"{{:6"6-P"68KL~&a(An-=Q*?@XXj.9FXXj(E:FFs~~&a(AfXQ-8 NE
 !bIY345 ?c"

:""$	? 	&&+&> $$Q'E%FG	  'J*>!?',#7A
 MMOI
 	SZ!789 	GG!),JJz"&&(		GG
 ..+.F   <1N'D.1CH;  	P**k*OO	P&  <..+5: / < <<  N&&-u&MMNsH   
*S -T .*T3 	T"S>>T	T0T++T03	U<UU__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 @ @ : , / & WW_

*3 '[-(	,J$ J$ZMN` zF r,   