
    G@d{0                         d 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
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  G d d          Z G d de          ZdS )z
Help Plugin.
    N)Signal)SpyderAPIError)PluginsSpyderDockablePlugin)on_plugin_availableon_plugin_teardown_)get_conf_path)DEFAULT_SMALL_DELTA)HelpConfigPage)
HelpWidgetc                       e Zd ZdZdS )HelpActionsspyder_tutorial_actionN)__name__
__module____qualname__ShowSpyderTutorialAction     :lib/python3.11/site-packages/spyder/plugins/help/plugin.pyr   r      s        7r   r   c                       e Zd ZdZdZej        ej        ej        gZ	ej
        ej        ej        gZej        ZeZeZeZdZ ee          ZeZdZ e            Z e            Z	  e            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             Z0 e+ej                  d             Z1d Z2d%dZ3d% fd	Z4d Z5d Z6d Z7d&dZ8d Z9d Z:d Z;d'd!Z<d" Z=d# Z>d$ Z? xZ@S )(Helpz#
    Docstrings viewer widget.
    helpFc                       t          d          S )Nr   r	   r   r   r   get_namezHelp.get_name=   s    yyr   c                      t          d          S )Nz;Get rich text documentation from the editor and the consoler	   selfs    r   get_descriptionzHelp.get_descriptionA   s    IK K 	Kr   c                 ,    |                      d          S )Nr   )create_iconr   s    r   get_iconzHelp.get_iconE   s    '''r   c                    |                                  }|j                            | j                   |j                            | j                   |                    |                                            |j                            | j                   |                     t          j
        t          d          | j        d          | _        d S )NzSpyder tutorialF)text	triggeredregister_shortcut)
get_widgetsig_render_startedconnectsig_render_finishedset_historyload_historysig_item_foundsave_historycreate_actionr   r   r
   show_tutorialtutorial_action)r    widgets     r   on_initializezHelp.on_initializeH   s    "" 	!))$*ABBB"**4+CDDD 	4,,..///%%d&7888#110$%%(#	  2  
  
r   )pluginc                     |                                  }|                     t          j                  }|j                            | j                   |                    |           d S N)r)   
get_pluginr   Consolesig_help_requestedr+   set_object_textset_internal_consoler    r4   internal_consoles      r   on_console_availablezHelp.on_console_availableZ   sZ    ""??7?;;+33D4HIII##$455555r   c                     |                      t          j                  }|j                            | j                   d S r8   )r9   r   Editorr;   r+   set_editor_docr    editors     r   on_editor_availablezHelp.on_editor_availablea   s5    00!))$*=>>>>>r   c                 z   |                      t          j                  }|j                            | j                   |j                            | j                   |j                            | j                   |j	                            | j
                   |j                            | j                   d S r8   )r9   r   IPythonConsolesig_shellwidget_changedr+   set_shellwidgetsig_shellwidget_createdsig_render_plain_text_requestedshow_plain_textsig_render_rich_text_requestedshow_rich_textr;   r<   r    
ipyconsoles     r   on_ipython_console_availablez!Help.on_ipython_console_availablef   s    __W%;<<
*2243GHHH*2243GHHH2:: 	" 	" 	"199	! 	! 	! 	%--d.BCCCCCr   c                 n    |                      t          j                  }|                    |            d S r8   )r9   r   Preferencesregister_plugin_preferencesr    preferencess     r   on_preferences_availablezHelp.on_preferences_availables   s0    oog&9:://55555r   c                     |                      t          j                  }|j                            | j                   |                     t          j                  r|                                  d S d S r8   )	r9   r   	Shortcutssig_shortcuts_updatedr+   show_intro_messageis_plugin_availableMainMenu_setup_menusr    	shortcutss     r   on_shortcuts_availablezHelp.on_shortcuts_availablex   sm    OOG$566	 	'//0GHHH##G$455 	 	  	 r   c                     |                      t          j                  r7|                     t          j                  r|                                  d S d S |                                  d S r8   )is_plugin_enabledr   rZ   r]   r_   r   s    r   on_main_menu_availablezHelp.on_main_menu_available   sp    !!'"344 	 ''(9:: $!!#####$ $ r   c                     |                                  }|                     t          j                  }|j                            | j                   |                    d            d S r8   )r)   r9   r   r:   r;   
disconnectr<   r=   r>   s      r   on_console_teardownzHelp.on_console_teardown   sY    ""??7?;;+66t7KLLL##D)))))r   c                     |                      t          j                  }|j                            | j                   d S r8   )r9   r   rB   r;   rg   rC   rD   s     r   on_editor_teardownzHelp.on_editor_teardown   s5    00!,,T-@AAAAAr   c                 z   |                      t          j                  }|j                            | j                   |j                            | j                   |j                            | j                   |j	                            | j
                   |j                            | j                   d S r8   )r9   r   rH   rI   rg   rJ   rK   rL   rM   rN   rO   r;   r<   rP   s     r   on_ipython_console_teardownz Help.on_ipython_console_teardown   s    __W%;<<
*55d6JKKK*55 	" 	" 	"2== 	" 	" 	"1<<	! 	! 	! 	%001EFFFFFr   c                 n    |                      t          j                  }|                    |            d S r8   )r9   r   rT   deregister_plugin_preferencesrV   s     r   on_preferences_teardownzHelp.on_preferences_teardown   s0    oog&9::11$77777r   c                     |                      t          j                  }|j                            | j                   d S r8   )r9   r   rZ   r[   rg   r\   r`   s     r   on_shortcuts_teardownzHelp.on_shortcuts_teardown   s6    OOG$566	'2243JKKKKKr   c                 .    |                                   d S r8   )_remove_menusr   s    r   on_main_menu_teardownzHelp.on_main_menu_teardown   s    r   c                 .   |                                  }|                                 }|                     d          }|                                 }|                    ||           |                    ||           |                    |           d S )NT)	rich_text)color_scheme)get_color_schemeget_fontr)   set_plain_text_fontset_rich_text_fontset_plain_text_color_scheme)r    rw   font	rich_fontr4   s        r   update_fontzHelp.update_font   s    ,,..}}MMDM11	""""4l"CCC!!)T222**<88888r   c                 .    |                                   dS )NT)r0   )r    
cancelables     r   on_closezHelp.on_close   s    tr   c                     t                                          |           	 |                     t          j                  }|                    dh           d S # t          $ r Y d S w xY w)Nconnect_to_oi)super
apply_confr9   r   rB   apply_plugin_settingsr   )r    options_setnotifyrE   	__class__s       r   r   zHelp.apply_conf   sr    ;'''	__W^44F((/):;;;;; 	 	 	DD	s   5A 
A)(A)c                    |                      t          j                  }|                      t          j                  }d }|rddlm} |j        }|r8ddlm}m	} |
                    | j        |j        |j        ||j                   d S d S )Nr   )ShortcutActions)ApplicationMenusHelpMenuSections)menu_idsectionbeforebefore_section)r9   r   r^   rZ   spyder.plugins.shortcuts.pluginr   ShortcutSummaryActionspyder.plugins.mainmenu.apir   r   add_item_to_application_menur3   r   DocumentationSupport)r    mainmenura   shortcuts_summary_actionr   r   r   s          r   r_   zHelp._setup_menus   s    ??7#344OOG$566	#'  	MGGGGGG'6'L$ 		94 4 4 4 4 4 4 4 11$(-(6//7 2 9 9 9 9 9			9 		9r   c                     ddl m} |                     t          j                  }|                    t          j        |j                   d S )Nr   )r   )r   )	r   r   r9   r   r^   !remove_item_from_application_menur   r   r   )r    r   r   s      r   rs   zHelp._remove_menus   s[    @@@@@@??7#344220$) 	3 	+ 	+ 	+ 	+ 	+r   c                     |j                             |                     d                     |                                                     |           dS )a  
        Set IPython Console `shelwidget` as the current shellwidget.

        Parameters
        ----------
        shellwidget: spyder.plugins.ipyconsole.widgets.shell.ShellWidget
            The shell widget that is going to be connected to Help.
        zconnect/ipython_consoleN)_controlset_help_enabledget_confr)   	set_shell)r    shellwidgets     r   rJ   zHelp.set_shellwidget   sS     	--MM344	6 	6 	6##K00000r   Nc                    t           j                            | j                  rat	          | j        d          5 }|                                                    d          }ddd           n# 1 swxY w Y   d |D             }ng }|S )zT
        Load history from a text file in the user configuration directory.
        r
