B
    nôb\Ç  ã               @   sf   d 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 ddlmZ G dd	„ d	ee
ƒZdS )
zOnline Help Pluginé    N)ÚSignal)Ú_Úget_conf_path)ÚSpyderPluginMixin)Úto_text_string)ÚPydocBrowserc               @   sz   e Zd ZdZeeeƒZd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d„Zdd„ Zdd„ Zdd„ ZdS )Ú
OnlineHelpz
    Online Help Plugin
    Z
onlinehelpc             C   sj   || _ t | |¡ t | |¡ |  ¡  |  | j¡ | j |  	d¡¡ | j
 |  	d¡¡ | j
 |  ¡ ¡ d S )NÚzoom_factorZmax_history_entries)Úmainr   Ú__init__r   Zinitialize_pluginZregister_widget_shortcutsZfind_widgetÚwebviewZset_zoom_factorZ
get_optionÚ	url_comboZsetMaxCountZaddItemsÚload_history)ÚselfÚparent© r   ú8lib/python3.7/site-packages/spyder/plugins/onlinehelp.pyr      s    zOnlineHelp.__init__Nc             C   s0   t  | j¡r(dd„ t| jdƒ ¡ D ƒ}ng }|S )z4Load history from a text file in user home directoryc             S   s   g | ]}|  d d¡‘qS )Ú
Ú )Úreplace)Ú.0Úliner   r   r   ú
<listcomp>0   s   z+OnlineHelp.load_history.<locals>.<listcomp>Úr)ÚospÚisfileÚLOG_PATHÚopenÚ	readlines)r   ÚobjÚhistoryr   r   r   r   -   s
    zOnlineHelp.load_historyc                s4   t ˆ jdƒ d ‡ fdd„tˆ j ¡ ƒD ƒ¡¡ dS )z2Save history to a text file in user home directoryÚwr   c                s   g | ]}t ˆ j |¡ƒ‘qS r   )r   r   ZitemText)r   Úindex)r   r   r   r   9   s   z+OnlineHelp.save_history.<locals>.<listcomp>N)r   r   ÚwriteÚjoinÚranger   Úcount)r   r   )r   r   Úsave_history6   s    
zOnlineHelp.save_historyc             C   s$   t  | |¡ |r |  ¡ s |  ¡  dS )z!DockWidget visibility has changedN)r   Úvisibility_changedZis_server_runningZ
initialize)r   Úenabler   r   r   r(   =   s    zOnlineHelp.visibility_changedc             C   s   t dƒS )zReturn widget titlezOnline help)r   )r   r   r   r   Úget_plugin_titleD   s    zOnlineHelp.get_plugin_titlec             C   s   | j  ¡  ¡  | j S )zq
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        )r   ZlineEditZ	selectAll)r   r   r   r   Úget_focus_widgetH   s    zOnlineHelp.get_focus_widgetFc             C   s   |   ¡  |  d| j ¡ ¡ dS )z3Perform actions before parent main window is closedr	   T)r'   Z
set_optionr   Zget_zoom_factor)r   Z
cancelabler   r   r   Úclosing_pluginP   s    zOnlineHelp.closing_pluginc             C   s   dS )zRefresh widgetNr   )r   r   r   r   Úrefresh_pluginV   s    zOnlineHelp.refresh_pluginc             C   s   g S )z*Return a list of actions related to pluginr   )r   r   r   r   Úget_plugin_actionsZ   s    zOnlineHelp.get_plugin_actionsc             C   s   | j  | ¡ dS )z'Register plugin in Spyder's main windowN)r
   Zadd_dockwidget)r   r   r   r   Úregister_plugin^   s    zOnlineHelp.register_plugin)N)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚstrÚobjectZsig_option_changedZCONF_SECTIONr   r   r   r   r'   r(   r*   r+   r,   r-   r.   r/   r   r   r   r   r      s   

	
r   )r3   Úos.pathÚpathr   Zqtpy.QtCorer   Zspyder.config.baser   r   Zspyder.pluginsr   Zspyder.py3compatr   Zspyder.widgets.pydocguir   r   r   r   r   r   Ú<module>   s   