a
     ³Šaþ+  ã                   @   sÊ   d Z ddlZddlmZmZ ddlmZ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 ddlmZ ddlmZ ddlmZ edƒZG dd„ dƒZG dd„ deƒZdS )z
Help Plugin.
é    N)ÚQtÚSignal)Ú__docs_url__Ú__forum_url__Ú__trouble_url__)ÚPluginsÚSpyderDockablePlugin)Úon_plugin_available)Úget_translation)Úget_conf_path)ÚDEFAULT_SMALL_DELTA)ÚConsoleActions)ÚHelpConfigPage)Ú
HelpWidget)Ú
start_fileÚspyderc                   @   s   e Zd ZdZdS )ÚHelpActionsZspyder_tutorial_actionN)Ú__name__Ú
__module__Ú__qualname__ÚShowSpyderTutorialAction© r   r   ú9lib/python3.9/site-packages/spyder/plugins/help/plugin.pyr   !   s   r   c                       s|  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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(e#ejddd„ ƒZ)dd„ Z*d5dd„Z+d6‡ fdd„	Z,dd „ Z-d!d"„ Z.d7d$d%„Z/d&d'„ Z0d(d)„ Z1d*d+„ Z2d8d-d.„Z3d/d0„ Z4d1d2„ Z5d3d4„ Z6‡  Z7S )9ÚHelpz#
    Docstrings viewer widget.
    ÚhelpFc                 C   s   t dƒS )Nr   ©Ú_©Úselfr   r   r   Úget_nameA   s    zHelp.get_namec                 C   s   t dƒS )Nz;Get rich text documentation from the editor and the consoler   r   r   r   r   Úget_descriptionD   s    ÿzHelp.get_descriptionc                 C   s
   |   d¡S )Nr   )Zcreate_iconr   r   r   r   Úget_iconH   s    zHelp.get_iconc                 C   s`   |   ¡ }|j | j¡ |j | j¡ | |  ¡ ¡ |j | j¡ | jt	j
tdƒ| jdd| _d S )NzSpyder tutorialF)ÚtextZ	triggeredZregister_shortcut)Ú
get_widgetÚsig_render_startedÚconnectÚsig_render_finishedZset_historyÚload_historyZsig_item_foundÚsave_historyZcreate_actionr   r   r   Úshow_tutorialÚtutorial_action)r   Úwidgetr   r   r   Úon_initializeK   s    üzHelp.on_initialize)Zpluginc                 C   s0   |   ¡ }|  tj¡}|j | j¡ | |¡ d S ©N)r#   Ú
get_pluginr   ÚConsoleÚsig_help_requestedr%   Úset_object_textZset_internal_console)r   r+   Zinternal_consoler   r   r   Úon_console_available]   s    zHelp.on_console_availablec                 C   s   |   tj¡}|j | j¡ d S r-   )r.   r   ÚEditorr0   r%   Úset_editor_doc)r   Úeditorr   r   r   Úon_editor_availabled   s    zHelp.on_editor_availablec                 C   sV   |   tj¡}|j | j¡ |j | j¡ |j | j¡ |j	 | j
¡ |j | j¡ d S r-   )r.   r   ÚIPythonConsoleZsig_shellwidget_changedr%   Úset_shellwidgetZsig_shellwidget_createdZsig_render_plain_text_requestedÚshow_plain_textZsig_render_rich_text_requestedÚshow_rich_textr0   r1   )r   Ú
ipyconsoler   r   r   Úon_ipython_console_availablei   s    ÿÿÿz!Help.on_ipython_console_availablec                 C   s   |   tj¡}| | ¡ d S r-   )r.   r   ÚPreferencesZregister_plugin_preferences)r   Zpreferencesr   r   r   Úon_preferences_availablew   s    zHelp.on_preferences_availablec                    s8   ˆ   tj¡}|j ‡ fdd„¡ ˆ  tj¡r4ˆ  ¡  d S )Nc                      s   ˆ   ¡ S r-   )Úshow_intro_messager   r   r   r   Ú<lambda>‚   ó    z-Help.on_shortcuts_available.<locals>.<lambda>)r.   r   Ú	ShortcutsZsig_shortcuts_updatedr%   Úis_plugin_availableÚMainMenuÚ_setup_menus)r   Ú	shortcutsr   r   r   Úon_shortcuts_available|   s    
ÿzHelp.on_shortcuts_availablec                 C   s.   |   tj¡r"|  tj¡r*|  ¡  n|  ¡  d S r-   )Zis_plugin_enabledr   rB   rC   rE   r   r   r   r   Úon_main_menu_available‡   s    
zHelp.on_main_menu_availablec                 C   sL   |   ¡ }|  ¡ }| jdd}|  ¡ }|j||d | ||¡ | |¡ d S )NT)Z	rich_text)Úcolor_scheme)Úget_color_schemeZget_fontr#   Zset_plain_text_fontZset_rich_text_fontÚset_plain_text_color_scheme)r   rI   ZfontZ	rich_fontr+   r   r   r   Úupdate_font   s    zHelp.update_fontc                 C   s   |   ¡  dS )NT)r(   )r   Z
cancelabler   r   r   Úon_close™   s    zHelp.on_closec                    sb   t ƒ  |¡ |  ¡ }d|v r*| |  ¡ ¡ |  tj¡}| dh¡ |  tj	¡}|r^| dh¡ d S )NZcolor_scheme_nameZconnect_to_oi)
ÚsuperÚ
apply_confr#   rK   rJ   r.   r   r3   Zapply_plugin_settingsr7   )r   Zoptions_setZnotifyr+   r5   r;   ©Ú	__class__r   r   rO      s    zHelp.apply_confc                 C   sf   |   tj¡}|   tj¡}d }|r2ddlm} |j}|rbddlm}m	} |j
| j|j|j||jd d S )Nr   )ÚShortcutActions)ÚApplicationMenusÚHelpMenuSections)Zmenu_idZsectionZbeforeZbefore_section)r.   r   rD   rB   Zspyder.plugins.shortcuts.pluginrR   ZShortcutSummaryActionZspyder.plugins.mainmenu.apirS   rT   Zadd_item_to_application_menur*   r   ZDocumentationZSupport)r   ZmainmenurF   Zshortcuts_summary_actionrR   rS   rT   r   r   r   rE   ®   s    ûzHelp._setup_menusc                 C   s$   |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)Z_controlZset_help_enabledZget_confr#   Z	set_shell)r   Zshellwidgetr   r   r   r8   Â   s    	ÿzHelp.set_shellwidgetNc                 C   s`   t j | j¡rXt| jdƒ}| ¡  d¡}W d  ƒ n1 s>0    Y  dd„ |D ƒ}ng }|S )zT
        Load history from a text file in the user configuration directory.
        ÚrÚ
