
,]c           @   s  d  Z  d d l Z d d l j Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 m Z 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 m Z m Z m Z d d l m Z m Z d d l m Z d d l  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+ m, Z, d d l- m. Z/ d d l- m0 Z0 d d l1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 d d l7 m8 Z8 m9 Z9 m: Z: m; Z; d d l< m= Z= d d l> m? Z? d d l@ mA ZA d d lB mC ZC e jD d e! d  d d d e? f d     YZE d e) f d     YZF d e f d     YZG d e f d      YZH d! e
 f d"     YZI d# e' f d$     YZJ d S(%   s   Help PluginiN(   t   PYQT5(   t   QThreadt   QUrlt   Signalt   Slot(   t   QActionGroupt	   QComboBoxt	   QGroupBoxt   QHBoxLayoutt   QLabelt	   QLineEditt   QMenut   QMessageBoxt   QSizePolicyt   QToolButtont   QVBoxLayoutt   QWidget(   t   QWebEnginePaget	   WEBENGINE(   t   dependencies(   t   _t   get_conf_patht   get_module_source_path(   t   DEFAULT_SMALL_DELTA(   t   SpyderPluginWidget(   t   PluginConfigPage(   t   get_meth_class_instt   to_text_string(   t   icon_manager(   t   programs(   t   CSS_PATHt   generate_contextt	   sphinxifyt   usaget   warning(   t   add_actionst   create_actiont   create_toolbuttont   create_plugin_layout(   t   FrameWebView(   t   EditableComboBox(   t   FindReplace(   t
   codeeditort   sphinxsD   Show help for objects in the Editor and Consoles in a dedicated panet   required_versions   >=0.6.6t   ObjectComboBoxc           B   sG   e  Z d  Z e e e  Z d   Z d d  Z d   Z	 e
 d  Z RS(   s)   
    QComboBox handling object names
    c         C   sJ   t  j |  |  | |  _ |  j t j t j  i d t 6d t 6|  _	 d  S(   Nt    (
   R(   t   __init__t   helpt   setSizePolicyR   t	   Expandingt   Fixedt   Truet   Falset   tips(   t   selft   parent(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR/   8   s    	c         C   s2  |  j  j   s t S| d k r. |  j   } n  t j d t |  d  sM t St	 |  } t } |  j  j
 d  r |  j  j } | d k	 r | j | d t } q n  | s.|  j  j   } | d k	 r.y | j |  } Wq+t j k
 r'|  j  j   } y | j |  } Wq(t j k
 r#q(Xq+Xq.n  | S(   s   Return True if string is valids   ^[a-zA-Z0-9_\.]*$i    t   automatic_importt   force_importN(   R0   t   source_is_consoleR4   t   Nonet   currentTextt   ret   searcht   strR5   R   t
   get_optiont   internal_shellt
   is_definedt	   get_shellt   sockett   error(   R7   t   qstrt   objtxtt   shell_is_definedt   shell(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   is_valid>   s0    c         C   s   |  j  |  j    d  S(   N(   t   validateR=   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   validate_current_textZ   s    c         C   s   |  j  |  } |  j   r | d k	 r | r^ | r^ |  j |  j |  |  j j t t  q | r |  j   |  j	   j
 t  q |  j j t t  n  d S(   s)   Reimplemented to avoid formatting actionsN(   RK   t   hasFocusR<   t   show_tipR6   t   validt   emitR5   t   selectedt   lineEditt   cursorWordForward(   R7   RG   t   editingRP   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyRL   ]   s    
N(   t   __name__t
   __module__t   __doc__R   t   boolRP   R/   R<   RK   RM   R4   RL   (    (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR-   1   s   		t   HelpConfigPagec           B   s   e  Z d    Z RS(   c         C   sL  t  t d   } t t d   } | j t  |  j t d  d  } t j d  } t j d d  } | j | py |  | r | r t d  } | j	 |  n  |  j t d	  d
  } t
   } | j |  | j |  | j |  | j |  t  t d   }	 |  j t d  d  }
 t j d d  } |
 j |  | st j d  } t d  } | d t d  | 7} |
 j	 |  n  t
   } | j |
  |	 j |  t  t d   } |  j t d  d  } t
   } | j |  | j |  t
   } | j |  | j |	  | j |  | j d  |  j |  d  S(   Ns   Automatic connectionss   This pane can automatically show an object's help information after a left parenthesis is written next to it. Below you can decide to which plugin you want to connect it to turn on this feature.t   Editors   connect/editort   ropet   jedis   >=0.8.1s[   This feature requires the Rope or Jedi libraries.
It seems you don't have either installed.s   IPython Consoles   connect/ipython_consoles   Additional featuress   Render mathematical equationst   mathR+   s   >=1.1s-   This feature requires Sphinx 1.1 or superior.s   
s!   Sphinx %s is currently installed.s   Source codes
   Wrap linest   wrapi   (   R   R   R	   t   setWordWrapR4   t   create_checkboxR   t   is_module_installedt
   setEnabledt
   setToolTipR   t	   addWidgett	   setLayoutt   get_module_versiont
   addStretch(   R7   t   connections_groupt   connections_labelt
   editor_boxt   rope_installedt   jedi_installedt
   editor_tipt   ipython_boxt   connections_layoutt   features_groupt   math_boxt
   req_sphinxt
   sphinx_vert
   sphinx_tipt   features_layoutt   sourcecode_groupt   wrap_mode_boxt   sourcecode_layoutt   vlayout(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt
   setup_pageq   sR    						(   RV   RW   R{   (    (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyRZ   p   s   t   RichTextc           B   s5   e  Z d  Z d   Z d d  Z d   Z d   Z RS(   s)   
    WebView widget with find dialog
    c         C   s   t  j |  |  t |   |  _ t |   |  _ |  j j |  j j  |  j j   t	   } | j
 d d d d  | j |  j  | j |  j  |  j |  d  S(   Ni    (   R   R/   R'   t   webviewR)   t   find_widgett
   set_editort
   web_widgett   hideR   t   setContentsMarginsRe   Rf   (   R7   R8   t   layout(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR/      s    	c         C   s   |  j  j | d | d S(   s   Set fontt
   fixed_fontN(   R}   t   set_font(   R7   t   fontR   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR      s    c         C   s   |  j  j | |  d S(   s   Set html textN(   R}   t   setHtml(   R7   t	   html_textt   base_url(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   set_html   s    c         C   s   |  j  d |  j j    d  S(   NR.   (   R   R}   t   url(   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   clear   s    N(   RV   RW   RX   R/   R<   R   R   R   (    (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR|      s
   		t	   PlainTextc           B   sG   e  Z d  Z e   Z d   Z d d  Z d   Z d   Z	 d   Z
 RS(   s2   
    Read-only editor widget with find dialog
    c      	      s   t  j   |  d    _ t j      _   j j d t d d d t d t    j j j	   f d      j j
 t  t      _   j j   j    j j   t   } | j d d d d  | j   j  | j   j    j |  d  S(   Nt   linenumberst   languaget   pyt   scrollflagareat	   edge_linec              s     j  j   S(   N(   t   focus_changedRQ   (    (   R7   (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   <lambda>   R.   i    (   R   R/   R<   t   editorR*   t
   CodeEditort   setup_editorR5   R   t   connectt   setReadOnlyR4   R)   R~   R   R   R   R   Re   Rf   (   R7   R8   R   (    (   R7   s2   lib/python2.7/site-packages/spyder/plugins/help.pyR/      s    		c         C   s   |  j  j | d | d S(   s   Set fontt   color_schemeN(   R   R   (   R7   R   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR      s    c         C   s   |  j  j |  d S(   s   Set color schemeN(   R   t   set_color_scheme(   R7   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR      s    c         C   sm   |  j  j |  |  j  j |  | r9 |  j  j d  n |  j  j d   |  j  j |  |  j  j d  d  S(   NR   t   sof(   R   t   set_highlight_current_linet   set_occurrence_highlightingt   set_languageR<   t   set_textt   set_cursor_position(   R7   t   textt   is_code(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR      s    c         C   s   |  j  j   d  S(   N(   R   R   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR      s    N(   RV   RW   RX   R   R   R/   R<   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR      s   				
t   SphinxThreadc           B   sM   e  Z d  Z e e  Z e e  Z d d  Z d e	 d d  Z
 d   Z RS(   s&  
    A worker thread for handling rich text rendering.

    Parameters
    ----------
    doc : str or dict
        A string containing a raw rst text or a dict containing
        the doc string components to be rendered.
        See spyder_kernels.utils.dochelpers.getdoc for description.
    context : dict
        A dict containing the substitution variables for the
        layout template
    html_text_no_doc : unicode
        Text to be rendered if doc string cannot be extracted.
    math_option : bool
        Use LaTeX math rendering.

    R.   c         C   s;   t  t |   j   d  |  _ d  |  _ | |  _ t |  _ d  S(   N(	   t   superR   R/   R<   t   doct   contextt   html_text_no_docR5   t   math_option(   R7   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR/     s
    			c         C   sA   |  j    r= | |  _ | |  _ | |  _ | |  _ |  j   n  d S(   s,   Start thread to render a given documentationN(   t   waitR   R   R   t   img_patht   start(   R7   R   R   R   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   render  s    				c         C   s  |  j  } |  j } | d  k	 rt |  t k r)d | j   k r)y t d | d d | d d | d d |  j d |  j  } t	 | d |  } | d d k r t
 | d | d | d g  r t d  } | d	 7} n t d
  } | d | 7} n  Wq~t k
 r%} |  j j t |   d  SXq|  j d  k	 ry t	 | |  j  } Wq~t k
 rz} |  j j t |   d  SXqn  |  j j |  d  S(   Nt	   docstringt   namet   argspect   noteR^   R   R.   s"   No further documentation availables   <div class="hr"></div>s   No documentation availables   <div id="doc-warning">%s</div>(   R   R   R<   t   typet   dictt   keysR   R   R   R    t   anyR   t	   Exceptiont	   error_msgRQ   R   R   t
   html_ready(   R7   R   R   R   t   msgRF   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   run(  s6    		$

	!N(   RV   RW   RX   R   R@   R   R   R/   R<   R5   R   R   (    (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR      s   t   Helpc           B   s  e  Z d  Z d Z e Z e e  Z e Z	 e
   Z d7 d  Z d   Z d   Z d   Z d   Z d   Z d   Z e d	  Z d
   Z d   Z d   Z d   Z d   Z d   Z d7 d  Z d   Z d   Z e d    Z  d   Z! d7 d  Z" d   Z# e$ e%  d    Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, d   Z- d   Z. e d  d!  Z/ d"   Z0 e$   d#    Z1 d$   Z2 e$   e$ e%  e$ e% e%  e3 e3 d%     Z4 e e d&  Z5 e d'  Z6 e d(  Z7 d7 d)  Z8 d*   Z9 e$ e%  d+    Z: e$ e%  d,    Z; e$ e%  d-    Z< e$ e%  d.    Z= e$   d/    Z> d0   Z? d1   Z@ d2   ZA d7 d3  ZB d4   ZC d5   ZD e d6  ZE RS(8   s"   
    Docstrings viewer widget
    R0   c         C   s  t  r t j |  | d | n t j |  |  d  |  _ d  |  _ |  j   t d  |  _ d  |  _	 d  |  _
 t |   |  _ t |   |  _ |  j   } |  j |  j   |  |  j j j |  j d   t |  t d  d |  j |  _ |  j j |  j d   |  j j j j   t |  j j j |  j f  |  j |  j d   d  |  _ t |  _ d  d  g |  _ d  |  _  t!   } | j" d d d d  t d  } t# j$ d	 k rt% d
 |  } n t% |  } | j& |  t' |   |  _( |  j( j) t d  t d  g  |  j( j* j+ |  j,  t- j. d  r[t- j. d d  r[|  j( j/   | j/   n  | j& |  j(  | j0 d  | j& t% t d    t1 |   |  _2 | j& |  j2  t3 |   |  _4 |  j4 j5 t6  | j& |  j4  |  j2 j7 |  j d   |  j2 j) |  j8    |  j2 j9 d d  |  j2 j: j+ |  j;  t6 |  _< |  j d t6  |  _= t |  t d  d |  j> |  _? t |  t d  d |  j@ |  _A t |  t d  d |  jB |  _C tD |   } | jE t6  | jF |  j?  | jF |  jC  t |  t d  d |  jG |  _H |  j d  } |  jH j |  tI |  d |  jJ |  _K | j& |  jK  |  jL   tI |  d t d  d tM jN d  } | jO tP jQ  tR |   }	 t |	 |  jC |  j? |  jA d  |  jH g  | jS |	  | j& |  |  j= r|  jT   n
 |  jU   |  j? j |  j=  |  jC j |  j=  |  j,   tV |  }
 |
 j& |  j  |
 j& |  j  |  jW |
  tX d tY |  j   |  _Z |  jZ j[ j+ |  j\  |  jZ j] j+ |  j^  |  j j_ } t` s| ja   jb tc jd  n  | je j+ |  jf  t6 |  _g d  S(    Nt   mains   No documentation availableR_   s
   Wrap linest   toggledt	   rich_texti    t   Sourcet   darwins     t   ConsoleR[   R\   R]   s   >=0.8.1i
   t   Objectt   max_history_entriesR.   t	   rich_modes
   Plain Texts   Show Sources	   Rich Texts   Automatic importR9   t	   triggeredR   t   Optionst   icont   tooloptionsR   (h   R    R   R/   R<   RB   t   consolet   initialize_pluginR   t   no_doc_stringt   _last_console_cbt   _last_editor_cbR   t
   plain_textR|   R   t   get_color_schemet   set_plain_text_fontt   get_plugin_fontR   t   toggle_wrap_modeRA   R$   t   wrap_actiont
   setCheckedt   readonly_menut   addSeparatorR#   t   set_rich_text_fontRJ   R5   t   lockedt   _last_textst   _last_editor_docR   R   t   syst   platformR	   Re   R   t   source_combot   addItemst   currentIndexChangedR   t   source_changedR   Rb   R   t
   addSpacingR-   t   comboR
   t   object_editR   R4   t   setMaxCountt   load_historyt   setItemTextRP   t   force_refreshR   t	   rich_helpt   toggle_plain_textt   plain_text_actiont   toggle_show_sourcet   show_source_actiont   toggle_rich_textt   rich_text_actionR   t   setExclusivet	   addActiont   toggle_auto_importt   auto_import_actionR%   t   toggle_lockedt   locked_buttont   _update_lock_icont   imaR   t   setPopupModeR   t   InstantPopupR   t   setMenut   switch_to_rich_textt   switch_to_plain_textR&   Rf   R   R"   t   _sphinx_threadR   t   _on_sphinx_thread_html_readyR   t   _on_sphinx_thread_error_msgR}   R   t   paget   setLinkDelegationPolicyR   t   DelegateAllLinkst   linkClickedt   handle_link_clickst   _starting_up(   R7   R8   R   t   layout_editt   txtt   source_labelt   help_actionst   auto_import_statet   options_buttont   menuR   t   view(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR/   S  s    		
						"		
		


c         C   s   |  j  j |  j  j |   d S(   s3   Action to be performed on first plugin registrationN(   R   t   tabify_pluginst   variableexplorer(   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   on_first_registration  s    c         C   s
   t  d  S(   s   Return widget titleR   (   R   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   get_plugin_title  s    c         C   s   t  j d  S(   s   Return widget iconR0   (   R   R   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   get_plugin_icon  s    c         C   s   |  j  j   j   |  j  S(   sq   
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        (   R   RS   t	   selectAll(   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   get_focus_widget  s    c         C   s   g  S(   s*   Return a list of actions related to plugin(    (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   get_plugin_actions  s    c         C   s^   |  j  j |  j j  |  j j |   |  j j j |   |  j j j |  _ |  j j |  _ d S(   s'   Register plugin in Spyder's main windowN(	   R   R   R   t   plugin_focus_changedt   add_dockwidgetR   t   set_helpRJ   RB   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   register_plugin  s
    c         C   s   t  S(   s3   Perform actions before parent main window is closed(   R4   (   R7   t
   cancelable(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   closing_plugin  s    c         C   s-   |  j  r) t |  _  |  j   |  j   n  d S(   s   Refresh widgetN(   R  R5   R   t   show_intro_message(   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   refresh_plugin  s    		
c         C   sN   |  j    } |  j   } |  j d t  } |  j | d | |  j |  d S(   s   Update font from PreferencesR   R   N(   R   R   R4   R   R   (   R7   R   R   t	   rich_font(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   update_font  s
    c   	      C   s   d } |  j    } d } d } |  j |  } |  j j |  d } |  j |  } | | k rn |  j |  n  | | k r |  j |  n  | | k r |  j |  n  |  j j j	 d | g  |  j j
 j	 d | g  d S(   s*   Apply configuration file's plugin settingst   color_scheme_namet   connect_to_oiR_   R^   t   optionsN(   R   RA   R   R   t   set_plain_text_color_schemeR   t   toggle_math_modeR   R   t   apply_plugin_settingst
   ipyconsole(	   R7   R!  t   color_scheme_nt   color_scheme_ot	   connect_nt   wrap_nt   wrap_ot   math_nt   math_o(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR$    s     c         C   s   |  j  j   d k S(   s    Return True if source is Consolei    (   R   t   currentIndex(   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR;   .  s    c         C   s   |  j  j d  d  S(   Ni   (   R   t   setCurrentIndex(   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   switch_to_editor_source2  s    c         C   s   |  j  j d  d  S(   Ni    (   R   R.  (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   switch_to_console_source5  s    c         C   s   |  j    rI |  j j   |  j j   |  j j t  |  j j t  n: |  j j   |  j j   |  j j	 t  |  j j	 t  |  j
   d  S(   N(   R;   R   t   showR   R   R   Rc   R4   R   t   setDisabledt   restore_text(   R7   t   index(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   8  s    c         C   s%   |  j    r | |  _ n	 | |  _ d  S(   N(   R;   R   R   (   R7   t   callback(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt	   save_textG  s    c         C   s   |  j    r |  j } n	 |  j } | d  k rY |  j   rI |  j j   q |  j j   nJ | d } | d } | |   t |  |  j k r |  j	   n
 |  j
   d  S(   Ni    i   (   R;   R   R   R<   t   is_plain_text_modeR   R   R   R   R   R   (   R7   t   cbt   funct   args(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR3  M  s    	


c         C   s'   |  j  j   r |  j  j S|  j j Sd  S(   N(   R   t	   isVisibleR~   R   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR~   a  s    
c         C   s    |  j  j | d |  j   d S(   s   Set rich text mode fontR   N(   R   R   R   (   R7   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   h  s    c         C   s   |  j  j | d | d S(   s   Set plain text mode fontR   N(   R   R   (   R7   R   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   l  s    c         C   s   |  j  j |  d S(   s    Set plain text mode color schemeN(   R   R   (   R7   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR"  p  s    c         C   s'   |  j  j j |  |  j d |  d S(   s   Toggle wrap modeR_   N(   R   R   R   t
   set_option(   R7   t   checked(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   t  s    c         C   s   |  j  d |  d S(   s   Toggle math modeR^   N(   R<  (   R7   R=  (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR#  z  s    c         C   s   |  j  j   S(   s(   Return True if plain text mode is active(   R   R;  (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR7  ~  s    c         C   s   |  j  j   S(   s'   Return True if rich text mode is active(   R   R;  (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   is_rich_text_mode  s    c         C   s7   t  |  _ |  j j   |  j j   |  j j t  d S(   s   Switch to plain text modeN(	   R5   R   R   R1  R   R   R   R   R4   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR     s    	c         C   sG   t  |  _ |  j j   |  j j   |  j j t   |  j j t	  d S(   s   Switch to rich text modeN(
   R4   R   R   R   R   R1  R   R   R   R5   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR     s
    	c         C   s  t  |  t k r | d } | rZ d j d t |  d | d d t |  d g  } n d } | d r d j d | | d d g  } n d } | d r d j d	 | d d
 g  } n d } d j | | | | d g  } n | } |  j j | |  |  j |  j j | | g  d S(   s   Set plain text docsR   R.   t   =s   
s   

R   s   Definition: R   s   Type: s   

----

R   N(   R   R   t   joint   lenR   R   R6  (   R7   R   R   R   t	   rst_titlet
   definitionR   t	   full_text(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   set_plain_text  s$    


c         C   s3   |  j  j | |  |  j |  j  j | | g  d S(   s   Set rich textN(   R   R   R6  (   R7   R   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   set_rich_text_html  s    c         C   s   t  d  } t  d  } t j d k r0 d } n d } |  j   r t  d  } t  d  } t  d  } | d	 | d
 d d | d f } |  j t | | | |  t j t   n@ d t  d  } | | d | f } | | 7} |  j	 | d t
 d  S(   Ns   Here you can get help of any object by pressing %s in front of it, either on the Editor or the Console.%sHelp can also be shown automatically after writing a left parenthesis next to an object. You can activate this behavior in %s.s   Preferences > HelpR   s   Cmd+Is   Ctrl+It   Usages   New to Spyder? Read ourt   tutorials   <b>s   </b>s   <br><br>s   <i>s   </i>s   

%ssM   Please consider installing Sphinx to get documentation rendered in rich text.s   

R   (   R   R   R   R>  RF  R!   R   t   fromLocalFileR   RE  R5   (   R7   t   intro_messaget   prefst   shortcutt   titlet   tutorial_messageRH  t   install_sphinx(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR    s$    		
R.   c         C   s=   |  j    |  j   t d | d |  } |  j | |  d S(   s   Show text in rich modet   collapseR   N(   t   switch_to_pluginR   R   t   render_sphinx_doc(   R7   R   RP  R   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   show_rich_text  s    

c         C   s+   |  j    |  j   |  j | d t d S(   s   Show text in plain modeR   N(   RQ  R   RE  R5   (   R7   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   show_plain_text  s    

c         C   sQ   |  j    t d  } t j | d  } t |  j   } |  j | d t d S(   sA   Show the Spyder tutorial in the Help plugin, opening it if neededs   spyder.utils.helps   tutorial.rstRP  N(   RQ  R   t   ospR@  t   opent   readRS  R4   (   R7   t   tutorial_pathRH  R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   show_tutorial  s
    
c         C   sg   t  | j    } | d k r+ |  j   n8 | j d  rJ t j |  n |  j j j t	 |   d  S(   Ns   spy://tutorialt   http(
   R   t   toStringRY  t
   startswithR   t
   start_fileR   R}   t   loadR   (   R7   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR    s    c         C   sW   | rS |  j    r( |  j d  d t qS |  j d  k	 rS |  j |  j d t qS n  d  S(   NR   (   R;   t   set_object_textR<   R4   R   t   set_editor_doc(   R7   RP   RU   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR     s
    c         C   s   |  j  r | r d S|  j   t } | d k rN t |  j j    } t } n  |  j | d | } | rt | rt d S| r |  j j	 |  n  | r |  j
   n  |  j d k	 r |  j j t  n  |  j | d | |  j d k	 r |  j j t  n  d S(   s   Set object analyzed by HelpNt   ignore_unknownt   force(   R   R0  R4   R<   R   R   R=   R5   t	   show_helpt   add_textt   save_historyt
   dockwidgett   blockSignalst   _Help__eventually_raise_help(   R7   R   R   Ra  t   add_to_combot   found(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR_    s&    
	c         C   s   |  j  r | r d S|  j   | |  _ |  j j | d  |  j rT |  j |  n |  j | d t |  j	 d k	 r |  j	 j t  n  |  j | d d | |  j	 d k	 r |  j	 j t  n  d S(   s   
        Use the help plugin to show docstring dictionary computed
        with introspection plugin from the Editor plugin
        Nt   obj_textR   R   Rb  (   R   R/  R   R   t   setTextR   RR  RE  R5   Rf  R<   Rg  R4   Rh  (   R7   R   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR`    s    
		c         C   s   |  j  j   } t |  j d  r |  j r | s? |  j j   r |  j r | sb | |  j | k r |  j j |  j  } |  j	 j | k r |  j j
 d  k	 r |  j j
 j | k r |  j   q q n  | |  j | <d  S(   Nt   tabifiedDockWidgets(   R   R-  t   hasattrR   Rf  R;  t   ismaximizedR   Rm  R   R%  R<   RQ  (   R7   R   Rb  R4  t   dockwidgets(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   __eventually_raise_help1  s    
c         C   sV   t  j |  j  rL g  t |  j d  j   D] } | j d d  ^ q+ } n g  } | S(   s4   Load history from a text file in user home directoryt   rs   
R.   (   RU  t   isfilet   LOG_PATHRV  t	   readlinest   replace(   R7   t   objt   linet   history(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   ?  s
    7c         C   s   yf g  t  |  j j    D] } t |  j j |   ^ q } d j |  } t |  j d  j |  Wn t	 t
 t f k
 r n Xd S(   s2   Save history to a text file in user home directorys   
t   wN(   t   rangeR   t   countR   t   itemTextR@  RV  Rt  t   writet   UnicodeEncodeErrort   UnicodeDecodeErrort   EnvironmentError(   R7   R4  t   search_history(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyRe  H  s    7c         C   s;   | r& | |  _  |  j   |  j   n  |  j d |  d S(   s   Toggle plain text docstringR   N(   R   R   R   R<  (   R7   R=  (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   T  s
    	
c         C   s<   | r |  j    n  | |  _ |  j   |  j d |  d S(   s   Toggle show source codeR   N(   R   R   R   R<  (   R7   R=  (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   ]  s
    

c         C   s1   | r | |  _  |  j   n  |  j d |  d S(   s3   Toggle between sphinxified docstrings or plain onesR   N(   R   R   R<  (   R7   R=  (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   f  s    
c         C   s+   |  j  j   |  j d |  |  j   d S(   s   Toggle automatic import featureR9   N(   R   RM   R<  R   (   R7   R=  (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   n  s    c         C   s   |  j  |  _  |  j   d S(   sP   
        Toggle locked state
        locked = disable link with Console
        N(   R   R   (   R7   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   u  s    c         C   sl   |  j  r t j d  n t j d  } |  j j |  |  j  rL t d  n	 t d  } |  j j |  d S(   s   Update locked state icont   lockt	   lock_opent   Unlockt   LockN(   R   R   R   R   t   setIconR   Rd   (   R7   R   t   tip(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   ~  s    '!c         C   s   | |  _  d S(   s   Bind to shellN(   RJ   (   R7   RJ   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt	   set_shell  s    c         C   s   t  |  j d  s5 t  |  j d  r |  j j   r d |  _ |  j j d k	 r |  j j j   } | d k	 r | j d k	 r | |  _ q n  |  j d k r |  j |  _ q n  |  j S(   s{   
        Return shell which is currently bound to Help,
        or another running shell if it has been terminated
        t   get_doct
   is_runningN(	   Rn  RJ   R  R<   R   R%  t   get_current_shellwidgett   kernel_clientRB   (   R7   RJ   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyRD     s    	c         C   sb   |  j  j d k	 r6 |  j  j j   } t j |  } n d } |  j j | | |  j d  |  d S(   s3   Transform doc string dictionary to HTML and show itR.   R^   N(	   R   R   R<   t   get_current_filenameRU  t   dirnameR   R   RA   (   R7   R   R   t   fnamet   dname(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyRR    s    c         C   s*   |  j  j   |  j | t j t   d S(   s3   Set our sphinx documentation based on thread resultN(   R   R   RF  R   RI  R   (   R7   R   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR     s    c         C   sY   |  j  j   |  j j t  t j d  } t j |  t	 d  t	 d  | | f  d S(   s2    Display error message on Sphinx rich text failureR+   R   s   The following error occured 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   R4   R   Rg   R   t   criticalR   (   R7   R   Rt   (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR     s    			c         C   sx  |  j    } | d k r d St |  } | j |  s |  j d  rj |  j j | d t rj |  j } q d } d } d } n  | d k	 r | j |  } | j |  } n  t	 } |  j
 r |  j |  | d k	 S|  j r| } | d k ra| } | d k r|  j } | rt	 SqqanF | } | d k r[| } | d k rat d  } | rXt	 Sqan t } |  j | d | t S(   s	   Show helpNR9   R:   s   No source code available.R   (   RD   R<   R   RC   RA   RB   R4   R  t
   get_sourceR5   R   RR  R   R   R   RE  (   R7   Rk  Ra  RJ   R   t   source_textR   t   hlp_text(    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyRc    sH    		
		
N(F   RV   RW   RX   t   CONF_SECTIONRZ   t   CONFIGWIDGET_CLASSR   Rt  R   t   FONT_SIZE_DELTAR   R   R<   R/   R  R  R  R  R  R  R5   R  R  R  R$  R;   R/  R0  R   R6  R3  t   propertyR~   R   R   R"  R   RY   R   R#  R7  R>  R   R   RE  RF  R  RS  RT  RY  R  R4   R   R_  R`  Rh  R   Re  R   R   R   R   R   R   R  RD   RR  R   R   Rc  (    (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyR   G  sz   																														
											(K   RX   R>   t   os.patht   pathRU  RE   R   t   qtpyR    t   qtpy.QtCoreR   R   R   R   t   qtpy.QtWidgetsR   R   R   R   R	   R
   R   R   R   R   R   R   t   qtpy.QtWebEngineWidgetsR   R   t   spyderR   t   spyder.config.baseR   R   R   t   spyder.config.fontsR   t   spyder.pluginsR   t   spyder.plugins.configdialogR   t   spyder.py3compatR   R   t   spyder.utilsR   R   R   t   spyder.utils.help.sphinxifyR   R   R    R!   R"   t   spyder.utils.qthelpersR#   R$   R%   R&   t   spyder.widgets.browserR'   t   spyder.widgets.comboboxesR(   t   spyder.widgets.findreplaceR)   t   spyder.widgets.sourcecodeR*   t   addR-   RZ   R|   R   R   R   (    (    (    s2   lib/python2.7/site-packages/spyder/plugins/help.pyt   <module>   s<   "R("?=3I