
    eC                         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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! ddl"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(  G d de      Z)y)z
Application Plugin.
    N)Slot)QMenu)PluginsSpyderPluginV2_)on_plugin_availableon_plugin_teardown)MENU_SEPARATOR)DEVget_module_pathget_debug_levelrunning_under_pytest)ApplicationConfigPage)ApplicationActionsApplicationContainerApplicationPluginMenus)ConsoleActions)ApplicationMenusFileMenuSectionsHelpMenuSectionsToolsMenuSections)add_actionsc                   t   e Zd ZdZej
                  ej                  gZej                  ej                  ej                  ej                  ej                  gZeZdZdZeZdZed        Zd Zd Zd Z eej                        d	        Z eej
                        d
        Z eej                        d        Z eej                        d        Z eej                        d        Z eej                        d        Z  e!ej                        d        Z" e!ej                        d        Z# e!ej                        d        Z$ e!ej
                        d        Z% e!ej                        d        Z&d5dZ'd Z(d Z)d Z*d Z+d Z,d Z-d Z.e/d        Z0d Z1d Z2d Z3d  Z4d! Z5d" Z6d6d$Z7d% Z8d& Z9 e:       d7d'       Z;e/d(        Z<e/d)        Z=e/d*        Z>e/d+        Z?e/d,        Z@e/d-        ZAe/d.        ZBe/d/        ZCe/d0        ZDe/d1        ZEe/d2        ZFe/d3        ZGe/d4        ZHy#)8ApplicationapplicationmainFc                      t        d      S )Nr   r        C/usr/lib/python3/dist-packages/spyder/plugins/application/plugin.pyget_namezApplication.get_name1   s    r    c                 $    | j                  d      S )Ngenprefs)create_iconselfs    r!   get_iconzApplication.get_icon5   s    
++r    c                     t        d      S )Nz&Provide main application base actions.r   r&   s    r!   get_descriptionzApplication.get_description8   s    9::r    c                     | j                         }|j                  j                  | j                         |j	                  | j
                         y N)get_containersig_report_issue_requestedconnectreport_issue
set_window_window)r'   	containers     r!   on_initializezApplication.on_initialize;   s<    &&(	,,44T5F5FGT\\*r    )pluginc                 d    | j                  t        j                        r| j                          y y r,   )is_plugin_availabler   MainMenu_populate_help_menur&   s    r!   on_shortcuts_availablez"Application.on_shortcuts_availableA   s'    ##G$4$45$$& 6r    c                 z    | j                  t        j                        r| j                  j	                  d       y y )NTr7   r   r8   report_action
setVisibler&   s    r!   on_console_availablez Application.on_console_availableF   s/    ##G$4$45))$/ 6r    c                 d    | j                  t        j                        }|j                  |        y r,   )
get_pluginr   Preferencesregister_plugin_preferencesr'   preferencess     r!   on_preferences_availablez$Application.on_preferences_availableK   s&     oog&9&9://5r    c                 x   | j                          | j                          | j                  t        j                        r0| j                  t        j                        r!| j                          n| j                          | j                  t        j                        s| j                  j                  d       y y NF)
_populate_file_menu_populate_tools_menuis_plugin_enabledr   	Shortcutsr7   r9   Consoler=   r>   r&   s    r!   on_main_menu_availablez"Application.on_main_menu_availableQ   s      "!!#!!'"3"34''(9(9:((*$$&''8))%0 9r    c                     | j                  t        j                        }| j                         j                  j                  |j                         y r,   )rA   r   Editorr-   sig_load_log_filer/   loadr'   editors     r!   on_editor_availablezApplication.on_editor_available_   s5    0..66v{{Cr    c                     | j                   r;| j                  t        j                        }|j	                  | j                          y y r,   )application_update_statusrA   r   	StatusBaradd_status_widgetr'   	statusbars     r!   on_statusbar_availablez"Application.on_statusbar_availabled   s:     ))(9(9:I''(F(FG *r    c                     | j                   rE| j                  t        j                        }|j	                  | j                   j
                         y y r,   )rW   rA   r   rX   remove_status_widgetIDrZ   s     r!   on_statusbar_teardownz!Application.on_statusbar_teardownm   s@     ))(9(9:I**4+I+I+L+LM *r    c                 d    | j                  t        j                        }|j                  |        y r,   )rA   r   rB   deregister_plugin_preferencesrD   s     r!   on_preferences_teardownz#Application.on_preferences_teardownt   s$    oog&9&9:11$7r    c                     | j                  t        j                        }| j                         j                  j                  |j                         y r,   )rA   r   rP   r-   rQ   
