a
    a                     @   s  d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZmZmZmZmZmZmZ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%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> edZ?e4j@ZAG dd dZBG dd dZCG dd dZDG dd dZEG d d! d!e:ZFG d"d# d#ee!ZGG d$d% d%eZHG d&d' d'eZIdS )(z
Help plugin widgets.
    N)QtQUrlSignalSlotQPoint)QColor)	WEBENGINEQWebEnginePage)	QActionGroup	QComboBoxQLabel	QLineEditQMessageBoxQSizePolicyQStackedLayoutQVBoxLayoutQWidget)on_conf_change)get_translation)PluginMainWidget)SpyderWidgetMixin)get_module_source_path)CSS_PATHgenerate_contextloadingusagewarning)SphinxThread)get_meth_class_instto_text_string)programs)get_image_path)QStylePalette)
start_file)FrameWebView)EditableComboBox)FindReplace)SimpleCodeEditorZspyderc                   @   s0   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
S )HelpWidgetActionsZtoggle_automatic_import_actionZtoggle_locked_actionZtoggle_plain_mode_actionZtoggle_rich_mode_actionZtoggle_show_source_actionZtoggle_wrap_actionZhelp_widget_copy_action)select_all_actionhome_actionN)__name__
__module____qualname__ToggleAutomaticImportToggleLockedTogglePlainModeToggleRichModeToggleShowSource
ToggleWrap
CopyAction	SelectAllHome r7   r7   :lib/python3.9/site-packages/spyder/plugins/help/widgets.pyr(   5   s   r(   c                   @   s   e Zd ZdZdZdS )HelpWidgetOptionsMenuSectionsZdisplay_sectionZother_sectionN)r+   r,   r-   DisplayOtherr7   r7   r7   r8   r9   B   s   r9   c                   @   s   e Zd ZdZdS )HelpWidgetMainToolbarSectionsZmain_sectionN)r+   r,   r-   Mainr7   r7   r7   r8   r<   G   s   r<   c                   @   s    e Zd ZdZdZdZdZdZdS )HelpWidgetToolbarItemssource_labelsource_comboobject_labelobject_comboobject_editN)r+   r,   r-   SourceLabelSourceComboObjectLabelObjectCombo
ObjectEditr7   r7   r7   r8   r>   K   s
   r>   c                   @   s@   e Zd ZdZeeeZdddZdddZdd Z	dd
dZ
dS )ObjectComboBoxz)
    QComboBox handling object names
    Nc                 C   s@   t | | || _| tjtj ddd| _|d ur<|| _d S )N )TF)	r%   __init__helpZsetSizePolicyr   Z	ExpandingZFixedtipsID)selfparentZid_r7   r7   r8   rK   \   s    zObjectComboBox.__init__c                 C   s   | j  sdS |du r|  }tdt|ds4dS t|}d}| j drj| j j}|durj|j	|dd}|s| j 
 }|durz|	|}W nB tjy   | j 
 }z|	|}W n tjy   Y n0 Y n0 |S )zReturn True if string is validTNz^[a-zA-Z0-9_\.]*$r   Fautomatic_importZforce_import)rL   source_is_consolecurrentTextresearchstrr   get_confinternal_shell
is_defined	get_shellsocketerror)rO   qstrZobjtxtZshell_is_definedshellr7   r7   r8   is_valide   s0    


zObjectComboBox.is_validc                 C   s   |  |   d S N)validaterT   rO   r7   r7   r8   validate_current_text   s    z$ObjectComboBox.validate_current_textTc                 C   sp   |  |}|  rl|durl|rB|sB| | j|  | jdd n*|r^|   |  d n| jdd dS )z)Reimplemented to avoid formatting actionsNF)	r`   ZhasFocusZshow_tiprM   validemitZselectedlineEditZcursorWordForward)rO   r^   editingre   r7   r7   r8   rb      s    
zObjectComboBox.validate)N)N)T)r+   r,   r-   __doc__r   boolre   rK   r`   rd   rb   r7   r7   r7   r8   rI   U   s   

	
rI   c                       sJ   e Zd ZdZeeZ fddZdddZdd Z	d	d
 Z
