Mini Shell
3
<�Zc�
� @ s0 d dl mZ d dlmZmZ G dd� de�ZdS )� )�App)�RenderScreenSignal�CloseScreenSignalc @ sD e Zd ZdZddd�Zddd�Zdd � Zd
d� Zdd
� Zdd� Z dS )�
SignalHandlera" Provides methods for handling signals anc callbacks.
Provides main methods:
`connect()` -- connect this widget on given signal
`create_signal()` -- create signal class which can be used in the emit method
`emit()` -- emit signal given signal
Nc C s t j� j|||� dS )a{ Connect this class method with given signal.
:param signal: signal class which you want to connect
:type signal: class based on `simpleline.event_loop.AbstractSignal`
:param callback: the callback function
:type callback: func(event_message, data)
:param data: Data you want to pass to the callback
:type data: Anything
N)r �get_event_loopZregister_signal_handler)�self�signal�callback�data� r �$/usr/lib/python3.6/signal_handler.py�connect# s zSignalHandler.connectr c C s
|| |�S )a| Create signal instance usable in the emit method.
:param signal_class: signal you want to use
:type signal_class: class based on `simpleline.event_loop.AbstractSignal`
:param priority: priority of the signal; please look on the `simpleline.event_loop.AbstractSignal.priority` for
further info
:type priority: int
r )r Zsignal_classZpriorityr r r �
create_signal1 s
zSignalHandler.create_signalc C s t j� j|� dS )z�Emit the signal.
This will add `signal` to the event loop.
:param signal: signal to emit
:type signal: instance of class based on `simpleline.event_loop.AbstractSignal`
N)r r �enqueue_signal)r r r r r �emit= s zSignalHandler.emitc C s | j |�}| j|� dS )z}Create the signal and emit it.
This is basically shortcut for calling `self.create_signal` and `self.emit`.
N)r r )r r Zcreated_signalr r r �create_and_emitG s
zSignalHandler.create_and_emitc C s | j t�}tj� j|� dS )zYEmit signal to initiate draw.
Add RenderScreenSignal to the event loop.
N)r r r r r )r r r r r �redrawO s
zSignalHandler.redrawc C s | j t�}tj� j|� dS )z\Emit signal to close this screen.
Add CloseScreenSignal to the event loop.
N)r r r r r )r r r r r �closeW s
zSignalHandler.close)N)r )
�__name__�
__module__�__qualname__�__doc__r
r r r r r r r r r r s
r N)Z
simpleliner Zsimpleline.event_loop.signalsr r �objectr r r r r �<module> s