
    G@dOd                        d Z ddlZddlZddlZddlZddlmZmZ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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 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+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4  G d d          Z5 G d d          Z6 G d d          Z7 G d de          Z8dS )zT
Container Widget.

Holds references for base actions in the Application of Spyder.
    N)QtQThreadQTimerSignalSlot)QGuiApplication)QActionQMessageBoxQPushButton)__docs_url____forum_url____trouble_url____version__)dependencies)_)PluginMainContainer)InstallerMissingDependencies)is_anaconda)get_conf_pathget_debug_level
is_pynsistrunning_in_mac_app)ApplicationUpdateStatus)ConsoleActions)UserEnvDialog)
start_fileDialogManager)AboutDialog)DependenciesDialog)MessageCheckBox)WorkerUpdatesc                       e Zd ZdZdS )ApplicationPluginMenusdebug_logs_menuN)__name__
__module____qualname__DebugLogsMenu     Dlib/python3.11/site-packages/spyder/plugins/application/container.pyr#   r#   +   s        %MMMr*   r#   c                       e Zd ZdZdZdS )LogsMenuSectionsspyder_log_sectionlsp_logs_sectionN)r%   r&   r'   SpyderLogSectionLSPLogsSectionr)   r*   r+   r-   r-   /   s        +'NNNr*   r-   c                   6    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdS )ApplicationActionszspyder documentation!spyder_documentation_video_actionspyder_troubleshooting_actionspyder_dependencies_actionspyder_check_updates_actionspyder_support_actionspyder_about_action spyder_user_env_variables_actionRestartRestart in debug modeN)r%   r&   r'   SpyderDocumentationActionSpyderDocumentationVideoActionSpyderTroubleshootingActionSpyderDependenciesActionSpyderCheckUpdatesActionSpyderSupportActionSpyderAboutSpyderUserEnvVariablesSpyderRestartSpyderRestartDebugr)   r*   r+   r3   r3   5   sQ        
 !7%H""A;<1'K @
 M0r*   r3   c                       e Zd Z e            Z	  ee          Z	 d fd	Zd Zd Z	d Z
 e            d             Z e            d             Zd Z e            dd
            Z ee          d             Z e            d             Zd Zd Z e            d             Z e            d             Z e            d             Zd Zd Zd Zd Zd Zd Z xZS )ApplicationContainerNc                 x    t                                          |||           d | _        d | _        d | _        d S N)super__init__current_dpidpi_messageboxinstaller_path)selfnamepluginparent	__class__s       r+   rL   zApplicationContainer.__init__X   sA    vv...  " #r*   c           
      |	   t          d           | _        t                      | _        d | _        t                      st                      rvt          |           | _        | j        j        	                    | j
                   | j        j        	                    | j                   | j                                         d| _        d | _        d | _        d | _        |                     t&          j        t+          d          |                     d          d t.          j        dd          | _        d	|                     t&          j        t+          d
          |                     d          fd          | _        |                     t&          j        t+          d          d           | _        |                     t<          j        t+          d          |                     d          | j                   | _!        |                     t&          j"        t+          d          | j#        |                     d                    | _$        |                     t&          j%        t+          d          | j
                  | _&        |                     t&          j'        t+          d          d           | _(        |                     t&          j)        t+          d          dz  |                     d          | j*        tV          j,                  | _-        t\          j/        dk    rt+          d          }nt+          d           }|                     t&          j0        t+          d!          |                     d"          || j1        #          | _2        |                     t&          j3        t+          d$          |                     d%          t+          d&          | j4        t.          j        dd'          | _5        |                     t&          j6        t+          d(          t+          d)          | j7        t.          j        dd*          | _8        ts                      d+k    rX| :                    tv          j<        t+          d,                    | _=        | j=        j>        	                    | j?                   d S d S )-N)rS   FzSpyder documentationDialogHelpButtonc                  *    t          t                    S rJ   )r   r   r)   r*   r+   <lambda>z,ApplicationContainer.setup.<locals>.<lambda>   s    j66 r*   Tr   )texticon	triggeredcontextregister_shortcutshortcut_contextzHhttps://www.youtube.com/playlist?list=PLPonohdiDqg9epClEcXoAPUiK0pN5eRoczTutorial videos	VideoIconc                  "    t                     S rJ   )r   )spyder_video_urls   r+   rX   z,ApplicationContainer.setup.<locals>.<lambda>   s    j)9:: r*   )rY   rZ   r[   zTroubleshooting...c                  *    t          t                    S rJ   )r   r   r)   r*   r+   rX   z,ApplicationContainer.setup.<locals>.<lambda>   s    j99 r*   )r[   zReport issue...bug)rZ   r[   zDependencies...advanced)r[   rZ   zCheck for updates...zSpyder support...c                  *    t          t                    S rJ   )r   r   r)   r*   r+   rX   z,ApplicationContainer.setup.<locals>.<lambda>   s    j77 r*   zAbout %s...SpyderMessageBoxInformation)rZ   r[   menurolentz\Show and edit current user environment variables in Windows registry (i.e. for all sessions)z?Show current user environment variables (i.e. for all sessions)z%Current user environment variables...environment)rZ   tipr[   z&Restartrestartr;   )rZ   rk   r[   r\   r^   r]   z&Restart in debug moder<   )rk   r[   r\   r^   r]      z
