
    
8d                     &    d Z  G d de          ZdS )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dS )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    =lib/python3.11/site-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        r|                                  || _         |dS |j                            | j                   |j                            | j                   |j        j                            | j                   |j	        j                            | j                   |j
        j                            | j                   |j        j                            | j                   |j        r|                                  dS dS )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243IJJJ'2243IJJJ $5@@PPP$5@@PPP$5@@PPP!-88(* * * * )&&((( , F 	&..t/EFFF&..t/EFFF 	#4<<T^LLL#4<<T^LLL#4<<T^LLL ,44T5MNN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                   || _         |d S |j                            | j                   d S )N)r   kernel_restartedr   _handle_kernel_restartedr   )r   r   old_mans      r   r   z BaseFrontendMixin.kernel_managerG   s]    &$//0MNNN-!F'//0MNNNNNr
   c                     dS )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                     dS )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                     dS )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                     dS )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                     dS )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                 h    |d         d         }t          | d|z   d          }|r ||           dS dS )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   sK     x=,$
X 5t<< 	GCLLLLL	 	r
   c                 d    | j         j        j        }|d                             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   s0    (08
?#''	:>>*LLr
   c                     |d         r9|d         d         }| j         d                             |          }|r	|j        rdS |                     |          }|d         dk    r
| j        o| S | j        rdS |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  uNN3''	z?o--,>Y>$ 	4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# # X# (% (% (%T $ $ X$ 	O 	O 	O  
 
 
  
  
    M M M
    r
   r   N)rE   objectr   r$   r
   r   <module>rI      sI    F F] ] ] ] ] ] ] ] ] ]r
   