ó
ē,]c           @   s   d  Z  d d l Z d d l Z d d l 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 e f d	     YZ d S(
   sS   
Widget that handles communications between a console in debugging
mode and Spyder
iĸĸĸĸN(   t   Qt(   t   RichJupyterWidget(   t   PICKLE_PROTOCOL(   t   CONF(   t   to_text_stringt   DebuggingWidgetc           B   sJ   e  Z d  Z d   Z e d  Z d d  Z d   Z d   Z d   Z	 RS(   s   
    Widget with the necessary attributes and methods to handle
    communications between a console in debugging mode and
    Spyder
    c         C   s   |  j  j |  d S(   s7   Send raw characters to the IPython kernel through stdinN(   t   kernel_clientt   input(   t   selft   line(    (    sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyt   write_to_stdin    s    c         C   sn   |  j  s | rj t j d d i   } t j | d t g } t |  } d } |  j j | j	 |   n  d S(   s/   Set Spyder breakpoints into a debugging sessiont   runt   breakpointst   protocolu1   !get_ipython().kernel._set_spyder_breakpoints({})N(
   t   _readingR   t   gett   picklet   dumpsR   R   R   R   t   format(   R   t   forcet   breakpoints_dictt   serialiazed_breakpointsR   t   cmd(    (    sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyt   set_spyder_breakpoints$   s    t    c         C   s&   d j  | |  } |  j j |  d S(   s%   Run an IPython magic while debugging.s6   !get_ipython().kernel.shell.run_line_magic('{}', '{}')N(   R   R   R   (   R   t   magict   argst   code(    (    sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyt   dbg_exec_magic2   s    c         C   sŠ   d | k rN d | d k rN | d d } | d d } |  j  j | |  n  d | k rz |  j j t j | d   n  d | k rĶ |  j j t j | d   n  d S(   sī   
        Refresh Variable Explorer and Editor from a Pdb session,
        after running any pdb command.

        See publish_pdb_state and notify_spyder in spyder_kernels
        t   stept   fnamet   linenot   namespace_viewt   var_propertiesN(   t   sig_pdb_stept   emitt   sig_namespace_viewt   astt   literal_evalt   sig_var_properties(   R   t	   pdb_stateR   R   (    (    sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyt   refresh_from_pdb8   s    c            sy     j  r t d   n    j j j     f d   }   j rL t   _ n    j | d d d | d | d d d S(   s#   Save history and add a %plot magic.s.   Request for raw input during hidden execution.c            sÃ   t    j j  d k o+   j j d |  k ss |  j d  d } d | t t j  k rs   j j j |   qs n  |  j d  rŊ |  j   d }  d |  }   j	 j
 |  n   j	 j
 |   d  S(   Ni    iĸĸĸĸt    t   do_s   %plot s+   __spy_code__ = get_ipython().run_cell('%s')(   t   lent   _controlt   historyt   splitt   dirt   pdbt   Pdbt   appendt
   startswithR   R   (   R	   R   R   (   R   (    sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyt   callbackV   s    
t   contentt   promptR5   t   passwordN(   t   _hiddent   RuntimeErrorR   t   iopub_channelt   flushR   t   Falset	   _readline(   R   t   msgR5   (    (   R   sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyt   _handle_input_requestM   s    		c         C   sÔ   | j    } |  j rš |  j |  j _ | t j k rJ |  j j d t  t S| t j	 k rp |  j j d t
  t S| t j t j f k r |  j j   n t
 |  j _ t t |   j |  St t |   j |  Sd S(   s'   Handle Key_Up/Key_Down while debugging.t   backwardN(   t   keyR   t   _prompt_posR-   t   current_prompt_posR    t   Key_Upt   browse_historyt   Truet   Key_DownR=   t
   Key_Returnt	   Key_Entert   reset_search_post   hist_wholelinet   superR   t   _event_filter_console_keypress(   R   t   eventRB   (    (    sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyRN   l   s     	(
   t   __name__t
   __module__t   __doc__R
   R=   R   R   R)   R@   RN   (    (    (    sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyR      s   			(   RR   R%   R1   R   t   qtpy.QtCoreR    t   qtconsole.rich_jupyter_widgetR   t   spyder.config.baseR   t   spyder.config.mainR   t   spyder.py3compatR   R   (    (    (    sF   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/debugging.pyt   <module>
   s   