disconnectrR   rS   s     r!   on_editor_teardownzApplication.on_editor_teardowny   s5    0..99&++Fr    c                 z    | j                  t        j                        r| j                  j	                  d       y y rH   r<   r&   s    r!   on_console_teardownzApplication.on_console_teardown~   s/    ##G$4$45))%0 6r    c                     | j                          | j                          | j                          | j                  j	                  d       y rH   )_depopulate_file_menu_depopulate_tools_menu_depopulate_help_menur=   r>   r&   s    r!   on_main_menu_teardownz!Application.on_main_menu_teardown   s:    ""$##%""$%%e,r    c                 @    | j                         j                          y r,   )r-   on_close)r'   _unuseds     r!   ro   zApplication.on_close   s    %%'r    c                    | j                         }t               s|j                          t        j                  dk(  s| j
                  j                         }|j                  j                  |j                         | j
                  j                         j                         }|j                         |_        |j                  j                  |j                         yy)z(Actions after the mainwindow in visible.darwinN)r-   r   compute_dependenciessysplatformr2   windowHandlescreenChangedr/   handle_new_screenscreenlogicalDotsPerInchcurrent_dpilogicalDotsPerInchChangedshow_dpi_change_message)r'   r3   windowry   s       r!   on_mainwindow_visiblez!Application.on_mainwindow_visible   s    &&(	 $%**, ||x'\\..0F  (()D)DE\\..0779F$*$=$=$?I!,,44113 (r    c                 *   | j                  t        j                        }|j                  | j                  t
        j                  t        j                         |j                  | j                  t
        j                  t        j                         y )Nmenu_idsection)
rA   r   r8   add_item_to_application_menurestart_actionr   Filer   Restartrestart_debug_actionr'   mainmenus     r!   rI   zApplication._populate_file_menu   st    ??7#3#34--$))$,, 	. 	. 	--%%$))$,, 	. 	.r    c                 F   | j                  t        j                        }|j                  | j                  t
        j                  t        j                         t               dk\  r;|j                  | j                  t
        j                  t        j                         yy)-Add base actions and menus to the Tools menu.r      N)rA   r   r8   r   user_env_actionr   Toolsr   r   debug_logs_menuExtrasr   s     r!   rJ   z Application._populate_tools_menu   s    ??7#3#34--  $**%++ 	. 	-
 !11$$(..)00 2 2 "r    c                 d    | j                          | j                          | j                          y)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&   s    r!   r9   zApplication._populate_help_menu   s&    668002..0r    c                 f   | j                  t        j                        }| j                  t        j                        }d}|rddlm} |j                  }| j                  | j                  fD ]B  }|j                  |t        j                  t        j                  |t        j                         D y)z<Add base Spyder documentation actions to the Help main menu.Nr   ShortcutActions)r   r   beforebefore_section)rA   r   r8   rL   spyder.plugins.shortcuts.pluginr   ShortcutSummaryActiondocumentation_actionvideo_actionr   r   Helpr   DocumentationSupport)r'   r   	shortcutsshortcuts_summary_actionr   r   s         r!   r   z5Application._populate_help_menu_documentation_section   s    ??7#3#34OOG$5$56	#' G'6'L'L$))4+<+<%> 	9 11$(--(66//77 2 9	9r    c                 &   | j                  t        j                        }| j                  | j                  | j
                  | j                  fD ]A  }|j                  |t        j                  t        j                  t        j                         C y)z6Add Spyder base support actions to the Help main menu.)r   r   r   N)rA   r   r8   trouble_actionr=   dependencies_actionsupport_group_actionr   r   r   r   r   ExternalDocumentationr'   r   support_actions      r!   r   z/Application._populate_help_menu_support_section   s    ??7#3#34##T%7%7(())+ 	GN 11(--(00/EE	 2 G		Gr    c                     | j                  t        j                        }|j                  | j                  t
        j                  t        j                         y)z!Create Spyder base about actions.r   N)	rA   r   r8   r   about_actionr   r   r   Aboutr   s     r!   r   z-Application._populate_help_menu_about_section   sD    ??7#3#34--$))$** 	. 	,r    c                 6    | j                   j                         S r,   )r   r~   r&   s    r!   r2   zApplication._window   s    yy!!r    c                 d    | j                          | j                          | j                          y r,   )+_depopulate_help_menu_documentation_section%_depopulate_help_menu_support_section#_depopulate_help_menu_about_sectionr&   s    r!   rl   z!Application._depopulate_help_menu   s&    88:224002r    c                     | j                  t        j                        }t        j                  t        j
                  fD ]#  }|j                  |t        j                         % y Nr   )	rA   r   r8   r   SpyderDocumentationActionSpyderDocumentationVideoAction!remove_item_from_application_menur   r   )r'   r   r   s      r!   r   z7Application._depopulate_help_menu_documentation_section   s\    ??7#3#34"<<"AA%C 	/  66$(-- 7 /	/r    c                 (   | j                  t        j                        }t        j                  t
        j                  t        j                  t        j                  t        j                  fD ]#  }|j                  |t        j                         % y)z;Remove Spyder base support actions from the Help main menu.r   N)rA   r   r8   r   SpyderTroubleshootingActionr   SpyderReportActionSpyderDependenciesActionSpyderCheckUpdatesActionSpyderSupportActionr   r   r   r   s      r!   r   z1Application._depopulate_help_menu_support_section   su    ??7#3#34">>11";;";;"668 	/N 66(-- 7 /	/r    c                     | j                  t        j                        }|j                  t        j
                  t        j                         y r   )rA   r   r8   r   r   SpyderAboutr   r   r   s     r!   r   z/Application._depopulate_help_menu_about_section  s;    ??7#3#3422**$)) 	3 	+r    c                     | j                  t        j                        }t        j                  t        j
                  fD ]#  }|j                  |t        j                         % y r   )	rA   r   r8   r   SpyderRestartSpyderRestartDebugr   r   r   )r'   r   	action_ids      r!   rj   z!Application._depopulate_file_menu  sY    ??7#3#34,::,??A 	/I66(-- 7 /	/r    c                    | j                  t        j                        }|j                  t        j
                  t        j                         t               dk\  r0|j                  t        j                  t        j                         yy)r   r   r   N)rA   r   r8   r   r   SpyderUserEnvVariablesr   r   r   r   DebugLogsMenur   s     r!   rk   z"Application._depopulate_tools_menu  sr    ??7#3#342255$** 	3 	, !66&44(.. 7 0 "r    Nc                    d}d}| j                  t        j                        }| j                  t        j                        }t	        |      }| j
                  g}|r'ddlm} |j                  |j                        }||gz  }|r2ddl
