
    eo                        d Z ddlZddlZddlZddlZddlm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 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*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8  G d d      Z9 G d d      Z: G d d      Z; G d de      Z<y)zT
Container Widget.

Holds references for base actions in the Application of Spyder.
    N)parse)QtQThreadQTimerSignalSlot)QGuiApplication)QActionQMessageBoxQPushButton)__docs_url____forum_url____trouble_url__)dependencies)_)PluginMainContainer)InstallerMissingDependencies)is_anaconda)get_conf_pathget_debug_level
is_pynsistrunning_in_mac_app)ApplicationUpdateStatus)ConsoleActions)is_anaconda_pkgget_spyder_conda_channel)UserEnvDialog)
start_fileDialogManager)AboutDialog)DependenciesDialog)MessageCheckBox)WorkerUpdatesc                       e Zd ZdZy)ApplicationPluginMenusdebug_logs_menuN)__name__
__module____qualname__DebugLogsMenu     F/usr/lib/python3/dist-packages/spyder/plugins/application/container.pyr%   r%   -   s    %Mr,   r%   c                       e Zd ZdZdZy)LogsMenuSectionsspyder_log_sectionlsp_logs_sectionN)r'   r(   r)   SpyderLogSectionLSPLogsSectionr+   r,   r-   r/   r/   1   s    +'Nr,   r/   c                   4    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
Zy)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-   r5   r5   7   sC    
 !7%H""A;<1'K @
 M0r,   r5   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 )ApplicationContainerc                 R    t         |   |||       d | _        d | _        d | _        y N)super__init__current_dpidpi_messageboxinstaller_path)selfnamepluginparent	__class__s       r-   rN   zApplicationContainer.__init__Z   s0    vv.  " #r,   c           
         t        d       | _        t               | _        d | _        t               s
t               rt        |       | _        | j                  j                  j                  | j                         | j                  j                  j                  | j                         | j                  j                          d| _        d | _        d | _        d | _        | j%                  t&        j(                  t+        d      | j-                  d      d t.        j0                  dd      | _        d	| j%                  t&        j4                  t+        d
      | j-                  d      fd      | _        | j%                  t&        j8                  t+        d      d       | _        | j%                  t<        j>                  t+        d      | j-                  d      | j@                        | _!        | j%                  t&        jD                  t+        d      | jF                  | j-                  d            | _$        | j%                  t&        jJ                  t+        d      d       | _&        | j%                  t&        jN                  t+        d      dz  | j-                  d      | jP                  tR        jT                        | _+        tX        jZ                  dk(  rt+        d      }nt+        d      }| j%                  t&        j\                  t+        d       | j-                  d!      || j^                  "      | _0        | j%                  t&        jb                  t+        d#      | j-                  d$      t+        d%      | jd                  t.        j0                  dd&      | _3        | j%                  t&        jh                  t+        d'      t+        d(      | jj                  t.        j0                  dd)      | _6        to               d*k\  r^| jq                  tr        jt                  t+        d+            | _;        | jv                  jx                  j                  | jz                         y y ),N)rU   FzSpyder documentationDialogHelpButtonc                       t        t              S rL   )r   r   r+   r,   r-   <lambda>z,ApplicationContainer.setup.<locals>.<lambda>   s    j6 r,   Tr   )texticon	triggeredcontextregister_shortcutshortcut_contextzHhttps://www.youtube.com/playlist?list=PLPonohdiDqg9epClEcXoAPUiK0pN5eRoczTutorial videos	VideoIconc                      t               S rL   )r   )spyder_video_urls   r-   rZ   z,ApplicationContainer.setup.<locals>.<lambda>   s    j)9: r,   )r[   r\   r]   zTroubleshooting...c                       t        t              S rL   )r   r   r+   r,   r-   rZ   z,ApplicationContainer.setup.<locals>.<lambda>   s    j9 r,   )r]   zReport issue...bug)r\   r]   zDependencies...advanced)r]   r\   zSpyder support...c                       t        t              S rL   )r   r   r+   r,   r-   rZ   z,ApplicationContainer.setup.<locals>.<lambda>   s    j7 r,   zAbout %s...SpyderMessageBoxInformation)r\   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)r\   tipr]   z&Restartrestartr=   )r\   rm   r]   r^   r`   r_   z&Restart in debug moder>   )rm   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_actionr5   r?   r   create_iconr   ApplicationShortcutdocumentation_actionr@   video_actionrA   trouble_actionr   SpyderReportActionsig_report_issue_requestedreport_actionrB   show_dependenciesdependencies_actionrD   support_group_actionrE   
