
    Je{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y)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y)HelpActionsspyder_tutorial_actionN)__name__
__module____qualname__ShowSpyderTutorialAction     </usr/lib/python3/dist-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    y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r   c                 $    | j                  d      S )Nr   )create_iconr   s    r   get_iconzHelp.get_iconE   s    ''r   c                    | j                         }|j                  j                  | j                         |j                  j                  | j                         |j	                  | j                                |j                  j                  | j                         | j                  t        j                  t        d      | j                  d      | _        y )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*AB""**4+C+CD 	4,,./%%d&7&78#1100$%((#	  2  
r   )pluginc                     | j                         }| j                  t        j                        }|j                  j                  | j                         |j                  |       y 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   sJ    "??7??;++33D4H4HI##$45r   c                     | j                  t        j                        }|j                  j	                  | j
                         y r8   )r9   r   Editorr;   r+   set_editor_docr    editors     r   on_editor_availablezHelp.on_editor_availablea   s.    0!!))$*=*=>r   c                    | j                  t        j                        }|j                  j	                  | j
                         |j                  j	                  | j
                         |j                  j	                  | j                         |j                  j	                  | j                         |j                  j	                  | j                         y 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243G3GH**2243G3GH22::  	"1199	! 	%%--d.B.BCr   c                 d    | j                  t        j                        }|j                  |        y r8   )r9   r   Preferencesregister_plugin_preferencesr    preferencess     r   on_preferences_availablezHelp.on_preferences_availables   s$    oog&9&9://5r   c                     | j                  t        j                        }|j                  j	                  | j
                         | j                  t        j                        r| j                          y y 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   sW    OOG$5$56	 	''//0G0GH##G$4$45 6r   c                     | j                  t        j                        r1| j                  t        j                        r| j	                          y y | j	                          y r8   )is_plugin_enabledr   rZ   r]   r_   r   s    r   on_main_menu_availablezHelp.on_main_menu_available   sI    !!'"3"34''(9(9:!!# ; r   c                     | j                         }| j                  t        j                        }|j                  j                  | j                         |j                  d        y r8   )r)   r9   r   r:   r;   
disconnectr<   r=   r>   s      r   on_console_teardownzHelp.on_console_teardown   sI    "??7??;++66t7K7KL##D)r   c                     | j                  t        j                        }|j                  j	                  | j
                         y r8   )r9   r   rB   r;   rg   rC   rD   s     r   on_editor_teardownzHelp.on_editor_teardown   s.    0!!,,T-@-@Ar   c                    | j                  t        j                        }|j                  j	                  | j
                         |j                  j	                  | j
                         |j                  j	                  | j                         |j                  j	                  | j                         |j                  j	                  | j                         y 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5d6J6JK**55  	"22==  	"11<<	! 	%%001E1EFr   c                 d    | j                  t        j                        }|j                  |        y r8   )r9   r   rT   deregister_plugin_preferencesrV   s     r   on_preferences_teardownzHelp.on_preferences_teardown   s$    oog&9&9:11$7r   c                     | j                  t        j                        }|j                  j	                  | j
                         y r8   )r9   r   rZ   r[   rg   r\   r`   s     r   on_shortcuts_teardownzHelp.on_shortcuts_teardown   s0    OOG$5$56	''2243J3JKr   c                 $    | j                          y r8   )_remove_menusr   s    r   on_main_menu_teardownzHelp.on_main_menu_teardown   s    r   c                     | j                         }| j                         }| j                  d      }| j                         }|j                  ||       |j	                  ||       |j                  |       y )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   sh    ,,.}}MMDM1	"""4l"C!!)T2**<8r   c                 $    | j                          y)NT)r0   )r    
cancelables     r   on_closezHelp.on_close   s    r   c                     t         |   |       	 | j                  t        j                        }|j                  dh       y # t        $ r Y y 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   sJ    ;'	__W^^4F((/):; 		s   1A 	AAc                 >   | j                  t        j                        }| j                  t        j                        }d }|rddlm} |j                  }|rGddlm}m	} |j                  | j                  |j                  |j                  ||j                         y y )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#34OOG$5$56	#' G'6'L'L$4 11$$(--(66//77 2 9	 r   c                     ddl m} | j                  t        j                        }|j                  t        j                  |j                         y )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#342200$)) 	3 	+r   c                     |j                   j                  | j                  d             | j                         j	                  |       y)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   s:     	--MM34	6##K0r   c                 <   t         j                  j                  | j                        r_t	        | j                  d      5 }|j                         j                  d      }ddd       D cg c]  }|j                  dd       }}|S g }|S # 1 sw Y   .xY wc c}w )zT
        Load history from a text file in the user configuration directory.
        r
N )ospathisfileLOG_PATHopenreadsplitreplace)r    objfhlineslinehistorys         r   r.   zHelp.load_history   s     77>>$--(dmmS) .R	-. ;@@$t||D"-@G@  G. . As     B,BBc                    	 dj                  | j                         j                               }t        | j                  d      5 }|j                  |       ddd       y# 1 sw Y   yxY w# t        t        t        f$ r Y y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  sp    	!YYt'8'D'D'FGNdmmS) )R() ) )"$68HI 		s0   AA, A A,  A)%A, )A, ,BBc                 `    | j                          | j                         j                          y)zShow the Spyder tutorial.N)switch_to_pluginr)   r2   r   s    r   r2   zHelp.show_tutorial  s!    '')r   c                 @    | j                         j                          y)z&Show the IPython introduction message.N)r)   r\   r   s    r   r\   zHelp.show_intro_message  s    ,,.r   c                 h    | j                          | j                         j                  |||       y)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  s1     	((2: 	) 	<r   c                 b    | j                          | j                         j                  |       y)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                 r    | j                          | j                         j                  |d   |d          y)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  s;    ( 	)) '(89 	* 	
r   c                     |j                  dd      }| j                          | j                         j                  ||       y)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   "   sz    D##W__gnnEH&&(9(97;K;KLH%%FLL&I\*H)O"' M (N  K(
$ 06 16 /? 0?  6 67
D 8
D  3 346 56  1 12  3   0 01  2  w/* 0* w~~.B /B w556G 7G w2238 48 w001L 2L w//0 199$+1*
/<$
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      sI   
 
  1 <- % , 3 7 28 8
L
 L
r   