dd Z  ZS )RichTextz)
    WebView widget with find dialog
    c                    s   t  j||d t| | _| j  tr@| jj t	t
 n&| jjdt
 | j tj t| | _| j| jj | j  t }|dddd || j || j | | | jj| j d S )N)Zclass_parentzbackground:{}r   )superrK   r$   webviewsetupr   Z
web_widgetZpageZsetBackgroundColorr   MAIN_BG_COLORZsetStyleSheetformatZsetLinkDelegationPolicyr	   ZDelegateAllLinksr&   find_widget
set_editorhider   setContentsMargins	addWidget	setLayoutZlinkClickedconnectsig_link_clickedrO   rP   layout	__class__r7   r8   rK      s,    





zRichText.__init__Nc                 C   s   | j j||d dS )Set font
fixed_fontN)rm   set_fontrO   fontr   r7   r7   r8   r      s    zRichText.set_fontc                 C   s   | j || dS )zSet html textN)rm   ZsetHtmlrO   	html_textZbase_urlr7   r7   r8   set_html   s    zRichText.set_htmlc                 C   s&   t |tr|}nt|}| | d S ra   )
isinstancer   load)rO   urlZqurlr7   r7   r8   load_url   s    
zRichText.load_urlc                 C   s   |  d| j  d S )NrJ   )r   rm   r   rc   r7   r7   r8   clear   s    zRichText.clear)N)r+   r,   r-   ri   r   r   rx   rK   r   r   r   r   __classcell__r7   r7   r{   r8   rk      s   
rk   c                   @   s`   e Zd ZdZe ZeeZdd ZdddZ	dd Z
d	d
 Zdd Zdd Zdd Zdd ZdS )	PlainTextz2
    Read-only editor widget with find dialog
    c                 C   s   t | | d | _t| | _| jjdddd | jj| j | jd | j	t
j t| | _| j| j | j  t }|dddd || j || j | | | jj| j d S )NpyF)ZlanguageZhighlight_current_lineZlinenumbersTr   )r   rK   editorr'   Zsetup_editorZsig_focus_changedrw   focus_changedsetReadOnlyZsetContextMenuPolicyr   ZCustomContextMenur&   rq   rr   rs   r   rt   ru   rv   ZcustomContextMenuRequested!sig_custom_context_menu_requestedry   r7   r7   r8   rK      s,    



zPlainText.__init__Nc                 C   s   | j | | j | dS )r}   N)r   set_color_schemer   rO   r   color_schemer7   r7   r8   r      s    zPlainText.set_fontc                 C   s   | j | dS )zSet color schemeN)r   r   rO   r   r7   r7   r8   r      s    zPlainText.set_color_schemec                 C   s:   |r| j d n| j d  | j | | j d d S )Nr   Zsof)r   Zset_languageset_textZset_cursor_position)rO   textis_coder7   r7   r8   r      s
    zPlainText.set_textc                 C   s   | j   d S ra   )r   r   rc   r7   r7   r8   r     s    zPlainText.clearc                 C   s   | j | d S ra   )r   Ztoggle_wrap_moderO   valuer7   r7   r8   set_wrap_mode  s    zPlainText.set_wrap_modec                 C   s   | j   d S ra   )r   copyrc   r7   r7   r8   r     s    zPlainText.copyc                 C   s   | j   d S ra   )r   	selectAllrc   r7   r7   r8   
select_all  s    zPlainText.select_all)N)r+   r,   r-   ri   r   r   r   r   rK   r   r   r   r   r   r   r   r7   r7   r7   r8   r      s   
	r   c                       s  e Zd ZdZe Ze Ze Zdc fdd	Zdd Z	dd Z
d	d
 Zedddd Zedddd Zedddd Zedddd Zedddd Zdd Zdd Zee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/d0 Zed1d2 Z d3d4 Z!d5d6 Z"d7d8 Z#d9d: Z$d;d< Z%d=d> Z&dddAdBZ'dCdD Z(e dEdF Z)dGdH Z*e ee+ee+e+dedIdJZ,dfdKdLZ-dgdMdNZ.dOdP Z/dQdR Z0de1fdSdTZ2dhdUdVZ3dWdX Z4didYdZZ5d[d\ Z6d]d^ Z7d_d` Z8dadb Z9  Z:S )j