show_aboutr
   	AboutRoleabout_actionosrS   rF   show_user_env_variablesuser_env_actionrG   restart_normalrestart_actionrH   restart_debugrestart_debug_actionr   create_menur%   r*   menu_debug_logsaboutToShowcreate_debug_log_actions)rR   rm   rc   s     @r-   setupzApplicationContainer.setupf   s    $+4=  ,o)-&<-/-D.D*++KKgd(()++JJ'$112**88:%*"""! %)$6$688)*!!"456**"  %7 %"!G ..==$%!!+.:	 / < #00::"#9 1 ; "//-- !!%(55	 0 7
 $(#5#577 ,,!!*-	 $6 $/  %)$6$622!"7 %7 %9! !..**mx'!!"9:oo&& / ( 77d? ? @C    !C#115556!!-022  2  4 #00,,jM!!),)))** " 1 $ %)$6$611&')*((** " %7 %$! !#'#3#3&44,$D    ,,44--/ "r,   c                      y rL   r+   rR   s    r-   update_actionsz#ApplicationContainer.update_actions   s    r,   c                 0   | j                   j                          | j                  | j                  j                          | j                  4| j                  j                          | j                  j                          | j                  4| j                  j                          | j                  j                          t        j                  dk(  rdnd}| j                  r3t        j                  dj                  || j                  g      d       yy)z.To call from Spyder when the plugin is closed.Nrk   startopen T)shell)rq   	close_allr|   stoprz   quitwaitrp   r   rS   rQ   
subprocessPopenjoin)rR   cmds     r-   on_closezApplicationContainer.on_close   s    %%')##%*$$&$$&##/$$))+$$))+ ''T/wvSXXsD,?,?&@AN r,   c                 :    t        |       }|j                          y)zShow Spyder About dialog.N)r    show)rR   abts     r-   r   zApplicationContainer.show_about   s     $
r,   c                 L    | j                   j                  t        |              y)z0Show Windows current user environment variables.N)rq   r   r   r   s    r-   r   z,ApplicationContainer.show_user_env_variables   s     	  t!45r,   c                 D   | j                   }| j                  j                  }| j                  j                  }| j                  j                  }d}t        t        j                  |       }|j                  t        d             |j                  t        j                         |j                  t        d             |j                  t        j                         |j!                  t        j                         |j#                  t        j$                         d}|j'                  | j)                  |             t        d      j+                  |      }|[|j-                  |       |j/                  d       |j1                          | j2                  r| j2                  j5                          n|r.| j2                  r| j2                  j7                  |       t8        j:                  j=                  d	      rt?        |      t?        d
      k\  r|j                  t        j@                  t        jB                  z         |j!                  t        j@                         tE               s-tG               s#|dz   }	|t        d      j+                  |	      z   }