m}	 |j                  |	j                        }|j                  |       |t        | j                  gz  }t!        ||       |S )zV
        Return menu with the actions to be shown by the Spyder context menu.
        N)parentr   )HelpActionsr   )rA   r   r   rL   r   r   spyder.plugins.help.pluginr   
get_actionShowSpyderTutorialActionr   r   r   appendr   r   r   )
r'   r   tutorial_actionshortcuts_actionhelp_pluginr   menuactionsr   r   s
             r!   get_application_context_menuz(Application.get_application_context_menu)  s     oogll3OOG$5$56	F#,,->)44446O((GG(3355 7NN+,ND$5$566D'"r    c                     | j                  t        j                        r0| j                  t        j                        }|j	                          y y r,   )r7   r   rM   rA   r0   )r'   consoles     r!   r0   zApplication.report_issueG  s7    ##GOO4oogoo6G  " 5r    c                 8    | j                   j                          y)zApply applications settings.N)_mainapply_settingsr&   s    r!   r   zApplication.apply_settingsL  s    

!!#r    c                 V   | j                  t        j                        }t        d      }t	        j
                  |dd      }t        j                  j                         }|j                  dd      }|j                  d      }t        j                         }	t        j                  }
||}d}nd}||d<   t        |	      |d	<   t        |      |d
<   t        j                  dk(  r:t        j                          }|xj"                  t        j$                  z  c_        d}nd}d}d}|j'                  |
|      }	 | j(                  j+                  d|      r*t        j,                  ||||       |j/                          yy# t0        $ r }t3        |       t3        |       Y d}~yd}~ww xY w)zs
        Quit and Restart Spyder application.

        If reset True it allows to reset spyder on restart.
        spyderappz
restart.pySPYDER_BOOTSTRAP_ARGSNSPYDER_ARGSTF
SPYDER_PIDSPYDER_IS_BOOTSTRAPntz"{0}" "{1}")close_immediately)shellenvstartupinfo)rA   r   rM   r   ospjoinosenvironcopypopgetpidrt   
executablestrname
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWformatr   closingPopenquit	Exceptionprint)r'   resetr   r   spyder_start_directoryrestart_scriptr   bootstrap_argsspyder_argspidpythonis_bootstrapr   r   commanderrors                   r!   restartzApplication.restartP  s{    //'//2 "1!:"8%N jjoo!8$?ggm, iik %(KL L )MHL%(%6!" 77d?$002K:#B#BBEKE..8		yy  9J K  3-8: L  	 %L'NN		s   7AE? ?	F(F##F(c                 6    | j                         j                  S )z+Open Spyder's Documentation in the browser.)r-   r   r&   s    r!   r   z Application.documentation_action       !!#888r    c                 6    | j                         j                  S )z1Open Spyder's video documentation in the browser.)r-   r   r&   s    r!   r   zApplication.video_action       !!#000r    c                 6    | j                         j                  S )z;Open Spyder's troubleshooting documentation in the browser.)r-   r   r&   s    r!   r   zApplication.trouble_action       !!#222r    c                 6    | j                         j                  S )z&Show Spyder's Dependencies dialog box.)r-   r   r&   s    r!   r   zApplication.dependencies_action  s     !!#777r    c                 6    | j                         j                  S )z.Check if a new version of Spyder is available.)r-   check_updates_actionr&   s    r!   r  z Application.check_updates_action  r  r    c                 6    | j                         j                  S )z2Open Spyder's Google support group in the browser.)r-   r   r&   s    r!   r   z Application.support_group_action  r  r    c                 6    | j                         j                  S )zShow Spyder's About dialog box.)r-   r   r&   s    r!   r   zApplication.about_action  r  r    c                 6    | j                         j                  S )z4Show Spyder's Windows user env variables dialog box.)r-   r   r&   s    r!   r   zApplication.user_env_action  s     !!#333r    c                 6    | j                         j                  S zRestart Spyder action.)r-   r   r&   s    r!   r   zApplication.restart_action  r
  r    c                 6    | j                         j                  S )z$Restart Spyder in DEBUG mode action.)r-   r   r&   s    r!   r   z Application.restart_debug_action  r  r    c                 6    | j                         j                  S r  )r-   r=   r&   s    r!   r=   zApplication.report_action  s     !!#111r    c                 \    | j                         j                  t        j                        S r,   )r-   get_menur   r   r&   s    r!   r   zApplication.debug_logs_menu  s'    !!#,,"002 	2r    c                 6    | j                         j                  S r,   )r-   rW   r&   s    r!   rW   z%Application.application_update_status  s    !!#===r    )Tr,   )FF)I__name__