Nc                 S   s   g | ]}|  d d¡‘qS )rV   Ú )Úreplace)Ú.0Úliner   r   r   Ú
<listcomp>×   rA   z%Help.load_history.<locals>.<listcomp>)ÚosÚpathÚisfileÚLOG_PATHÚopenÚreadÚsplit)r   ÚobjÚfhÚlinesÚhistoryr   r   r   r'   Ï   s    ,zHelp.load_historyc              
   C   sj   zLd  |  ¡  ¡ ¡}t| jdƒ}| |¡ W d  ƒ n1 s@0    Y  W n tttfyd   Y n0 dS )zR
        Save history to a text file in the user configuration directory.
        rV   ÚwN)	Újoinr#   Zget_historyr`   r_   ÚwriteÚUnicodeEncodeErrorÚUnicodeDecodeErrorÚEnvironmentError)r   Zsearch_historyrd   r   r   r   r(   Ý   s    ,zHelp.save_historyc                 C   s   |   ¡  |  ¡  ¡  dS )zShow the Spyder tutorial.N)Úswitch_to_pluginr#   r)   r   r   r   r   r)   ê   s    zHelp.show_tutorialc                 C   s   |   ¡  |  ¡  ¡  dS )z&Show the IPython introduction message.N)rm   r#   r?   r   r   r   r   r?   ï   s    zHelp.show_intro_messagerW   c                 C   s    |   ¡  |  ¡ j|||d 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)rm   r#   r:   )r   r"   rn   ro   r   r   r   r:   ô   s    ÿzHelp.show_rich_textc                 C   s   |   ¡  |  ¡  |¡ dS )z†
        Show help in plain mode.

        Parameters
        ----------
        text: str
            Plain text to display.
        N)rm   r#   r9   )r   r"   r   r   r   r9     s    	zHelp.show_plain_textc                 C   s&   |   ¡  |  ¡ j|d |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)rq   N)rm   r#   r1   )r   Zoptions_dictr   r   r   r1     s
    þzHelp.set_object_textc                 C   s*   |  dd¡}|  ¡  |  ¡ j||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)rr   N)Úpoprm   r#   r4   )r   Z	help_datarr   r   r   r   r4   ,  s    þzHelp.set_editor_doc)F)F)N)FrW   )8r   r   r   Ú__doc__ÚNAMEr   r=   r/   r3   ZREQUIRESr7   rB   rD   ZOPTIONALZVariableExplorerZTABIFYr   ZWIDGET_CLASSZCONF_SECTIONr   ZCONF_WIDGET_CLASSZ	CONF_FILEr   r_   r   ZFONT_SIZE_DELTAZDISABLE_ACTIONS_WHEN_HIDDENr   Zsig_focus_changedr$   r&   r   r    r!   r,   r	   r2   r6   r<   r>   rG   rH   rL   rM   rO   rE   r8   r'   r(   r)   r?   r:   r9   r1   r4   Ú__classcell__r   r   rP   r   r   &   sX   
















r   )rt   r\   Zqtpy.QtCorer   r   r   r   r   r   Zspyder.api.pluginsr   r   Z)spyder.api.plugin_registration.decoratorsr	   Zspyder.api.translationsr
   Zspyder.config.baser   Zspyder.config.fontsr   Zspyder.plugins.console.apir   Zspyder.plugins.help.confpager   Zspyder.plugins.help.widgetsr   Zspyder.utils.qthelpersr   r   r   r   r   r   r   r   Ú<module>   s   