Nc                 :    g | ]}|                     d d          S )r    )replace).0lines     r   
<listcomp>z%Help.load_history.<locals>.<listcomp>   s&    @@@$t||D"--@@@r   )ospathisfileLOG_PATHopenreadsplit)r    objfhlineshistorys        r   r.   zHelp.load_history   s     7>>$-(( 	dmS)) .R		--. . . . . . . . . . . . . . . A@%@@@GGGs   (A..A25A2c                 <   	 d                     |                                                                           }t          | j        d          5 }|                    |           ddd           dS # 1 swxY w Y   dS # t          t          t          f$ r Y dS w xY w)zR
        Save history to a text file in the user configuration directory.
        r   wN)	joinr)   get_historyr   r   writeUnicodeEncodeErrorUnicodeDecodeErrorEnvironmentError)r    search_historyr   s      r   r0   zHelp.save_history  s    	!YYt'8'8'D'D'F'FGGNdmS)) )R((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )"$68HI 	 	 	DD	s6   AB  A3&B  3A77B  :A7;B   BBc                 z    |                                   |                                                                  dS )zShow the Spyder tutorial.N)switch_to_pluginr)   r2   r   s    r   r2   zHelp.show_tutorial  s6    '')))))r   c                 R    |                                                                   dS )z&Show the IPython introduction message.N)r)   r\   r   s    r   r\   zHelp.show_intro_message  s$    ,,.....r   r   c                     |                                   |                                                     |||           dS )a  
        Show help in rich mode.

        Parameters
        ----------
        text: str
            Plain text to display.
        collapse: bool, optional
            Show collapsable sections as collapsed/expanded. Default is False.
        img_path: str, optional
            Path to folder with additional images needed to correctly
            display the rich text help. Default is ''.
        )collapseimg_pathN)r   r)   rO   )r    r&   r   r   s       r   rO   zHelp.show_rich_text  sN     	((2: 	) 	< 	< 	< 	< 	<r   c                 |    |                                   |                                                     |           dS )z
        Show help in plain mode.

        Parameters
        ----------
        text: str
            Plain text to display.
        N)r   r)   rM   )r    r&   s     r   rM   zHelp.show_plain_text*  s:     	))$/////r   c                     |                                   |                                                     |d         |d                    dS )a  
        Set object's name in Help's combobox.

        Parameters
        ----------
        options_dict: dict
            Dictionary of data. See the example for the expected keys.

        Examples
        --------
        >>> help_data = {
            'name': str,
            'force_refresh': bool,
        }

        See Also
        --------
        :py:meth:spyder.widgets.mixins.GetHelpMixin.show_object_info
        nameignore_unknown)r   N)r   r)   r<   )r    options_dicts     r   r<   zHelp.set_object_text6  sX    ( 	)) '(89 	* 	
 	
 	
 	
 	
