a
     ³Šaf4  ã                   @   sì   d Z ddlZddlmZ ddlZddl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 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mZmZ ddlm Z m!Z!m"Z"m#Z# ddl$m%Z% edƒZ&G dd„ deƒZ'dS )z
Application Plugin.
é    N)ÚSlot)ÚQMenu)ÚPluginsÚSpyderPluginV2)Úget_translation)Úon_plugin_available)ÚMENU_SEPARATOR)ÚDEVÚget_module_pathÚget_debug_levelÚrunning_under_pytest)ÚApplicationConfigPage)ÚApplicationContainerÚApplicationPluginMenusÚWinUserEnvDialog)ÚApplicationMenusÚFileMenuSectionsÚHelpMenuSectionsÚToolsMenuSections)Úadd_actionsÚspyderc                   @   sÈ  e Zd ZdZejejgZejej	ej
ejgZeZdZdZeZdd„ Zdd„ Zdd	„ Zd
d„ Zeej
ddd„ ƒZeejddd„ ƒZeejddd„ ƒZeej	ddd„ ƒZeejddd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Z dd „ Z!d!d"„ Z"d#d$„ Z#d%d&„ Z$e%d'd(„ ƒZ&dJd*d+„Z'd,d-„ Z(d.d/„ Z)e*ƒ d0d1„ ƒZ+e%d2d3„ ƒZ,e%d4d5„ ƒZ-e%d6d7„ ƒZ.e%d8d9„ ƒZ/e%d:d;„ ƒZ0e%d<d=„ ƒZ1e%d>d?„ ƒZ2e%d@dA„ ƒZ3e%dBdC„ ƒZ4e%dDdE„ ƒZ5e%dFdG„ ƒZ6e%dHdI„ ƒZ7d)S )KÚApplicationZapplicationÚmainFc                 C   s   t dƒS )Nr   ©Ú_©Úself© r   ú@lib/python3.9/site-packages/spyder/plugins/application/plugin.pyÚget_name1   s    zApplication.get_namec                 C   s
   |   d¡S )NZgenprefs)Zcreate_iconr   r   r   r   Úget_icon4   s    zApplication.get_iconc                 C   s   t dƒS )Nz&Provide main application base actions.r   r   r   r   r   Úget_description7   s    zApplication.get_descriptionc                 C   s4   |   ¡ }|j | j¡ | | j¡ | j | j¡ d S ©N)Úget_containerZsig_report_issue_requestedÚconnectÚreport_issueZ
set_windowÚ_windowZsig_restart_requestedÚrestart)r   Ú	containerr   r   r   Úon_initialize:   s    zApplication.on_initialize)Zpluginc                 C   s   |   tj¡r|  ¡  d S r"   )Úis_plugin_availabler   ÚMainMenuÚ_populate_help_menur   r   r   r   Úon_shortcuts_availableA   s    z"Application.on_shortcuts_availablec                 C   s   |   tj¡r| j d¡ d S )NT)r*   r   r+   Úreport_actionÚ
setVisibler   r   r   r   Úon_console_availableF   s    z Application.on_console_availablec                 C   s   |   tj¡}| | ¡ d S r"   )Ú
get_pluginr   ÚPreferencesZregister_plugin_preferences)r   Zpreferencesr   r   r   Úon_preferences_availableK   s    z$Application.on_preferences_availablec                 C   sV   |   ¡  |  ¡  |  tj¡r2|  tj¡r:|  ¡  n|  ¡  |  tj¡sR| j 	d¡ d S )NF)
Ú_populate_file_menuÚ_populate_tools_menuZis_plugin_enabledr   Ú	Shortcutsr*   r,   ÚConsoler.   r/   r   r   r   r   Úon_main_menu_availableQ   s    
z"Application.on_main_menu_availablec                 C   s"   |   tj¡}|  ¡ j |j¡ d S r"   )r1   r   ÚEditorr#   Zsig_load_log_filer$   Úload)r   Zeditorr   r   r   Úon_editor_available_   s    zApplication.on_editor_availablec                 C   s   |   ¡  ¡  d S r"   )r#   Úon_closer   r   r   r   r<   d   s    zApplication.on_closec                 C   s†   |   ¡ }tƒ s| ¡  tdu r:|  d¡r:d|_|jdd tjdks‚| j	 
¡ }|j |j¡ | j	 
¡  ¡ }| ¡ |_|j |j¡ dS )z(Actions after the mainwindow in visible.NZcheck_updates_on_startupFT)ZstartupÚdarwin)r#   r   Zcompute_dependenciesr	   Zget_confZgive_updates_feedbackZcheck_updatesÚsysÚplatformr&   ZwindowHandleZscreenChangedr$   Zhandle_new_screenÚscreenZlogicalDotsPerInchZcurrent_dpiZlogicalDotsPerInchChangedZshow_dpi_change_message)r   r(   Úwindowr@   r   r   r   Úon_mainwindow_visibleg   s    