HelpWidgetTNc                    s(  t  ||| d _d  _d d g _d  _d  _d  _ dt	d _
td _d _tt j j
d j
d _d  _d  _d  _t  _t  _ttd _tj j_t  _tj j_ttd _ tj! j _t" tj# _$t%  _&tj' j&_ j&(d  j$) d	  j$*d
d  j+ d  j,tdtdg t-.dst-.dds j/   j/  t0   _1}|2 j |2 j  3|  jj45 j6  jj75 j8  j$j95 j:  jj;5 j<  jj=5 fdd  j>5 j?  j@5 jA d S )NTcss_pathZ
appearancezNo documentation availabler   )Zhtml_text_no_docr   ZSourceZObjectZmax_history_entriesr   rJ   wrapZConsoleZEditorZropeZjediz>=0.11.0c                    s      S ra   )source_changed)xrc   r7   r8   <lambda>a      z%HelpWidget.__init__.<locals>.<lambda>)Brl   rK   Z_starting_up_current_color_scheme_last_texts_last_editor_doc_last_console_cb_last_editor_cbrX   r   r   _no_docs	docstringr   r   _sphinx_threadr_   internal_consolerY   r   
plain_textrk   	rich_textr   r?   r>   rD   rN   r   r@   rE   rA   rF   rI   rG   rB   r   rC   rH   r   ZsetMaxCountZsetItemTextr   addItemsr    Zis_module_installedrs   r   stack_layoutru   rv   Z
html_readyrw   _on_sphinx_thread_html_ready	error_msg_on_sphinx_thread_error_msgre   force_refreshrx   handle_link_clicksZcurrentIndexChangedsig_render_startedZstart_spinnersig_render_finishedstop_spinner)rO   nameZpluginrP   rz   r{   rc   r8   rK      sr    














zHelpWidget.__init__c                 C   s   t dS )NHelp)r   rc   r7   r7   r8   	get_titleg  s    zHelpWidget.get_titlec                    sX   j tjtdd ddd _ j tjtd fdddd	 _ j tjtd
 fdddd	 _	 j tj
tdd ddd _ j tjtdddd _ j tjtdd ddd _ j tjtdd ddd _ j tjtdd d ddd _ j tjtd j dd _t }|d | j | j   } j j jfD ]} j||tjd qt j j|tjd   d _! j j j!dd  j j	 j!d d  j j j!d!d  " } j# j$ j% j& j' j jfD ]} j(||t)j*d" q +   ,      j-j./ j0 d S )#Nz
Wrap linesTr   )r   r   toggledinitialoptionZCopyc                    s
    j  S ra   )r   r   r   rc   r7   r8   r   u  r   z"HelpWidget.setup.<locals>.<lambda>F)r   r   	triggeredZregister_shortcutz
Select Allc                    s
    j  S ra   )r   r   r   rc   r7   r8   r   {  r   zAutomatic importrQ   zShow Sourceshow_source)r   r   r   r   z	Rich Text	rich_modez
Plain Text
plain_modezLock/Unlock	lock_openlocked)r   r   r   iconr   r   r6   home)r   r   r   r   )menusectionZplain_text_context_menuZcopy_sectionr   Zselect_sectionZwrap_section)toolbarr   )1Zcreate_actionr(   r3   r   rX   Zwrap_actionr4   Zcopy_actionr5   r)   r.   Zauto_import_actionr2   Zshow_source_actionr1   Zrich_text_actionr0   plain_text_actionr/   create_iconZlocked_actionr6   show_intro_messager*   r
   ZsetExclusive	addActionZget_options_menuZadd_item_to_menur9   r:   r;   Zcreate_menu_plain_text_context_menuZget_main_toolbarr?   r@   rA   rB   rC   Zadd_item_to_toolbarr<   r=   r   switch_to_rich_textr   r   rw   _show_plain_text_context_menu)rO   Zhelp_actionsr   itemr   r7   rc   r8   rn   j  s    




