ó
Æé)Mc           @   s¢  d  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 m Z m Z d d l Z d d l Z d d l j Z d d l Z e j Z d d l m Z m Z m Z 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% m& Z& y0 d d
 l' m( Z( m) Z) d e( e( f Z* d Z+ Wn e, k
 r[d Z) n Xd e! f d „  ƒ  YZ. d e& f d „  ƒ  YZ/ d e% f d „  ƒ  YZ0 d S(   s   Object Inspector Pluginiÿÿÿÿ(	   t   QHBoxLayoutt   QVBoxLayoutt   QLabelt   QSizePolicyt   QMenut   QToolButtont	   QGroupBoxt   QFontComboBoxt   QActionGroup(   t   SIGNALt   QUrlt   QTimerN(   t   get_conf_patht   get_icont   CONFt   get_color_scheme(   t   create_toolbuttont   add_actionst   create_action(   t   EditableComboBox(   t   ExtPythonShellWidget(   t   RichAndPlainTextt   PluginConfigPage(   t   CSS_PATHt	   sphinxifysû   <html>     <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />     <link rel="stylesheet" href="%s/default.css" type="text/css" />     <link rel="stylesheet" href="%s/pygments.css" type="text/css" />     </head>     <body>s   </body>     </html>t   ObjectComboBoxc           B   s,   e  Z d  Z d „  Z d d „ Z d „  Z RS(   s)   
    QComboBox handling object names
    c         C   s\   t  j |  | ƒ | |  _ |  j t j t j ƒ i |  j d ƒ t 6|  j d ƒ t	 6|  _
 d  S(   Nt    (   R   t   __init__t   object_inspectort   setSizePolicyR   t	   Expandingt   Fixedt   trt   Truet   Falset   tips(   t   selft   parent(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR   .   s    	c         C   s   | d k r |  j ƒ  } n  t j d t | ƒ d ƒ s: t S|  j j } t | ƒ } | d k	 rü |  j j	 ƒ  |  j j
 d ƒ rœ |  j j } | j | d t ƒSy | j | ƒ SWqü t j k
 rø |  j j	 ƒ  y | j | ƒ SWqù t j k
 rô qù Xqü Xn  d S(   s   Return True if string is valids   ^[a-zA-Z0-9_\.]*$i    t   automatic_importt   force_importN(   t   Nonet   currentTextt   ret   searcht   strR"   R   t   shellt   unicodet   _check_if_shell_is_runningt
   get_optiont   internal_shellt
   is_definedR!   t   sockett   error(   R$   t   qstrR-   t   objtxt(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   is_valid4   s&    c         C   s   |  j  |  j ƒ  ƒ d  S(   N(   t   validateR)   (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   validate_current_textL   s    N(   t   __name__t
   __module__t   __doc__R   R(   R7   R9   (    (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR   *   s   	t   ObjectInspectorConfigPagec           B   s   e  Z d  „  Z RS(   c   
      C   s8  t  |  j d ƒ ƒ } |  j |  j d ƒ d ƒ } |  j d d  d |  j d ƒ d t j ƒ } |  j d d d |  j d	 ƒ ƒ } t j d
 d ƒ } t	 | | ƒ } |  j
 |  j d ƒ | d ƒ } t ƒ  } | j | ƒ | j | ƒ | j | ƒ t ƒ  }	 |	 j | ƒ |	 j | ƒ |	 j | ƒ |	 j d ƒ |  j |	 ƒ d  S(   Ns   Source codes
   Wrap linest   wrapt   optiont   texts   Plain text font stylet   fontfilterst	   rich_texts   Rich text font stylet   color_schemest   namess   Syntax color scheme: t   color_scheme_namei   (   R   R    t   create_checkboxt   create_fontgroupR(   R   t   MonospacedFontsR   t   gett   zipt   create_comboboxR   t	   addWidgett	   setLayoutt
   addStretch(
   R$   t   sourcecode_groupt   wrap_mode_boxt   plain_text_font_groupt   rich_text_font_groupRD   t   choicest   cs_combot   sourcecode_layoutt   vlayout(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt
   setup_pageP   s*    		(   R:   R;   RW   (    (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR=   O   s   t   ObjectInspectorc           B   s  e  Z d  Z d Z e Z e 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 e e d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! e d „ Z" RS(   s"   
    Docstrings viewer widget
    t	   inspectors
   .inspectorc      	      sŽ  ˆ  j  ƒ  t j ˆ  | ƒ ˆ  j j j ˆ  j d ƒ ƒ d  ˆ  _ d  ˆ  _	 t
 ˆ  _ d  ˆ  _ t ƒ  } | j d d d d ƒ | j t ˆ  j d ƒ ƒ ƒ t ˆ  ƒ ˆ  _ | j ˆ  j ƒ ˆ  j j ˆ  j d ƒ ƒ ˆ  j j ˆ  j ƒ  ƒ ˆ  j ˆ  j t d ƒ ‡  f d †  ƒ t ˆ  _ t d  k	 o,ˆ  j d t ƒ ˆ  _ ˆ  j j ˆ  j ƒ ˆ  j j ˆ  j ƒ t  ˆ  ˆ  j d ƒ d	 ˆ  j! ƒ} | j" ˆ  j ƒ t  ˆ  ˆ  j d
 ƒ d	 ˆ  j# ƒ} t  ˆ  ˆ  j d ƒ d	 ˆ  j$ ƒ} | j" ˆ  j ƒ | j% t d  k	 ƒ t& ˆ  ƒ } | j' t ƒ | j( | ƒ | j( | ƒ | j( | ƒ t  ˆ  ˆ  j d ƒ d	 ˆ  j) ƒ} ˆ  j d ƒ } | j" | ƒ t* ˆ  d ˆ  j+ ƒˆ  _, | j ˆ  j, ƒ ˆ  j- ƒ  t* ˆ  d ˆ  j d ƒ d t. d ƒ d t ƒ}	 |	 j/ t0 j1 ƒ t2 ˆ  ƒ }
 t3 |
 | | | d  | g ƒ |	 j4 |
 ƒ | j |	 ƒ t5 ƒ  } | j d d d d ƒ | j6 | ƒ | j ˆ  j ƒ | j ˆ  j ƒ ˆ  j7 | ƒ t8 j9 d ˆ  j: ƒ d  S(   NRB   i    t   Objectt   max_history_entriess   valid(bool)c            s
   ˆ  j  ƒ  S(   N(   t   force_refresh(   t   valid(   R$   (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   <lambda>‡   s    t	   rich_modes
   Plain Textt   toggleds   Show Sources	   Rich Texts   Automatic importR&   t	   triggeredR@   t   Optionst   icons   tooloptions.pngt   text_beside_iconi@  (;   t   set_default_color_schemeR   R   RB   t   webviewt   set_fontt   get_plugin_fontR(   R-   t   external_consoleR"   t   lockedt
   _last_textR    t   setContentsMarginsRL   R   R    R   t   combot   setMaxCountR0   t   addItemst   load_historyt   connectR	   R!   t	   docstringR   t	   rich_helpt
   setVisiblet
   plain_textR   t   toggle_plain_textt
   setCheckedt   toggle_show_sourcet   toggle_rich_textt
   setEnabledR   t   setExclusivet	   addActiont   toggle_auto_importR   t   toggle_lockedt   locked_buttont   _update_lock_iconR   t   setPopupModeR   t   InstantPopupR   R   t   setMenuR   t	   addLayoutRM   R   t
   singleShott   refresh_plugin(   R$   R%   t   layout_editt   plain_text_actiont   show_sourcet   rich_text_actiont   help_actionst   auto_importt   auto_import_statet   options_buttont   menut   layout(    (   R$   s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR   q   sv    
							
		c         C   s   |  j  d ƒ S(   s   Return widget titles   Object inspector(   R    (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   get_plugin_titleÆ   s    c         C   s
   t  d ƒ S(   s   Return widget icons   inspector.png(   R   (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.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
        (   Rm   t   lineEditt	   selectAll(   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   get_focus_widgetÎ   s    c         C   s   g  S(   s*   Return a list of actions related to plugin(    (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   get_plugin_actionsÖ   s    c         C   sX   |  j  |  t d ƒ |  j j ƒ |  j j |  ƒ |  j j j |  ƒ |  j j j |  _ d S(   s'   Register plugin in Spyder's main windows   focus_changed()N(	   Rq   R	   t   maint   plugin_focus_changedt   add_dockwidgett   consolet   set_inspectorR-   R1   (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   register_pluginÚ   s
    c         C   s   t  S(   s3   Perform actions before parent main window is closed(   R!   (   R$   t
   cancelable(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   closing_pluginâ   s    c         C   s   |  j  d d t ƒd S(   s   Refresh widgetR\   N(   t   set_object_textR(   R"   (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR†   æ   s    c         C   s  d } t  |  j | ƒ ƒ } d } |  j ƒ  } d } |  j d ƒ } d } |  j | ƒ }	 |  j j |	 ƒ | | k r¤ | | k r… | n d }
 |  j j j | |
 ƒ n  | | k rÆ |  j	 j
 j | ƒ n" | | k rè |  j j j | ƒ n  | | k r
|  j j j |	 ƒ n  d S(   s*   Apply configuration file's plugin settingsRE   t   plugin_fontRB   R>   N(   R   R0   Rh   t   wrap_actionRw   R(   Ru   t   editorRg   RB   Rf   t   set_color_schemet   toggle_wrap_mode(   R$   t   optionst   color_scheme_nt   color_scheme_ot   font_nt   font_ot   rich_font_nt   rich_font_ot   wrap_nt   wrap_ot   scs(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   apply_plugin_settingsê   s$    c         C   s   | |  _  d  S(   N(   Ri   (   R$   Ri   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   set_external_console   s    c         C   s   |  j  d  d t ƒd  S(   NR\   (   RŸ   R(   R!   (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR\     s    c      	   C   sD  |  j  r | r d St } | d k rD t |  j j ƒ  ƒ } t } n  |  j | d | ƒ} | rj | rj d S| rƒ |  j j | ƒ n  |  j	 ƒ  t
 |  j d ƒ r7|  j r7|  j j ƒ  r7|  j r7| |  j k r7|  j j |  j ƒ } |  j j j | k r4t
 |  j d ƒ r4|  j j j | k r4|  j j ƒ  q4q7n  | |  _ d S(   s'   Set object analyzed by Object InspectorNt   ignore_unknownt   tabifiedDockWidgetst
   extconsole(   Rj   R!   R(   R.   Rm   R)   R"   t	   show_helpt   add_textt   save_historyt   hasattrR—   t
   dockwidgett	   isVisiblet   ismaximizedRk   R²   Rš   R³   t   raise_(   R$   R@   R\   R±   t   add_to_combot   foundt   dockwidgets(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyRŸ     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   (   t   ospt   isfilet   LOG_PATHt   filet	   readlinest   replace(   R$   t   objt   linet   history(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyRp   #  s
    7c         C   sZ   t  |  j d ƒ j d j g  t |  j j ƒ  ƒ D] } t |  j j | ƒ ƒ ^ q. ƒ ƒ d S(   s2   Save history to a text file in user home directoryt   ws   
N(	   RÃ   RÂ   t   writet   joint   rangeRm   t   countR.   t   itemText(   R$   t   index(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR¶   ,  s    c         C   sg   | rR | |  _  | |  _ |  j j ƒ  rE |  j j ƒ  |  j j ƒ  n  |  j ƒ  n  |  j d | ƒ d S(   s   Toggle plain text docstringR_   N(	   Rr   Rs   Ru   t   isHiddent   showRB   t   hideR\   t
   set_option(   R$   t   checked(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyRv   2  s    	
c         C   sh   | rS | |  _  | |  _ |  j j ƒ  rF |  j j ƒ  |  j j ƒ  n  |  j ƒ  n  |  j d | ƒ d S(   s   Toggle show source codeR_   N(	   Rr   Rs   Ru   RÐ   RÑ   RB   RÒ   R\   RÓ   (   R$   RÔ   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyRx   >  s    

c         C   sf   | rR | |  _  | |  _ |  j j ƒ  rE |  j j ƒ  |  j j ƒ  n  |  j ƒ  n  |  j d | ƒ d S(   s3   Toggle between sphinxified docstrings or plain onesR_   N(	   Rs   Rr   RB   RÐ   Ru   RÒ   RÑ   R\   RÓ   (   R$   RÔ   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyRy   J  s    	
c         C   s+   |  j  ƒ  |  j j ƒ  |  j d | ƒ d S(   s   Toggle automatic import featureR&   N(   R\   Rm   R9   RÓ   (   R$   RÔ   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR}   V  s    
c         C   s   |  j  |  _  |  j ƒ  d S(   sP   
        Toggle locked state
        locked = disable link with Console
        N(   Rj   R€   (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR~   \  s    c         C   sf   t  |  j r d n d ƒ } |  j j | ƒ |  j rC |  j d ƒ n |  j d ƒ } |  j j | ƒ d S(   s   Update locked state icons   lock.pngs   lock_open.pngt   Unlockt   LockN(   R   Rj   R   t   setIconR    t
   setToolTip(   R$   Rc   t   tip(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR€   d  s    'c         C   s   | |  _  d S(   s   Bind to shellN(   R-   (   R$   R-   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt	   set_shellk  s    c         C   sC   d  } |  j d  k	 r' |  j j ƒ  } n  | d  k r? |  j } n  | S(   N(   R(   Ri   t   get_running_python_shellR1   (   R$   R-   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyRÛ   o  s    c         C   s%   |  j  | k r! |  j ƒ  |  _  n  d S(   sb   
        External shall has terminated:
        binding object inspector to another shell
        N(   R-   RÛ   (   R$   R-   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   shell_terminatedw  s    c         C   s<   t  |  j t ƒ s& |  j j j ƒ  r8 |  j ƒ  |  _ n  d S(   sp   
        Checks if bound external shell is still running.
        Otherwise, switch to internal console
        N(   t
   isinstanceR-   R   t   externalshellt
   is_runningRÛ   (   R$   (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR/     s    c         C   sŽ  |  j  d k r d S|  j ƒ  |  j  d k r0 d St | ƒ } |  j  j | ƒ rZ |  j  } nE |  j d ƒ r |  j j | d t ƒr |  j } n d } d } d } | d k	 rä | j | ƒ } t	 | t
 ƒ rÒ d } n  | j | ƒ } n  t } t } |  j d ƒ } |  j rk| d k	 r#t | ƒ }	 n d | d }	 | r;t St |	 t }	 |  j j j |	 t j t ƒ ƒ n |  j r±| }
 |
 d k rú| }
 |
 d k r®| }
 | r«t Sq®qúnI | }
 |
 d k rô| }
 |
 d k rú|  j d ƒ }
 | rñt Sqún t } |  j j j ƒ  rŠ|  j j j | ƒ |  j j j | ƒ | rN|  j j j d ƒ n |  j j j d ƒ |  j j j |
 ƒ |  j j j  d	 ƒ n  | S(
   s	   Show helpNR&   R'   s   No documentation availables   <div id="warning">s   </div>s   No source code available.t   pyt   sof(!   R-   R(   R/   R.   R2   R0   R1   R!   t   get_docRÝ   t   boolt
   get_sourceR"   R    Rs   R   t	   HTML_HEADt	   HTML_TAILRB   Rf   t   setHtmlR
   t   fromLocalFileR   Rr   Ru   R¢   R¹   t   set_highlight_current_linet   set_occurence_highlightingt   set_languaget   set_textt   set_cursor_position(   R$   t   obj_textR±   R-   t   doc_textt   source_textt   is_codeR½   t   no_doct	   html_textt   hlp_text(    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyR´   ˆ  sp    
			
N(#   R:   R;   R<   t   CONF_SECTIONR=   t   CONFIGWIDGET_CLASSR   RÂ   R   R‘   R’   R•   R–   Rœ   R"   Rž   R†   R¯   R°   R\   RŸ   R(   Rp   R¶   Rv   Rx   Ry   R}   R~   R€   RÚ   RÛ   RÜ   R/   R´   (    (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyRX   j   s:   	U																						(1   R<   t   PyQt4.QtGuiR    R   R   R   R   R   R   R   R   t   PyQt4.QtCoreR	   R
   R   t   sysR*   t   os.patht   pathRÀ   R3   t   stdoutt   STDOUTt   spyderlib.configR   R   R   R   t   spyderlib.utils.qthelpersR   R   R   t   spyderlib.widgets.comboboxesR   t+   spyderlib.widgets.externalshell.pythonshellR   t   spyderlib.pluginsR   R   t   spyderlib.utils.sphinxifyR   R   Rå   Ræ   t   ImportErrorR(   R   R=   RX   (    (    (    s<   C:\Python27\lib\site-packages\spyderlib\plugins\inspector.pyt   <module>   s$   @3	"

%