n|t        d      z   }
|j-                  |
       |jI                          |jK                         t        j@                  k(  r| j2                  jM                  |       |jK                         r8|jK                         t        jB                  k(  r&tE               stG               s|j/                  |jK                                 |j                  t        j                         |j!                  t        j                         d}
|jK                         s|
|z  }
tN        jP                  dk(  r(tS               r|
t        d      z  }
n6|
t        d      z  }
n'tS               r|
t        d      z  }
n|
t        d      z  }
tS               rrtU               \  }}|dk(  }tW               r|s|
dz  }
|r%d}|
dz  }
|
t        d      j+                  |      z  }
n-|dk(  rd}nd| }|
d| d| dz  }
|
t        d      z  }
n|
d z  }
|
t        d!      j+                  |      z  }
|j-                  |
       |j1                          ny|rQ|j-                  t        d"             |j1                          | j2                  rA| j2                  j5                          n&| j2                  r| j2                  j5                          | jY                  ||j[                                | j\                  j_                  d       d#| _         y)$z3Show results of the Spyder update checking process.z5https://docs.spyder-ide.org/current/installation.htmlr\   rU   zNew Spyder versionzCheck for updates at startupcheck_updates_on_startupz$<h3>Spyder {} is available!</h3><br>NFlinuxz6.0.0z#standalone-installerszWould you like to automatically download and install it using Spyder's installer?<br><br>We <a href='{}'>recommend our own installer</a> because it's more stable and makes updating easy. This will leave your existing Spyder installation untouched.z8Would you like to automatically download and install it?)latest_release rk   zXRun the following command or commands in the Anaconda prompt to update manually:<br><br>zERun the following command in a cmd prompt to update manually:<br><br>zORun the following command or commands in a terminal to update manually:<br><br>zCRun the following command in a terminal to update manually:<br><br>pypiz&<code>conda update anaconda</code><br>zhttps://youtu.be/Ul79ihg41Rsz5<code>pip install --upgrade spyder</code><br><br><br>z<b>Important note:</b> You installed Spyder with pip in a Conda environment, which is not a good idea. See <a href="{}">our video</a> for more details about it.z	pkgs/mainz-c z<code>conda install z spyder=z</code><br><br><br>z<b>Important note:</b> Since you installed Spyder with Anaconda, please don't use pip to update it as that will break your installation.z-<code>pip install --upgrade spyder</code><br>zL<br><br>For more information, visit our <a href="{}">installation guide</a>.zSpyder is up to date.T)0ry   r{   update_availabler   errorr"   r   InformationsetWindowTitler   setAttributer   WA_ShowWithoutActivatingset_checkbox_textsetStandardButtonsOksetDefaultButtonsetTextFormatRichTextset_checkedget_confformatsetTextset_check_visibler   rr   rx   set_status_pendingsysplatform
startswithr   YesNor   r   exec_resultstart_installationr   rS   r   r   r   set_conf
is_checkedcheck_updates_actionsetDisabled)rR   feedbackr   r   	error_msgurl_iboxoptionheaderinstallers_urlmsgchannel__is_pypidont_mix_pip_conda_videos                  r-   _check_updates_readyz)ApplicationContainer._check_updates_ready  s    --  ..??,,;;''--	G ;#:#:%)+1123445a >?@{~~.[^^,"++& ,f-.2