ÿz!Application.on_mainwindow_visiblec                 C   s<   |   tj¡}|j| jtjtjd |j| j	tjtjd d S )N©Úmenu_idÚsection)
r1   r   r+   Úadd_item_to_application_menuÚrestart_actionr   ZFiler   ZRestartÚrestart_debug_action©r   Úmainmenur   r   r   r4   ‚   s    ýýzApplication._populate_file_menuc                 C   sN   |   tj¡}tdur*|j| jtjtjd t	ƒ dkrJ|j| j
tjtjd dS )z-Add base actions and menus to the Tools menu.NrC   é   )r1   r   r+   r   rF   Úwinenv_actionr   ZToolsr   r   Údebug_logs_menuZExtrasrI   r   r   r   r5      s    ý
ýz Application._populate_tools_menuc                 C   s   |   ¡  |  ¡  |  ¡  dS )z,Add base actions and menus to the Help menu.N)Ú)_populate_help_menu_documentation_sectionÚ#_populate_help_menu_support_sectionÚ!_populate_help_menu_about_sectionr   r   r   r   r,   œ   s    zApplication._populate_help_menuc                 C   sb   |   tj¡}|   tj¡}d}|r2ddlm} |j}| j| jfD ]}|j	|t
jtj|tjd q>dS )z<Add base Spyder documentation actions to the Help main menu.Nr   ©ÚShortcutActions)rD   rE   ZbeforeÚbefore_section)r1   r   r+   r6   Úspyder.plugins.shortcuts.pluginrR   ÚShortcutSummaryActionÚdocumentation_actionÚvideo_actionrF   r   ÚHelpr   ZDocumentationÚSupport)r   rJ   Ú	shortcutsZshortcuts_summary_actionrR   rV   r   r   r   rN   ¢   s    ÿûz5Application._populate_help_menu_documentation_sectionc                 C   sF   |   tj¡}| j| j| j| j| jfD ]}|j|t	j
tjtjd q$dS )z6Add Spyder base support actions to the Help main menu.)rD   rE   rS   N)r1   r   r+   Útrouble_actionr.   Údependencies_actionÚcheck_updates_actionÚsupport_group_actionrF   r   rX   r   rY   ZExternalDocumentation)r   rJ   Zsupport_actionr   r   r   rO   ´   s    ýüz/Application._populate_help_menu_support_sectionc                 C   s&   |   tj¡}|j| jtjtjd dS )z!Create Spyder base about actions.rC   N)	r1   r   r+   rF   Úabout_actionr   rX   r   ZAboutrI   r   r   r   rP   Á   s    ýz-Application._populate_help_menu_about_sectionc                 C   s
   | j  ¡ S r"   )r   rA   r   r   r   r   r&   É   s    zApplication._windowNc           
      C   sš   d}d}|   tj¡}|   tj¡}t|d}| jg}|rXddlm} | |j	¡}||g7 }|r~ddl
m}	 | |	j¡}| |¡ |t| jg7 }t||ƒ |S )zV
        Return menu with the actions to be shown by the Spyder context menu.
        N)Úparentr   )ÚHelpActionsrQ   )r1   r   rX   r6   r   rV   Zspyder.plugins.help.pluginra   Z