__module____qualname__NAMEr   rM   rB   REQUIRESr   r8   rL   rP   rX   OPTIONALr   CONTAINER_CLASSCONF_SECTION	CONF_FILEr   CONF_WIDGET_CLASSCAN_BE_DISABLEDstaticmethodr"   r(   r*   r4   r	   r:   r?   rF   rN   rU   r\   r
   r`   rc   rf   rh   rm   ro   r   rI   rJ   r9   r   r   r   propertyr2   rl   r   r   r   rj   rk   r   r0   r   r   r  r   r   r   r   r  r   r   r   r   r   r=   r   rW   r   r    r!   r   r   &   s]   D!4!45Hg..0A0A 1 13H*OLI-O   ,;+  1 12' 3' 00 10  3 346 56
  0 011 21 /D 0D  1 12H 3H w001N 2N w2238 48 w~~.G /G w/1 01 w//0- 1-(36	.219$G, " "3
//+/
0<#
$ 
V9 9v 9 9 1 1 3 3 8 8 9 9 9 9 1 1 4 4 3 3 9 9 2 2 2 2 > >r    r   )*__doc__r   os.pathpathr   r   rt   qtpy.QtCorer   qtpy.QtWidgetsr   spyder.api.pluginsr   r   spyder.api.translationsr   )spyder.api.plugin_registration.decoratorsr	   r
   spyder.api.widgets.menusr   spyder.config.baser   r   r   r   #spyder.plugins.application.confpager   $spyder.plugins.application.containerr   r   r   spyder.plugins.console.apir   spyder.plugins.mainmenu.apir   r   r   r   spyder.utils.qthelpersr   r   r   r    r!   <module>r4     si   
 
   
    7 %- 36 6 EF F 5M M .d>. d>r    