&
  	  KK	"!!%(HHJ--..<<>--..AA"$
 LL++G4(E'N:&&{'GH$$[__5!|,>,@%*-E%EN ' ( )/~(>?   , --  C 		::<;??222EE'5 F 7
 JJLJJLKNN2&L.0
 %%#**,&67&&{~~6$$[^^4zz|6MC77d?"}q ",  - - q "?  @ @ #}q "H  I I q "<  = = =":"<KGR%/G&(GG: 1 +
 q0 
 !&!9:; #k1&(G(+G9oG27) <&&4%513 q,   JJCq= &- 
 C 
KK123HHJ--..<<>--..<<>fcnn./ 	!!--e4 &*"r,   c                 B   | j                   j                  d       | j                  r| j                  j                          | j                  4| j                  j                          | j                  j                          t        d      | _        t        | |      | _	        | j                  j                  j                  | j                         | j                  j                  j                  | j                  j
                         | j                  j                  | j                         | j                  j                  j                  | j                  j                         |rt!        |       | _        | j"                  j%                  d       | j"                  j'                  d       | j"                  j(                  j                  | j                  j                         | j"                  j                          y| j                  j                          y)z<Check for spyder updates on github releases using a QThread.TN)startupi`  )r   r   rr   set_status_checkingrz   r   r   r   r#   r{   	sig_readyrt   r   moveToThreadstartedr   r   r|   setIntervalsetSingleShottimeout)rR   r   s     r-   ru   z"ApplicationContainer.check_updates  s    	!!--d3))**>>@*$$&$$&%dm+D'B%%--d.G.GH%%--d.A.A.F.FG(()<)<=##++D,?,?,E,EF
 !'D**51,,T2&&..t/B/B/H/HI$$&%%'r,   c                     || _         y)z5Set installer executable path to be run when closing.N)rQ   )rR   rQ   s     r-   rw   z'ApplicationContainer.set_installer_path  s     -r,   c                     t         j                  st        j                          t        |       }|j	                  t         j                         |j                          y)z Show Spyder Dependencies dialog.N)r   DEPENDENCIESdeclare_dependenciesr!   set_datar   )rR   dlgs     r-   r   z&ApplicationContainer.show_dependencies  s>    
 ((--/ &\../
r,   c                 L    	 t        j                          y# t        $ r Y yw xY w)z$Compute dependencies without errors.N)r   r   
ValueErrorr   s    r-   _compute_dependenciesz*ApplicationContainer._compute_dependencies  s%    
	--/ 		s    	##c                 p   | j                   | j                  _        | j                  j                  j	                  | j
                         t        |       }|j                  d       |j                  d       |j                  j	                  | j                  j                         |j                          y)zCompute dependencies.i'  TN)r   rp   runfinishedrt   report_missing_dependenciesr   r   r   r   r   )rR   dependencies_timers     r-   compute_dependenciesz)ApplicationContainer.compute_dependencies  s    '+'A'A  $  ))11,,	. $D\&&u-((.""**4+C+C+I+IJ  "r,   c                    t        j                         }|r-t        |       |j                  dd      j                  dd      j                  dd      }t	        d      |z  }t        |       }|j                  t
        j                         |j                  t        j                         |j                  t        j                         |j                  t
        j                         |j                  t        j                         |j!                  t	        d             |j#                  |       |j%                          yy)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   )rR   missing_depsmessagemessage_boxs       r-   r   z0ApplicationContainer.report_missing_dependencies  s    $88:(6
 )00>#GC0v1F     ##   &d+K 4 45$$R%8%89$$R%@%@A**;>>:))"++6&&qz2(C r,   c                 ^    dt         j                  d<   | j                  j                          y)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        |       }|j                  t        d             |j                  t         j                         |j                  t        d             t        t        d            }t        t        d            }|j                  |t         j                         |j                  |t         j                         |j                  t         j                         |j                          |j                         |k(  rdt        j                  d<   n(|j                         |k(  rdt        j                  d<   ny| j                  j!                          y)	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	  )rR   r   button_verbosebutton_minimals       r-   r   z"ApplicationContainer.restart_debug.  s     $1Z=)K(()BC	
 %Qy\2$Qy\2nk&<&<=nk&<&<={112		.0),BJJ~& N2),BJJ~&""'')r,   c           	           j                   j                          t        j                  d   g}|t	        j                  t        j
                  j                  t        d      d            z  }g }|D ]L  } j                  |t        j
                  j                  |      ||f fd	dd      }|j                  |       N  j                  |d    j                   t        j                  	       |d