zHelpWidget.setupc                 C   s   | j du p| jdu p| jdu S )z7Determine if the help welcome page should be displayed.N)r   r   r   rc   r7   r7   r8   _should_display_welcome_page  s
    
z'HelpWidget._should_display_welcome_pager   )r   c                 C   s   | j | d S ra   )r   r   r   r7   r7   r8   on_wrap_option_update  s    z HelpWidget.on_wrap_option_updater   c                 C   sN   |r|  d}td}n|  d}td}| tj}|| || d S )NlockZUnlockr   ZLock)r   r   
get_actionr(   r/   ZsetIconZ
setToolTip)rO   r   r   Ztipactionr7   r7   r8   on_lock_update  s    



zHelpWidget.on_lock_updaterQ   c                 C   s(   | j   |  r|   n|   d S ra   )rB   rd   r   r   r   r   r7   r7   r8   on_automatic_import_update  s    

z%HelpWidget.on_automatic_import_updater   c                 C   s`   |r.| | _ | j| j | tjd n|| _ | j| j | 	 rT| 
  n|   d S NF)r   r   ZsetCurrentWidgetr   r   r(   r2   
setCheckedr   r   r   r   r   r7   r7   r8   on_rich_mode_update  s    
zHelpWidget.on_rich_mode_updater   c                 C   sD   |r|    | tjd | | _|  r8|   n|   d S r   )	switch_to_plain_textr   r(   r1   r   r   r   r   r   r   r7   r7   r8   on_show_source_update  s    
z HelpWidget.on_show_source_updatec                 C   sN   |    D ]<\}}| j| j| j| j| jfD ]}|| vr,|| q,qd S ra   )	Zget_actionsitemsr   r   r@   rB   rC   Zactionsr   )rO   __r   Zwidgetr7   r7   r8   update_actions"  s    zHelpWidget.update_actionsc                 C   s   | j    | j S ra   )rB   rg   r   rc   r7   r7   r8   get_focus_widget0  s    zHelpWidget.get_focus_widgetc                 C   s   | j |}| j| d S ra   )r   ZmapToGlobalr   Zpopup)rO   Zpointr7   r7   r8   r   6  s    z(HelpWidget._show_plain_text_context_menuc                 C   s4   | j   | |t| j | j  |   dS )z
        Set our sphinx documentation based on thread result.

        Parameters
        ----------
        html_text: str
            Html results text.
        N)	r   waitset_rich_text_htmlr   fromLocalFiler   r   rf   r   )rO   r   r7   r7   r8   r   ;  s    	

z'HelpWidget._on_sphinx_thread_html_readyc                 C   sL   | j   | jd td}t| tdtd||f  | j	
  dS )z
        Display error message on Sphinx rich text failure.

        Parameters
        ----------
        error_msg: str
            Error message text.
        TZsphinxr   zThe following error occurred when calling <b>Sphinx %s</b>. <br>Incompatible Sphinx version or doc string decoding failed.<br><br>Error message:<br>%sN)r   r   r   r   r    Zget_module_versionr   Zcriticalr   r   rf   )rO   r   Z
sphinx_verr7   r7   r8   r   I  s    	

	z&HelpWidget._on_sphinx_thread_error_msgc                 C   s   | j  dkS )z!Return True if source is Console.r   )r@   currentIndexrc   r7   r7   r8   rS   b  s    zHelpWidget.source_is_consolec                 C   s   | j d dS )z)Switch to editor view of the help viewer.   Nr@   ZsetCurrentIndexrc   r7   r7   r8   switch_to_editor_sourcef  s    z"HelpWidget.switch_to_editor_sourcec                 C   s   | j d dS )z*Switch to console view of the help viewer.r   Nr   rc   r7   r7   r8   switch_to_console_sourcej  s    z#HelpWidget.switch_to_console_sourcec                 C   sf   |   }|r"| j  | j  n| j  | j  | tj| | tj	| | 
  dS )z$Handle a source (plain/rich) change.N)rS   rB   ZshowrC   rs   r   r(   r2   Z
setEnabledr.   restore_text)rO   Z
is_consoler7   r7   r8   r   n  s    


zHelpWidget.source_changedc                 C   s   |   r|| _n|| _dS )z
        Save help text.

        Parameters
        ----------
        callback: callable
            Method to call on save.
        N)rS   r   r   )rO   callbackr7   r7   r8   	save_text  s    	zHelpWidget.save_textc                 C   s|   |   r| j}n| j}|du r<| dr2|   qx|   n<|d }|dd }||  t|| ju rp|   n|   dS )z!Restore last text using callback.Nr   r   r   )rS   r   r   rX   r   r   r   r   )rO   cbfuncargsr7   r7   r8   r     s    



zHelpWidget.restore_textc                 C   s   |  dr| jjS | jjS dS )zShow find widget.r   N)rX   r   rq   r   rc   r7   r7   r8   rq     s    
zHelpWidget.find_widgetc                 C   s   |  tjd dS )zSwitch to plain text mode.TN)r   r(   r0   r   rc   r7   r7   r8   r     s    zHelpWidget.switch_to_plain_textc                 C   s   |  tjd dS )zSwitch to rich text mode.TN)r   r(   r1   r   rc   r7   r7   r8   r     s    zHelpWidget.switch_to_rich_textc              	   C   s   t |tu r|d }|r@ddt| d|ddt| dg}nd}zJ|d rfdd||d dg}nd}|d rdd	|d d
g}nd}W n ty   | j}d}Y n0 d||||d g}n|}| j|| | | jj||g dS )a  
        Set plain text docs.

        Parameters
        ----------
        text: str
            Text content.
        is_code: bool
            True if it is code text.

        Notes
        -----
        Text is coming from utils.dochelpers.getdoc
        r   rJ   =


ZargspeczDefinition: notezType: z

----

r   N)	typedictjoinlen	TypeErrorr   r   r   r   )rO   r   r   r   Z	rst_titleZ
definitionr   Z	full_textr7   r7   r8   set_plain_text  s2    

zHelpWidget.set_plain_textc                 C   s&   | j || | | j j||g dS )z
        Set rich text.

        Parameters
        ----------
        html_text: str
            Html string.
        base_url: str
            Location of stylesheets and images to load in the page.
        N)r   r   r   r   r7   r7   r8   r     s    zHelpWidget.set_rich_text_htmlc                 C   sT   | j   td}td}tjdkr0|dd}| t||| j	dt
| j	 dS )z>Create html page to show while the documentation is generated.zRetrieving documentationZloading_spritesnt\/r   N)r   rf   r   r!   osr   replacer   r   r   r   r   )rO   Zloading_messageZloading_imgr7   r7   r8   show_loading_message  s    


zHelpWidget.show_loading_messagec              	   C   sV  t d}t d}t d}t d}| jddd}| jddd}tjd	kr^|d
d}|d
d}| drt d}t d}t d}	||kr|| d| d dd| d f }
n,|| d| d d| d dd| d f }
| t||
||	| jdt	| j nTdt d }||kr(|| |d|f }
n|| ||d|f }
|
|7 }
| j
|
dd dS )z.Show message on Help with the right shortcuts.ziHere you can get help of any object by pressing %s in front of it, either on the Editor or the Console.%szwHere you can get help of any object by pressing %s in front of it on the Editor, or %s in front of it on the Console.%sz~Help can also be shown automatically after writing a left parenthesis next to an object. You can activate this behavior in %s.zPreferences > Helpzeditor/inspect current objectZ	shortcutsr   zconsole/inspect current objectdarwinZCtrlZCmdr   ZUsagezNew to Spyder? Read ourtutorialz<b>z</b>z<br><br>z<i>z</i>r   z

%szMPlease consider installing Sphinx to get documentation rendered in rich text.r   Fr   N)r   rX   sysplatformr  r   r   r   r   r   r   )rO   Zintro_message_eqZintro_message_difZintro_message_commonZprefsZshortcut_editorZshortcut_consoletitleZtutorial_messager  Zintro_messageZinstall_sphinxr7   r7   r8   r     sb    







zHelpWidget.show_intro_messageFrJ   c                 C   s(   |    t||| jd}| || dS )a  
        Show text 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_pathr   N)r   r   r   render_sphinx_doc)rO   r   r  r  contextr7   r7   r8   show_rich_text3  s
    zHelpWidget.show_rich_textc                 C   s   |    | j|dd dS )z
        Show text in plain mode.

        Parameters
        ----------
        text: str
            Plain text to display.
        Fr  N)r   r   )rO   r   r7   r7   r8   show_plain_textF  s    	zHelpWidget.show_plain_textc                 C   sZ   t d}tj|d}t|d}| }W d   n1 s>0    Y  | j|dd dS )zShow the Spyder tutorial.zspyder.plugins.help.utilsztutorial.rstrNT)r  )r   r  pathr   openreadr  )rO   Ztutorial_pathr  Zfhr   r7   r7   r8   show_tutorialR  s
    &zHelpWidget.show_tutorialc                 C   sB   t | }|dkr|   n |dr2t| n| j| dS )z
        Handle how url links should be opened.

        Parameters
        ----------
        url: QUrl
            QUrl object containing the link to open.
        zspy://tutorialZhttpN)r   ZtoStringr  
startswithr#   r   r   )rO   r   r7   r7   r8   r   ]  s    	


zHelpWidget.handle_link_clicksc                 C   s:   |r6|   r| jddd n| jdur6| j| jdd dS )z
        Force a refresh/rerender of the help viewer content.

        Parameters
        ----------
        valid: bool, optional
            Default is True.
        editing: bool, optional
            Default is True.
        NT)r   )rS   set_object_textr   set_editor_doc)rO   re   rh   r7   r7   r8   r   n  s
    
zHelpWidget.force_refreshc                 C   s   |  dr|sdS |   d}|du r8t| j }d}| j||d}|rR|sRdS |rb| j| |rp| j  | j	
 }|| j|< dS )a  
        Set object's name in Help's combobox.

        Parameters
        ----------
        text: str
            Object name.
        force_refresh: bool, optional
            Force a refresh with the rendering.
        ignore_unknown: bool, optional
            Ignore not found object names.

        See Also
        --------
        :py:meth:spyder.widgets.mixins.GetHelpMixin.show_object_info
        r   NTF)ignore_unknown)rX   r   r   rB   rT   	show_helpZadd_textsig_item_foundrf   r@   r   r   )rO   r   r   r  Zadd_to_combofoundindexr7   r7   r8   r    s     

zHelpWidget.set_object_textc                 C   sp   |  dr|sdS |   || _| j|d  |  drF| | n| j|dd | j }|d | j	|< dS )a  
        Set content for help data sent from the editor.

        Parameters
        ----------
        help_data: dict
            Dictionary with editor introspection information.
        force_refresh: bool, optional
            Force a refresh with the rendering.

        Examples
        --------
        >>> help_data = {
            'obj_text': str,
            'name': str,
            'argspec': str,
            'note': str,
            'docstring': str,
            'path': str,
        }
        r   Nobj_textr   Fr  r   )
rX   r   r   rC   ZsetTextr  r   r@   r   r   )rO   	help_datar   r  r7   r7   r8   r    s    

zHelpWidget.set_editor_docc                 C   s
   || _ dS )z
        Bind to shell.

        Parameters
        ----------
        shell: object
            internal shell or ipython console shell
        N)r_   )rO   r_   r7   r7   r8   	set_shell  s    	zHelpWidget.set_shellc                 C   s   | j du r| j| _ | j S )z@
        Return shell which is currently bound to Help.
        N)r_   rY   rc   r7   r7   r8   r[     s    
zHelpWidget.get_shellc                 C   sR   t |tr$|dd}tj|}nd}| jj||| d|| j	d | 
  dS )a;  
        Transform help_data dictionary to HTML and show it.

        Parameters
        ----------
        help_data: str or dict
            Dictionary with editor introspection information.
        context: dict
            Sphinx context.
        css_path: str
            Path to CSS file for styling.
        r  rJ   Zmathr   N)r   r   popr  r  dirnamer   ZrenderrX   r   r  )rO   r   r  r   r  Zdnamer7   r7   r8   r    s    
zHelpWidget.render_sphinx_docc                 C   s   |   }|du rdS t|}||sT| drH| jj|ddrH| j}nd}d}d}|durp||}||}d}| dr| j|| jd |duS | j	r|}|du r|}|du rdS n.|}|du r|}|du rt
d}|rdS nd}| j||d	 dS )
z
        Show help for an object's name.

        Parameters
        ----------
        obj_text: str
            Object's name.
        ignore_unknown: bool, optional
            Ignore unknown object's name.
        NrQ   TrR   Fr   r   zNo source code available.r  )r[   r   rZ   rX   rY   Zget_doc
get_sourcer  r   r   r   r   )rO   r  r  r_   docZsource_textr   Zhlp_textr7   r7   r8   r    sJ    




zHelpWidget.show_helpc                 C   s   | j j||d dS )z
        Set rich text mode font.

        Parameters
        ----------
        fixed_font: QFont
            The current rich text font to use.
        r~   N)r   r   r   r7   r7   r8   set_rich_text_font4  s    
zHelpWidget.set_rich_text_fontc                 C   s"   |du r| j }| jj||d dS )z
        Set plain text mode font.

        Parameters
        ----------
        font: QFont
            The current plain text font to use.
        color_scheme: str
            The selected color scheme.
        N)r   )r   r   r   r   r7   r7   r8   set_plain_text_font@  s    zHelpWidget.set_plain_text_fontc                 C   s   || _ | j| dS )z
        Set plain text mode color scheme.

        Parameters
        ----------
        color_scheme: str
            The selected color scheme.
        N)r   r   r   r   r7   r7   r8   set_plain_text_color_schemeP  s    	z&HelpWidget.set_plain_text_color_schemec                 C   s   | j | dS )z
        Set list of strings on object combo box.

        Parameters
        ----------
        history: list
            List of strings of objects.
        N)rB   r   )rO   historyr7   r7   r8   set_history\  s    	zHelpWidget.set_historyc                 C   s2   g }t | j D ]}|t| j| q|S )z=
        Return list of strings on object combo box.
        )rangerB   countappendr   ZitemText)rO   r)  r  r7   r7   r8   get_historyg  s    zHelpWidget.get_historyc                 C   s   || _ | j| _dS )z
        Set the internal console shell.

        Parameters
        ----------
        console: :py:class:spyder.plugins.console.plugin.Console
            Console plugin.
        N)r   Z
get_widgetr_   rY   )rO   Zconsoler7   r7   r8   set_internal_consoleq  s    	zHelpWidget.set_internal_console)NNN)FrJ   )TT)FF)F)F)N);r+   r,   r-   ZENABLE_SPINNERr   r  r   r   rK   r   rn   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rS   r   r   r   r   r   propertyrq   r   r   r   r   r  r   r  r  r  r   rj   r   r  r  r!  r[   r   r  r  r&  r'  r(  r*  r.  r/  r   r7   r7   r{   r8   r     sv   Gz






-9



'
%	
:

r   )Jri   r  rU   r\   r	  Zqtpy.QtCorer   r   r   r   r   Z
qtpy.QtGuir   Zqtpy.QtWebEngineWidgetsr   r	   Zqtpy.QtWidgetsr
   r   r   r   r   r   r   r   r   Zspyder.api.config.decoratorsr   Zspyder.api.translationsr   Zspyder.api.widgets.main_widgetr   Zspyder.api.widgets.mixinsr   Zspyder.config.baser   Z#spyder.plugins.help.utils.sphinxifyr   r   r   r   r   Z&spyder.plugins.help.utils.sphinxthreadr   Zspyder.py3compatr   r   Zspyder.utilsr    Zspyder.utils.image_path_managerr!   Zspyder.utils.paletter"   Zspyder.utils.qthelpersr#   Zspyder.widgets.browserr$   Zspyder.widgets.comboboxesr%   Zspyder.widgets.findreplacer&   Zspyder.widgets.simplecodeeditorr'   r   ZCOLOR_BACKGROUND_1ro   r(   r9   r<   r>   rI   rk   r   r   r7   r7   r7   r8   <module>   sD   ,
A7E