get_actionZShowSpyderTutorialActionrT   rR   rU   Úappendr   r_   r   )
r   r`   Ztutorial_actionZshortcuts_actionZhelp_pluginrZ   ZmenuZactionsra   rR   r   r   r   Úget_application_context_menuÏ   s*    
ÿ
ÿ

z(Application.get_application_context_menuc                 C   s$   |   tj¡r |  tj¡}| ¡  d S r"   )r*   r   r7   r1   r%   )r   Úconsoler   r   r   r%   í   s    zApplication.report_issuec                 C   s   | j  ¡  dS )zApply applications settings.N)Z_mainÚapply_settingsr   r   r   r   re   ò   s    zApplication.apply_settingsc              
   C   sh  |   tj¡}tdƒ}t |dd¡}tj ¡ }| 	dd¡}| 	d¡}t 
¡ }tj}|durb|}d}	nd}	||d< t|ƒ|d	< t|	ƒ|d
< trÀt |¡}
tjdkr°d |
g¡|d< nd |
g¡|d< tjdkrèt ¡ }| jtjO  _d}nd}d}d}| ||¡}z,| j d¡r*tj||||d | ¡  W n6 tyb } zt|ƒ t|ƒ W Y d}~n
d}~0 0 dS )zs
        Quit and Restart Spyder application.

        If reset True it allows to reset spyder on restart.
        r   Zappz
restart.pyZSPYDER_BOOTSTRAP_ARGSNZSPYDER_ARGSTFZ
SPYDER_PIDZSPYDER_IS_BOOTSTRAPÚntú;Z
PYTHONPATHú:z"{0}" "{1}")ÚshellÚenvÚstartupinfo)r1   r   r7   r
   ÚospÚjoinÚosÚenvironÚcopyÚpopÚgetpidr>   Ú
executableÚstrr	   ÚdirnameÚnameÚ
subprocessZSTARTUPINFOZdwFlagsZSTARTF_USESHOWWINDOWÚformatr   ÚclosingÚPopenÚquitÚ	ExceptionÚprint)r   rd   Zspyder_start_directoryZrestart_scriptrj   Zbootstrap_argsZspyder_argsÚpidZpythonZis_bootstrapZrepo_dirrk   ri   ZcommandÚerrorr   r   r   r'   ö   sJ    





ÿzApplication.restartc                 C   s
   |   ¡ jS )z+Open Spyder's Documentation in the browser.)r#   rV   r   r   r   r   rV   9  s    z Application.documentation_actionc                 C   s
   |   ¡ jS )z1Open Spyder's video documentation in the browser.)r#   rW   r   r   r   r   rW   >  s    zApplication.video_actionc                 C   s
   |   ¡ jS )z;Open Spyder's troubleshooting documentation in the browser.)r#   r[   r   r   r   r   r[   C  s    zApplication.trouble_actionc                 C   s
   |   ¡ jS )z&Show Spyder's Dependencies dialog box.)r#   r\   r   r   r   r   r\   H  s    zApplication.dependencies_actionc                 C   s
   |   ¡ jS )z.Check if a new version of Spyder is available.)r#   r]   r   r   r   r   r]   M  s    z Application.check_updates_actionc                 C   s
   |   ¡ jS )z2Open Spyder's Google support group in the browser.)r#   r^   r   r   r   r   r^   R  s    z Application.support_group_actionc                 C   s
   |   ¡ jS )zShow Spyder's About dialog box.)r#   r_   r   r   r   r   r_   W  s    zApplication.about_actionc                 C   s
   |   ¡ jS )z4Show Spyder's Windows user env variables dialog box.)r#   rL   r   r   r   r   rL   \  s    zApplication.winenv_actionc                 C   s
   |   ¡ jS ©zRestart Spyder action.)r#   rG   r   r   r   r   rG   a  s    zApplication.restart_actionc                 C   s
   |   ¡ jS )z$Restart Spyder in DEBUG mode action.)r#   rH   r   r   r   r   rH   f  s    z Application.restart_debug_actionc                 C   s
   |   ¡ jS r€   )r#   r.   r   r   r   r   r.   k  s    zApplication.report_actionc                 C   s   |   ¡  tj¡S r"   )r#   Zget_menur   ZDebugLogsMenur   r   r   r   rM   p  s    ÿzApplication.debug_logs_menu)N)8Ú__name__Ú
__module__Ú__qualname__ÚNAMEr   r7   r2   ZREQUIRESrX   r+   r6   r9   ZOPTIONALr   ZCONTAINER_CLASSZCONF_SECTIONZ	CONF_FILEr   ZCONF_WIDGET_CLASSr   r    r!   r)   r   r-   r0   r3   r8   r;   r<   rB   r4   r5   r,   rN   rO   rP   Úpropertyr&   rc   r%   re   r   r'   rV   rW   r[   r\   r]   r^   r_   rL   rG   rH   r.   rM   r   r   r   r   r   '   s|   ÿ












B










r   )(Ú__doc__rn   Úos.pathÚpathrl   rw   r>   Zqtpy.QtCorer   Zqtpy.QtWidgetsr   Zspyder.api.pluginsr   r   Zspyder.api.translationsr   Z)spyder.api.plugin_registration.decoratorsr   Zspyder.api.widgets.menusr   Zspyder.config.baser	   r
   r   r   Z#spyder.plugins.application.confpager   Z$spyder.plugins.application.containerr   r   r   Zspyder.plugins.mainmenu.apir   r   r   r   Zspyder.utils.qthelpersr   r   r   r   r   r   r   Ú<module>   s"   