ó
‹²,]c           @   s¿   d  Z  d d l Z d d l m Z d d l m Z d d l Z d d l m Z d d l	 m
 Z
 m Z d d l m Z m Z y e j Wn e k
 r¤ e j e _ n Xd e f d	 „  ƒ  YZ d S(
   sY   
Widget that handle communications between the IPython Console and
the Variable Explorer
iÿÿÿÿN(   t
   QEventLoop(   t   QMessageBox(   t   RichJupyterWidget(   t   _t   debug_print(   t   PY2t   to_text_stringt   NamepaceBrowserWidgetc           B   s›   e  Z d  Z d Z i  Z d Z e Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   s   
    Widget with the necessary attributes and methods to handle communications
    between the IPython Console and the Variable Explorer
    c         C   s   | |  _  |  j ƒ  d S(   s   Set namespace browser widgetN(   t   namespacebrowsert   configure_namespacebrowser(   t   selfR   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt   set_namespacebrowser0   s    	c            s6   ˆ  j  j ‡  f d †  ƒ ˆ  j j ‡  f d †  ƒ d S(   s-   Configure associated namespace browser widgetc            s   ˆ  j  j |  ƒ S(   N(   R   t   process_remote_view(   t   data(   R
   (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt   <lambda>8   s    c            s   ˆ  j  j |  ƒ S(   N(   R   t   set_var_properties(   R   (   R
   (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyR   <   s    N(   t   sig_namespace_viewt   connectt   sig_var_properties(   R
   (    (   R
   sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyR	   5   s    c         C   s*   |  j  r& |  j d ƒ |  j d ƒ n  d S(   s   Refresh namespace browsers)   get_ipython().kernel.get_namespace_view()s)   get_ipython().kernel.get_var_properties()N(   R   t   silent_exec_method(   R
   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt   refresh_namespacebrowser?   s
    	c         C   s<   |  j  r8 t |  j  j ƒ  ƒ } d | } |  j | ƒ n  d S(   s   Set the namespace view settingsu1   get_ipython().kernel.namespace_view_settings = %sN(   R   R   t   get_view_settingst   silent_execute(   R
   t   settingst   code(    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt   set_namespace_view_settingsG   s    	c         C   sÂ   d | } |  j  r, |  j j } d | } n	 |  j } t ƒ  } |  j j | j ƒ | | ƒ | j ƒ  |  j j	 | j ƒ d } |  j d k r» |  j r» |  j } d |  _ t | ƒ ‚ q» n  |  j S(   s   Ask kernel for a valueu$   get_ipython().kernel.get_value('%s')u   !N(   t   _readingt   kernel_clientt   inputR   R    t   sig_got_replyR   t   quitt   exec_t
   disconnectt   Nonet   _kernel_valuet   _kernel_replyt
   ValueError(   R
   t   nameR   t   methodt	   wait_loopt   msg(    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt	   get_valueP   s"    
			

	
	c         C   sP   t  | ƒ } d | | t f } |  j r? |  j j d | ƒ n |  j | ƒ d S(   s   Set value for a variableu,   get_ipython().kernel.set_value('%s', %s, %s)u   !N(   R   R   R   R   R   R   (   R
   R%   t   valueR   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt	   set_valuel   s    	
	c         C   s;   d | } |  j  r* |  j j d | ƒ n |  j | ƒ d S(   s   Remove a variableu'   get_ipython().kernel.remove_value('%s')u   !N(   R   R   R   R   (   R
   R%   R   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt   remove_valuew   s    
	c         C   sA   d | | f } |  j  r0 |  j j d | ƒ n |  j | ƒ d S(   s   Copy a variableu+   get_ipython().kernel.copy_value('%s', '%s')u   !N(   R   R   R   R   (   R
   t	   orig_namet   new_nameR   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt
   copy_value   s
    
	c         C   s   |  j  r2 t d ƒ } t j |  t d ƒ | ƒ d  St ƒ  } |  j j | j ƒ |  j d | | f ƒ | j	 ƒ  |  j j
 | j ƒ d  } |  j S(   Ns;   Loading this kind of data while debugging is not supported.t   Warnings*   get_ipython().kernel.load_data('%s', '%s')(   R   R   R   t   warningR    R   R   R   R   R   R    R!   R#   (   R
   t   filenamet   extt   messageR'   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt	   load_dataˆ   s    		
c         C   s‰   |  j  r2 t d ƒ } t j |  t d ƒ | ƒ d  St ƒ  } |  j j | j ƒ |  j d | ƒ | j	 ƒ  |  j j
 | j ƒ d  } |  j S(   Ns-   Saving data while debugging is not supported.R0   s)   get_ipython().kernel.save_namespace('%s')(   R   R   R   R1   R    R   R   R   R   R   R    R!   R#   (   R
   R2   R4   R'   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt   save_namespace›   s    			
c         C   s=  | d j  d ƒ } | d k r¨ yA t rB t j | d d ƒ } n t j t | d d ƒ ƒ } Wn+ t k
 r } d |  _ t | ƒ |  _	 n
 X| |  _ |  j
 j ƒ  d S| d k rð | d d } | d k	 r9t | t ƒ r9|  j | ƒ q9nI | d k r|  j d	 ƒ n- | d
 k r+|  j d t ƒ n t d | ƒ d S(   s1   
        Handle internal spyder messages
        t   contentt   spyder_msg_typeR   t   buffersi    Nt	   pdb_statet   pdb_continuet   continuet   set_breakpointst   forces   No such spyder message type: %s(   t   getR   t   cloudpicklet   loadst   bytest	   ExceptionR!   R"   t   reprR#   R   t   emitt
   isinstancet   dictt   refresh_from_pdbt   write_to_stdint   set_spyder_breakpointst   TrueR   (   R
   R(   R8   R*   R:   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt   _handle_spyder_msg®   s*    !		c         C   sù   | d d } |  j  d j | ƒ } t |  _ | d j d d ƒ } | d k rœ |  j rœ |  j d	 k	 r~ |  j ƒ  |  j ƒ  n  t |  _ t	 j
 ƒ  |  j _ n  | rß | j d k rß |  j rß |  j | ƒ |  j  d j | ƒ n t t |  ƒ j | ƒ d	 S(
   s^   
        Reimplemented to handle communications between Spyder
        and the kernel
        t   parent_headert   msg_idt   executeR7   t   execution_countt    i    R   N(   t   _request_infoR?   t   FalseR   t   _kernel_is_startingR   R!   R   R   t   timet	   monotonict	   ipyclientt   t0t   kindt   _hiddent   handle_exec_methodt   popt   superR   t   _handle_execute_reply(   R
   R(   RN   t   infot
   exec_count(    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyR^   Ï   s    	
	c         C   sþ   | d j  d d ƒ } | d j  d d ƒ } | d k r‘ t j ƒ  |  j _ |  j j j j |  j j ƒ |  j j j	 d ƒ |  j
 sú t |  _
 qú ni | d k rä | d	 k rä |  j d
 k	 rÏ |  j ƒ  |  j ƒ  n  t j ƒ  |  j _ n t t |  ƒ j | ƒ d
 S(   s]   
        Reimplemented to refresh the namespacebrowser after kernel
        restarts
        R7   t   execution_stateRQ   RM   t   msg_typet   startingiè  t   idlet   shutdown_requestN(   R?   RU   RV   RW   RX   t   timert   timeoutR   t	   show_timet   startRT   RK   R   R!   R   R   R]   R   t   _handle_status(   R
   R(   t   stateRb   (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyRj   ê   s    	
N(   t   __name__t
   __module__t   __doc__R!   R   t   _kernel_methodsR"   RK   RT   R   R	   R   R   R)   R+   R,   R/   R5   R6   RL   R^   Rj   (    (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyR      s$   		
											!	(   Rn   RU   t   qtpy.QtCoreR    t   qtpy.QtWidgetsR   R@   t   qtconsole.rich_jupyter_widgetR   t   spyder.config.baseR   R   t   spyder.py3compatR   R   RV   t   AttributeErrorR   (    (    (    sM   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.pyt   <module>
   s   