o
    º¼tf—  ã                   @   s   d Z G dd„ deƒZdS )z@Defines a convenient mix-in class for implementing Qt frontends.c                   @   sŒ   e Zd ZdZdZdZedd„ ƒZejdd„ ƒZedd„ ƒZ	e	jdd„ ƒZ	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd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                 C   ó   | j S )z"Returns the current kernel client.)Ú_kernel_client©Úself© r   úf/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/qtconsole/base_frontend_mixin.pyÚkernel_client   ó   zBaseFrontendMixin.kernel_clientc                 C   sü   | j }|dur<|j | j¡ |j | j¡ |jj | j¡ |j	j | j¡ |j
j | j¡ |jj | j¡ |jr<|  ¡  || _ |du rEd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   Zstarted_channelsÚ
disconnectÚ_started_channelsZstopped_channelsÚ_stopped_channelsZiopub_channelZmessage_receivedÚ	_dispatchZshell_channelZstdin_channelZ
hb_channelZkernel_diedÚ_handle_kernel_diedZchannels_runningÚconnect)r   r   Z
old_clientr   r   r   r      s0   ÿÿc                 C   r   )zThe kernel manager, if any)Ú_kernel_managerr   r   r   r   Úkernel_managerB   r	   z BaseFrontendMixin.kernel_managerc                 C   s@   | j }|d ur|j | j¡ || _ |d u rd S |j | j¡ d S )N)r   Zkernel_restartedr
   Ú_handle_kernel_restartedr   )r   r   Úold_manr   r   r   r   G   s   c                 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.
        Nr   )r   Zsince_last_heartbeatr   r   r   r   W   ó    z%BaseFrontendMixin._handle_kernel_diedc                 C   r   )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   r   r   r   r   e   r   z*BaseFrontendMixin._handle_kernel_restartedc                 C   r   )zŒCalled when the KernelManager starts (or restarts) the kernel subprocess.
        Channels may or may not be running at this point.
        Nr   r   r   r   r   Ú_started_kernelp   r   z!BaseFrontendMixin._started_kernelc                 C   r   )z˜ Called when the KernelManager channels have started listening or
            when the frontend is assigned an already listening KernelManager.
        Nr   r   r   r   r   r   u   r   z#BaseFrontendMixin._started_channelsc                 C   r   )z“ Called when the KernelManager channels have stopped listening or
            when a listening KernelManager is removed from the frontend.
        Nr   r   r   r   r   r   z   r   z#BaseFrontendMixin._stopped_channelsc                 C   s0   |d d }t | d| dƒ}|r||ƒ dS dS )zg Calls the frontend handler associated with the message type of the
            given message.
        ÚheaderÚmsg_typeZ_handle_N)Úgetattr)r   Úmsgr   Úhandlerr   r   r   r   ƒ   s
   ÿzBaseFrontendMixin._dispatchc                 C   s   | j jj}|d  d|¡|kS )z-Return whether a message is from this sessionÚparent_headerÚsession)r   r   Úget)r   r   Z
session_idr   r   r   Ú	from_hereŒ   s   
zBaseFrontendMixin.from_herec                 C   sb   |d r|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 messager   Úmsg_idÚexecuteFr   Zexecute_inputT)Z_request_infor   Zhiddenr   Zinclude_other_output)r   r   r    Úinfor   r   r   r   Úinclude_output‘   s   

z BaseFrontendMixin.include_output)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   Úsetterr   r   r   r   r   r   r   r   r#   r   r   r   r   r      s(    


*

		r   N)r'   Úobjectr   r   r   r   r   Ú<module>   s    