d D ].  } j                  | j                   t        j                  	       0  j                   j                          y)z1Create an action for each lsp and debug log file.SPYDER_DEBUG_FILElsp_logsz*.logc                 &    j                  |      S rL   )load_log_file)r   filerR   s     r-   rZ   z?ApplicationContainer.create_debug_log_actions.<locals>.<lambda>W  s    t/A/A$/G r,   TF)rm   r]   	overwriteregister_actionr   )section   N)r   clear_actionsr   r  globpathr   r   r}   basenameappendadd_item_to_menur/   r2   r3   _render)rR   filesdebug_logs_actionsr  actions   `    r-   r   z-ApplicationContainer.create_debug_log_actionsJ  s/   **,/01277<<j(A7KLL 		.D''  &)-G % ( F %%f-		. 	q!  $55 	 	
 ), 	F!!$$(77 " 	 	$$&r,   c                 :    | j                   j                  |       y)zLoad log file in editorN)sig_load_log_filer	  )rR   r  s     r-   r  z"ApplicationContainer.load_log_fileo  s    ##D)r,   c                     || _         y)z#Set window property of main window.N)_window)rR   windows     r-   
set_windowzApplicationContainer.set_windowu  s	    r,   c                     |W|j                         }| j                  |k7  r| j                  |       y|j                  j	                  | j                         yy)z#Connect DPI signals for new screen.N)logicalDotsPerInchrO   show_dpi_change_messagelogicalDotsPerInchChangedrt   )rR   
new_screennew_screen_dpis      r-   handle_new_screenz&ApplicationContainer.handle_new_screeny  sT    !'::<N>1,,^<44<<002 "r,   c                 $   | j                   j                         r| j                  dd       d| _         |dk(  rQ| j                  dd       | j                  dd       | j                  dd       | j                  j	                          y|| _        y)	z(Handle dpi change message dialog result.show_dpi_messageFNr   normal_screen_resolutionhigh_dpi_scalingThigh_dpi_custom_scale_factor)rP   r   r   r  r	  rO   )rR   r   dpis      r-   handle_dpi_change_responsez/ApplicationContainer.handle_dpi_change_response  s}    ))+MM,e4"Q; MM4e<MM,d3MM8%@&&++-  #Dr,   c                 "     j                  d      sy j                  k7  r j                  j                         }|j	                         t
        j                  k(  rt        j                  dk(  ry j                  d      ry j                  5 j                  j                           j                  j                          yt        t        j                          _	         j                  j                  t!        d              j                  j#                  d        j                  j%                  d        j                  j'                  t!        d	              j                  j)                  t!        d
      t        j*                          j                  j)                  t!        d      t        j*                        } j                  j-                  |        j                  j.                  j1                   fd        j                  j3                           j                  j5                         j7                         } j                  j5                         j9                         }t;        j<                         j?                         }|j7                         |z
  dz  }|j9                         |z
  dz  } j                  jA                  tC        |      tC        |              j                  jE                          yy)z;Show message to restart Spyder since the DPI scale changed.r8  Ndarwinr:  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                 (    j                  |       S rL   )r=  )r   r<  rR   s    r-   rZ   z>ApplicationContainer.show_dpi_change_message.<locals>.<lambda>  s    t>>vsK r,   ro   )#r   rO   r-  windowHandlewindowStater   WindowFullScreenr   r   rP   activateWindowraise_r"   r   Warningr   r   r   r   r   r  NoRoler   r   rt   r   rectwidthheightr	   primaryScreengeometrymoveint
adjustSize)	rR   r<  r.  dismiss_buttondpi_messagebox_widthdpi_messagebox_heightscreen_geometryxys	   ``       r-   r2  z,ApplicationContainer.show_dpi_change_message  sf   }}/0s" \\..0F""$(;(;;LLH,}}/0"".##224##**,"1{7J7J9=#?D 11!4G2HI++E211$7''23	4 ))!M*:K<N<NO!00::)k002N00@((00KM$$&
 $(#6#6#;#;#=#C#C#E $($7$7$<$<$>$E$E$G!-;;=FFHO &&(+??1DA ''),AAQFA $$SVSV4**,m #r,   rL   )F)r'   r(   r)   r   r   strr+  rN   r   r   r   r   r   r   r   ru   rw   r   r   r   r   r   r   r   r  r/  r6  r=  r2  __classcell__)rV   s   @r-   rJ   rJ   N   s   !' s#u/n
O" 
V 
 
V6 6r*h 
V( (< 
#Y- - 
V	 	# 
V% %R 
V* *
 
V* *6#'J*2#$;-r,   rJ   )=__doc__r   r   r   r!  packaging.versionr   qtpy.QtCorer   r   r   r   r   
qtpy.QtGuir	   qtpy.QtWidgetsr
   r   r   spyderr   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.condar   r   spyder.utils.environr   spyder.utils.qthelpersr   r   spyder.widgets.aboutr    spyder.widgets.dependenciesr!   spyder.widgets.helperwidgetsr"   spyder.workers.updatesr#   r%   r/   r5   rJ   r+   r,   r-   <module>rm     s    
  
  $ 9 9 & < < @ ?  % A @ +4 4 M 5 H . < , : 8 0& &( (1 1.B
-. B
-r,   