
    Ya                         d Z  G d de      Zy)z@Defines a convenient mix-in class for implementing Qt frontends.c                       e Zd 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y)BaseFrontendMixinz 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.
    Nc                     | j                   S )z"Returns the current kernel client.)_kernel_clientselfs    ?/usr/lib/python3/dist-packages/qtconsole/base_frontend_mixin.pykernel_clientzBaseFrontendMixin.kernel_client   s     """    c                    | j                   }|"|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                          || _         |y|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                          yy)zdDisconnect from the current kernel client (if any) and set a new
            kernel client.
        N)r   started_channels
disconnect_started_channelsstopped_channels_stopped_channelsiopub_channelmessage_received	_dispatchshell_channelstdin_channel
hb_channelkernel_died_handle_kernel_diedchannels_runningconnect)r   r	   
old_clients      r   r	   zBaseFrontendMixin.kernel_client   s    ((
!''2243I3IJ''2243I3IJ $$55@@P$$55@@P$$55@@P!!--88((* **&&( ,  	&&..t/E/EF&&..t/E/EF 	##44<<T^^L##44<<T^^L##44<<T^^L  ,,44T5M5MN ))""$ *r
   c                     | j                   S )zThe kernel manager, if any)_kernel_managerr   s    r   kernel_managerz BaseFrontendMixin.kernel_managerB   s     ###r
   c                     | j                   }|%|j                  j                  | j                         || _         |y |j                  j	                  | j                         y )N)r   kernel_restartedr   _handle_kernel_restartedr   )r   r   old_mans      r   r   z BaseFrontendMixin.kernel_managerG   sX    &&$$//0M0MN-!''//0M0MNr
   c                      y)a   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   since_last_heartbeats     r   r   z%BaseFrontendMixin._handle_kernel_diedW       r
   c                      y)a9   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.
        Nr$   r   s    r   r!   z*BaseFrontendMixin._handle_kernel_restartede   r&   r
   c                      y)zCalled when the KernelManager starts (or restarts) the kernel subprocess.
        Channels may or may not be running at this point.
        Nr$   r   s    r   _started_kernelz!BaseFrontendMixin._started_kernelp   r&   r
   c                      y)z Called when the KernelManager channels have started listening or
            when the frontend is assigned an already listening KernelManager.
        Nr$   r   s    r   r   z#BaseFrontendMixin._started_channelsu   r&   r
   c                      y)z Called when the KernelManager channels have stopped listening or
            when a listening KernelManager is removed from the frontend.
        Nr$   r   s    r   r   z#BaseFrontendMixin._stopped_channelsz   r&   r
   c                 J    |d   d   }t        | d|z   d      }|r	 ||       yy)zg Calls the frontend handler associated with the message type of the
            given message.
        headermsg_type_handle_N)getattr)r   msgr.   handlers       r   r   zBaseFrontendMixin._dispatch   s4     x=,$
X 5t<CL r
   c                 r    | j                   j                  j                  }|d   j                  d|      |k(  S )z-Return whether a message is from this sessionparent_headersession)r   r5   get)r   r1   
session_ids      r   	from_herezBaseFrontendMixin.from_here   s6    ((0088
?#''	:>*LLr
   c                     |d   r5|d   d   }| j                   d   j                  |      }|r|j                  ry| j                  |      }|d   dk(  r| j                  xr | S | j                  ry|S )z7Return whether we should include a given output messager4   msg_idexecuteFr.   execute_inputT)_request_infor6   hiddenr8   include_other_output)r   r1   r:   infor8   s        r   include_outputz BaseFrontendMixin.include_output   s    )(3F%%i044V<DNN3'	z?o-,,>Y>$$r
   )__name__
__module____qualname____doc__r   r   propertyr	   setterr   r   r!   r)   r   r   r   r8   rA   r$   r
   r   r   r      s     NO# # (% (%T $ $ 	O 	O


M
r
   r   N)rE   objectr   r$   r
   r   <module>rI      s    F] ]r
   