σ
_y]c           @   s    d  Z  d e f d     YZ d S(   s@   Defines a convenient mix-in class for implementing Qt frontends.t   BaseFrontendMixinc           B   s€   e  Z d  Z d Z d Z e d    Z e j d    Z e d    Z	 e	 j d    Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z RS(   sτ    A mix-in class for implementing Qt frontends.

    To handle messages of a particular type, frontends need only define an
    appropriate handler method. For example, to handle 'stream' messaged, define
    a '_handle_stream(msg)' method.
    c         C   s   |  j  S(   s"   Returns the current kernel client.(   t   _kernel_client(   t   self(    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyt   kernel_client   s    c         C   s]  |  j  } | d k	 r¬ | j j |  j  | j j |  j  | j j j |  j	  | j
 j j |  j	  | j j j |  j	  | j j j |  j  | j r¬ |  j   q¬ n  | |  _  | d k rΕ d S| j j |  j  | j j |  j  | j j j |  j	  | j
 j j |  j	  | j j j |  j	  | j j j |  j  | j rY|  j   n  d S(   sd   Disconnect from the current kernel client (if any) and set a new
            kernel client.
        N(   R   t   Nonet   started_channelst
   disconnectt   _started_channelst   stopped_channelst   _stopped_channelst   iopub_channelt   message_receivedt	   _dispatcht   shell_channelt   stdin_channelt
   hb_channelt   kernel_diedt   _handle_kernel_diedt   channels_runningt   connect(   R   R   t
   old_client(    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyR      s,    	
			c         C   s   |  j  S(   s   The kernel manager, if any(   t   _kernel_manager(   R   (    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyt   kernel_managerB   s    c         C   s[   |  j  } | d  k	 r+ | j j |  j  n  | |  _  | d  k rD d  S| j j |  j  d  S(   N(   R   R   t   kernel_restartedR   t   _handle_kernel_restartedR   (   R   R   t   old_man(    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyR   G   s    		c         C   s   d S(   s΄   This is called when the ``kernel_died`` signal is emitted.

        This method is called when the kernel heartbeat has not been
        active for a certain amount of time.
        This is a strictly passive notification -
        the kernel is likely being restarted by its KernelManager.

        Parameters
        ----------
        since_last_heartbeat : float
            The time since the heartbeat was last received.
        N(    (   R   t   since_last_heartbeat(    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyR   W   t    c         C   s   d S(   s9   This is called when the ``kernel_restarted`` signal is emitted.

        This method is called when the kernel has been restarted by the
        autorestart mechanism.

        Parameters
        ----------
        since_last_heartbeat : float
            The time since the heartbeat was last received.
        N(    (   R   (    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyR   e   R   c         C   s   d S(   s   Called when the KernelManager starts (or restarts) the kernel subprocess.
        Channels may or may not be running at this point.
        N(    (   R   (    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyt   _started_kernelp   R   c         C   s   d S(   s    Called when the KernelManager channels have started listening or
            when the frontend is assigned an already listening KernelManager.
        N(    (   R   (    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyR   u   R   c         C   s   d S(   s    Called when the KernelManager channels have stopped listening or
            when a listening KernelManager is removed from the frontend.
        N(    (   R   (    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyR	   z   R   c         C   s;   | d d } t  |  d | d  } | r7 | |  n  d S(   sg    Calls the frontend handler associated with the message type of the
            given message.
        t   headert   msg_typet   _handle_N(   t   getattrR   (   R   t   msgR   t   handler(    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyR      s    c         C   s)   |  j  j j } | d j d |  | k S(   s-   Return whether a message is from this sessiont   parent_headert   session(   R   R$   t   get(   R   R!   t
   session_id(    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyt	   from_here   s    c         C   sO   |  j  r t S|  j |  } | d d k r: |  j o9 | S|  j rG t S| Sd S(   s7   Return whether we should include a given output messageR   t   execute_inputN(   t   _hiddent   FalseR'   t   include_other_outputt   True(   R   R!   R'   (    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyt   include_output   s    		N(   t   __name__t
   __module__t   __doc__R   R   R   t   propertyR   t   setterR   R   R   R   R   R	   R   R'   R-   (    (    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyR       s   +									N(   R0   t   objectR    (    (    (    s<   lib/python2.7/site-packages/qtconsole/base_frontend_mixin.pyt   <module>   s   