Debug logs)@r   dependencies_threadr   dialog_managerapplication_update_statusr   r   r   sig_check_for_updates_requestedconnectcheck_updatessig_install_on_close_requestedset_installer_pathset_no_statusgive_updates_feedbackthread_updatesworker_updatesupdates_timercreate_actionr3   r=   r   create_iconr   ApplicationShortcutdocumentation_actionr>   video_actionr?   trouble_actionr   SpyderReportActionsig_report_issue_requestedreport_actionr@   show_dependenciesdependencies_actionrA   check_updates_actionrB   support_group_actionrC   
show_aboutr	   	AboutRoleabout_actionosrQ   rD   show_user_env_variablesuser_env_actionrE   restart_normalrestart_actionrF   restart_debugrestart_debug_actionr   create_menur#   r(   menu_debug_logsaboutToShowcreate_debug_log_actions)rP   rk   ra   s     @r+   setupzApplicationContainer.setupd   s    $+4==  ,oo)-&<< 	;-// 	;-D. . .D*+Kgd()))+J'$1222*88:::%*"""! %)$6$68)**!!"45566*"  %7 %" %"!G ..=$%%!!+..::::	 / < < #00:"##99 1 ; ; "//-  !!%((5	 0 7 7
 $(#5#57  ,!!*--	 $6 $/ $/ 
 %)$6$67$%%( %7 %* %*! %)$6$62!""77 %7 %9 %9! !..*mx'!!"9::o& / ( ( 7d?? ? @ @CC    ! !C#115566!!-002  2  4  4 #00,jMM!!),,))* " 1 $ $ %)$6$61&'')**(* " %7 %$ %$! !!#'#3#3&4,$ $D   ,44-/ / / / / "!r*   c                     d S rJ   r)   rP   s    r+   update_actionsz#ApplicationContainer.update_actions   s    r*   c                    | j                                          | j        | j                                         | j        2| j                                         | j                                         | j        2| j                                         | j                                         t          j	        dk    rdnd}| j
        r2t          j        d                    || j
        g          d           dS dS )z.To call from Spyder when the plugin is closed.Nri   startopen T)shell)ro   	close_allrz   stoprx   quitwaitrn   r   rQ   rO   