r   c                     |                     dd          }|                                  |                                                     ||           dS )aE  
        Set content for help data sent from the editor.

        Parameters
        ----------
        help_data: dict
            Dictionary of data. See the example for the expected keys.

        Examples
        --------
        >>> help_data = {
            'obj_text': str,
            'name': str,
            'argspec': str,
            'note': str,
            'docstring': str,
            'force_refresh': bool,
            'path': str,
        }

        See Also
        --------
        :py:meth:spyder.plugins.editor.widgets.editor.EditorStack.send_to_help
        force_refreshF)r   N)popr   r)   rC   )r    	help_datar   s      r   rC   zHelp.set_editor_docP  s`    2 "ou==((' 	) 	
 	
 	
 	
 	
r   )Fr8   )Fr   )Ar   r   r   __doc__NAMEr   rT   r:   rB   REQUIRESrH   rZ   r^   OPTIONALVariableExplorerTABIFYr   WIDGET_CLASSCONF_SECTIONr   CONF_WIDGET_CLASS	CONF_FILEr   r   r   FONT_SIZE_DELTADISABLE_ACTIONS_WHEN_HIDDENr   sig_focus_changedr*   r,   staticmethodr   r!   r$   r5   r   r@   rF   rR   rX   rb   re   r   rh   rj   rl   ro   rq   rt   r   r   r   r_   rs   rJ   r.   r0   r2   r\   rO   rM   r<   rC   __classcell__)r   s   @r   r   r   "   s         D#W_gnEH&(97;KLH%FLL&I}\**H)O"' M &((N   \K K K( ( (
 
 
$ 0006 6 106 ///? ? 0/?  6777
D 
D 87
D  34446 6 546  1222    32   0111    21  w///* * 0/* w~...B B /.B w5666G G 76G w23338 8 438 w0111L L 21L w/000  109 9 9        9 9 9$+ + +1 1 1     * * *
/ / /< < < <$
0 
0 
0
 
 
4
 
 
 
 
 
 
r   r   )r   r   qtpy.QtCorer   spyder.api.exceptionsr   spyder.api.pluginsr   r   )spyder.api.plugin_registration.decoratorsr   r   spyder.api.translationsr
   spyder.config.baser   spyder.config.fontsr   spyder.plugins.help.confpager   spyder.plugins.help.widgetsr   r   r   r   r   r   <module>r      sC   
 
			       1 0 0 0 0 0 < < < < < < < <- - - - - - - - % % % % % % , , , , , , 3 3 3 3 3 3 7 7 7 7 7 7 2 2 2 2 2 28 8 8 8 8 8 8 8
L
 L
 L
 L
 L
 L
 L
 L
 L
 L
r   