subprocessPopenjoin)rP   cmds     r+   on_closezApplicationContainer.on_close   s    %%''')##%%%*$$&&&$$&&&#/$))+++$))+++ 'T//wwv 	OSXXsD,?&@AANNNNNN	O 	Or*   c                 L    t          |           }|                                 dS )zShow Spyder About dialog.N)r   show)rP   abts     r+   r   zApplicationContainer.show_about   s"     $




r*   c                 T    | j                             t          |                      dS )z0Show Windows current user environment variables.N)ro   r   r   r   s    r+   r   z,ApplicationContainer.show_user_env_variables   s)     	  t!4!455555r*   c                 l   | j         }| j        j        }| j        j        }| j        j        }t
          j        dk    rd}nd}d}t          t          j	        |           }|
                    t          d                     |                    t          j                   |                    t          d                     |                    t          j                   |                    t          j                   d}|                     |          }	|                    |	           |V|}
|                    |
           |                    d
           |                                 |                                }	nz|r| j        r| j                            |           t          d                              |t8                    }d}t          d                              |          }t;                      r#t          d                              |          }nWt=                      st?                      r;|                    t          j         t          j!        z             t          d          }||z   |z   }
|                    |
           |                    d           |                                 | j        r{|"                                t          j         k    r| j        #                    |           n=|"                                t          j!        k    r| j                            |           |                                }	n|rt          d          }
|                    |
           |                    d
           |                                 |                                }	| j        r| j        $                                 n | j        r| j        $                                 | %                    ||	           | j&        '                    d
           d| _         d	S )z3Show results of the Spyder update checking process.darwinzHhttps://github.com/spyder-ide/spyder/releases/latest/download/Spyder.dmgzShttps://github.com/spyder-ide/spyder/releases/latest/download/Spyder_64bit_full.exez-https://docs.spyder-ide.org/installation.htmlrZ   rS   zNew Spyder versionzCheck for updates at startupcheck_updates_on_startupNF)latest_releasez;<b>Spyder {} is available!</b> <i>(you have {})</i><br><br> zDFor more information, visit our <a href="{}">installation guide</a>.a,  <b>Important note:</b> Since you installed Spyder with Anaconda, please <b>don't</b> use <code>pip</code> to update it as that will break your installation.<br><br>Instead, run the following commands in a terminal:<br><code>conda update anaconda</code><br><code>conda install spyder={}</code><br><br>z@Would you like to automatically download and install it?<br><br>TzSpyder is up to date.)(rw   ry   update_availabler   errorsysplatformr    r
   InformationsetWindowTitler   setAttributer   WA_ShowWithoutActivatingset_checkbox_textsetStandardButtonsOksetDefaultButtonget_confset_checkedsetTextset_check_visibleexec_
is_checkedrp   set_status_pendingformatr   r   r   r   YesNoresultstart_installationrv   set_confr   setDisabled)rP   feedbackr   r   	error_msgurl_rurl_iboxoptionrs   msgheadercontentfooters                 r+   _check_updates_readyz)ApplicationContainer._check_updates_ready   s5    -  .?,;'-	 <8##+EE6E? ;#:%)+ + +11223334555a >??@@@{~...[^,,, ,f--&&& CKK!!%(((IIKKKNN,,MM 6C1 72EE'5 F 7 7 7  : ; ;;A6"K<1 <1  =  &--  == G	 	 f^,, G  \\ %7%9%9 **;?+6>,: ; ; ;. G
 w&/C   %%d+++		1 ;zz||{666II+9 J ; ; ; ;776II+9 J ; ; ; # 0 0 
C/00C   %%e,,,		 # 0 01 C2@@BBB1 C2@@BBBfm,,, 	!--e444 &*"""r*   Fc                 ~   | j                             d           | j        r| j                                         | j        2| j                                         | j                                         t          d          | _        t          | |          | _	        | j	        j
                            | j                   | j	        j
                            | j        j                   | j	                            | j                   | j        j                            | j	        j                   t!          |           | _        | j                            d           | j                            d           | j        j                            | j        j                   | j                                         dS )z<Check for spyder updates on github releases using a QThread.TN)startupi`  )r   r   rp   set_status_checkingrx   r   r   r   r!   ry   	sig_readyrr   r   moveToThreadstartedr   r   rz   setIntervalsetSingleShottimeout)rP   r   s     r+   rs   z"ApplicationContainer.check_updatesi  s    	!--d333) 	A*>>@@@*$$&&&$$&&&%dmm+D'BBB%--d.GHHH%--d.A.FGGG(()<===#++D,?,EFFF
 $D\\&&u---((..."**4+>+DEEE  """""r*   c                     || _         dS )z5Set installer executable path to be run when closing.N)rO   )rP   rO   s     r+   ru   z'ApplicationContainer.set_installer_path  s     -r*   c                     t           j        st          j                     t          |           }|                    t           j                   |                                 dS )z Show Spyder Dependencies dialog.N)r   DEPENDENCIESdeclare_dependenciesr   set_datar   )rP   dlgs     r+   r   z&ApplicationContainer.show_dependencies  sQ    
 ( 	0-/// &&\.///




r*   c                 P    	 t          j                     dS # t          $ r Y dS w xY w)z$Compute dependencies without errors.N)r   r   
ValueErrorr   s    r+   _compute_dependenciesz*ApplicationContainer._compute_dependencies  s>    
	-///// 	 	 	DD	s    
%%c                 R   | j         | j        _        | j        j                            | j                   t          |           }|                    d           |                    d           |j	                            | j        j
                   |
                                 dS )zCompute dependencies.i'  TN)r   rn   runfinishedrr   report_missing_dependenciesr   r   r   r   r   )rP   dependencies_timers     r+   compute_dependenciesz)ApplicationContainer.compute_dependencies  s    '+'A $ )11,	. 	. 	. $D\\&&u---((..."**4+C+IJJJ  """""r*   c                    t          j                    }|rVt          |           |                    dd                              dd                              dd          }t	          d          |z  }t          |           }|                    t
          j                   |                    t          j
                   |                    t          j                   |                    t
          j                   |                    t          j                   |                    t	          d                     |                    |           |                                 dS dS )z<Show a QMessageBox with a list of missing hard dependencies.z<br>
<z&lt;a  <b>You have missing dependencies!</b><br><br><tt>%s</tt><br><b>Please install them to avoid this message.</b><br><br><i>Note</i>: Spyder could work without some of these dependencies, however to have a smooth experience when using Spyder we <i>strongly</i> recommend you to install all the listed missing dependencies.<br><br>Failing to install these dependencies might result in bugs. Please be sure that any found bugs are not the direct result of missing dependencies, prior to reporting a new issue.ErrorN)r   missing_dependenciesr   replacer   r
   setIconCriticalr   r   WA_DeleteOnCloser   r   r   setWindowModalityNonModalr   r   r   )rP   missing_depsmessagemessage_boxs       r+   r   z0ApplicationContainer.report_missing_dependencies  sS    $8:: !	(666
 )00>>#GC00v1F1F      ##   &d++K 4555$$R%8999$$R%@AAA**;>:::))"+666&&qzz222(((C!	 !	r*   c                 V    dt           j        d<   | j                                         dS )zRestart in standard mode.r   SPYDER_DEBUGN)r   environsig_restart_requestedemitr   s    r+   r   z#ApplicationContainer.restart_normal  s+     &(
>""'')))))r*   c                    t          |           }|                    t          d                     |                    t           j                   |                    t          d                     t          t          d                    }t          t          d                    }|                    |t           j                   |                    |t           j                   |	                    t           j
                   |                                 |                                |k    rdt          j        d<   n*|                                |k    rdt          j        d<   ndS | j                                         dS )	zRestart in debug mode.Questionz2Which debug mode do you want Spyder to restart in?VerboseMinimal2r   3N)r
   r   r   r   r  r   r   	addButton
AcceptRoler   Cancelr   clickedButtonr   r   r   r  )rP   r   button_verbosebutton_minimals       r+   r   z"ApplicationContainer.restart_debug  sH    $1Z==)))K()))BCC	
 	
 	
 %Qy\\22$Qy\\22nk&<===nk&<==={1222		.00),BJ~&&  N22),BJ~&&F"'')))))r*   c           	           j                                          t          j        d         g}|t	          j        t          j                            t          d          d                    z  }g }|D ]T}                     |t          j        	                    |          ||f fd	dd          }|
                    |           U                     |d          j         t          j        	           |d
d         D ])}                     | j         t          j        	           * j                                          dS )z1Create an action for each lsp and debug log file.SPYDER_DEBUG_FILElsp_logsz*.logc                 .                         |          S rJ   )load_log_file)r   filerP   s     r+   rX   z?ApplicationContainer.create_debug_log_actions.<locals>.<lambda>  s    t/A/A$/G/G r*   TF)rk   r[   	overwriteregister_actionr   )section   N)r   clear_actionsr   r   globpathr   r   r{   basenameappendadd_item_to_menur-   r0   r1   _render)rP   filesdebug_logs_actionsr  actions   `    r+   r   z-ApplicationContainer.create_debug_log_actions  sh   **,,,/0127<<j(A(A7KKLLL 		. 		.D''  &&)-GGGGG % (  F %%f---- 	q! $5 	 	
 	
 	
 ), 	 	F!!$(7 "     	$$&&&&&r*   c                 :    | j                             |           dS )zLoad log file in editorN)sig_load_log_filer  )rP   r  s     r+   r  z"ApplicationContainer.load_log_file   s    ##D)))))r*   c                     || _         dS )z#Set window property of main window.N)_window)rP   windows     r+   
set_windowzApplicationContainer.set_window&  s    r*   c                     |W|                                 }| j        |k    r|                     |           dS |j                            | j                   dS dS )z#Connect DPI signals for new screen.N)logicalDotsPerInchrM   show_dpi_change_messagelogicalDotsPerInchChangedrr   )rP   
new_screennew_screen_dpis      r+   handle_new_screenz&ApplicationContainer.handle_new_screen*  st    !'::<<N>11,,^<<<<<4<<02 2 2 2 2 "!r*   c                 F   | j                                         r|                     dd           d| _         |dk    r]|                     dd           |                     dd           |                     dd           | j                                         dS || _        dS )	z(Handle dpi change message dialog result.show_dpi_messageFNr   normal_screen_resolutionhigh_dpi_scalingThigh_dpi_custom_scale_factor)rN   r   r   r   r  rM   )rP   r   dpis      r+   handle_dpi_change_responsez/ApplicationContainer.handle_dpi_change_response4  s    ))++ 	5MM,e444"Q;; MM4e<<<MM,d333MM8%@@@&++-----  #Dr*   c                 D                          d          sdS  j        k    r j                                        }|                                t
          j        k    rt          j        dk    rdS                       d          rdS  j	        4 j	        
                                  j	                                         dS t          t          j                    _	         j	                            t!          d                      j	                            d            j	                            d            j	                            t!          d	                      j	                            t!          d
          t          j                    j	                            t!          d          t          j                  } j	                            |            j	        j                             fd            j	                                          j	                                                                        } j	                                                                        }t;          j                                                    }|                                |z
  dz  }|                                |z
  dz  } j	                             tC          |          tC          |                      j	        "                                 dS dS )z;Show message to restart Spyder since the DPI scale changed.r0  Nr   r2  r   zDon't show again.FTao  A monitor scale change was detected. <br><br>We recommend restarting Spyder to ensure that it's properly displayed. If you don't want to do that, please be sure to activate the option<br><br><tt>Enable auto high DPI scaling</tt><br><br>in <tt>Preferences > Application > Interface</tt>, in case Spyder is not displayed correctly.<br><br>Do you want to restart Spyder?zRestart nowDismissc                 0                         |           S rJ   )r5  )r   r4  rP   s    r+   rX   z>ApplicationContainer.show_dpi_change_message.<locals>.<lambda>r  s    t>>vsKK r*   rm   )#r   rM   r%  windowHandlewindowStater   WindowFullScreenr   r   rN   activateWindowraise_r    r
   Warningr   r   r   r   r   r  NoRoler   r   rr   r   rectwidthheightr   primaryScreengeometrymoveint
adjustSize)	rP   r4  r&  dismiss_buttondpi_messagebox_widthdpi_messagebox_heightscreen_geometryxys	   ``       r+   r*  z,ApplicationContainer.show_dpi_change_messageF  s   }}/00 	Fs"" \..00F""$$(;;;LH,,}}/00 ".#22444#**,,,"1{7J9=#? #? #?D 11!4G2H2HIII++E22211$777''23 3	4 	4 	4 ))!M*:*:K<NOOO!0::)k02 2N00@@@(00KKKKKM M M$$&&&
 $(#6#;#;#=#=#C#C#E#E $($7$<$<$>$>$E$E$G$G!-;==FFHHO &&((+??1DA '')),AAQFA $$SVVSVV444**,,,,,m #"r*   rJ   )F)r%   r&   r'   r   r   strr#  rL   r   r   r   r   r   r   r   rs   ru   r   r   r   r   r   r   r   r  r'  r.  r5  r*  __classcell__)rT   s   @r+   rH   rH   L   s3       !' s# # # # # #t/ t/ t/l  
O O O" 
TVV  V
 
TVV6 6 V6i* i* i*V 
TVV# # # V#6 
T#YY- - Y- 
TVV	 	 V	  # # # 
TVV% % V%R 
TVV* * V*
 
TVV* * V*6#' #' #'J* * *  2 2 2# # #$;- ;- ;- ;- ;- ;- ;-r*   rH   )9__doc__r   r   r   r  qtpy.QtCorer   r   r   r   r   
qtpy.QtGuir   qtpy.QtWidgetsr	   r
   r   spyderr   r   r   r   r   spyder.api.translationsr   !spyder.api.widgets.main_containerr   spyder.utils.installersr   spyder.config.utilsr   spyder.config.baser   r   r   r   )spyder.plugins.application.widgets.statusr   spyder.plugins.console.apir   spyder.utils.environr   spyder.utils.qthelpersr   r   spyder.widgets.aboutr   spyder.widgets.dependenciesr   spyder.widgets.helperwidgetsr    spyder.workers.updatesr!   r#   r-   r3   rH   r)   r*   r+   <module>rb     s    
			     



  : 9 9 9 9 9 9 9 9 9 9 9 9 9 & & & & & & < < < < < < < < < < M L L L L L L L L L L L       % % % % % % A A A A A A @ @ @ @ @ @ + + + + + +4 4 4 4 4 4 4 4 4 4 4 4 M M M M M M 5 5 5 5 5 5 . . . . . . < < < < < < < < , , , , , , : : : : : : 8 8 8 8 8 8 0 0 0 0 0 0& & & & & & & &( ( ( ( ( ( ( (1 1 1 1 1 1 1 1.u- u- u- u- u-. u- u- u- u- u-r*   