U
    Pe                     @   sb   d Z ddlmZ ddlmZ ddlmZmZmZ G dd deZ	e
dkr^ddlmZ ee	  d	S )
a  
Switch
======

.. versionadded:: 1.0.7

.. image:: images/switch-on.jpg
    :align: right

.. image:: images/switch-off.jpg
    :align: right

The :class:`Switch` widget is active or inactive, like a mechanical light
switch. The user can swipe to the left/right to activate/deactivate it::

    switch = Switch(active=True)

To attach a callback that listens to the activation state::

    def callback(instance, value):
        print('the switch', instance, 'is', value)

    switch = Switch()
    switch.bind(active=callback)

By default, the representation of the widget is static. The minimum size
required is 83x32 pixels (defined by the background image). The image is
centered within the widget.

The entire widget is active, not just the part with graphics. As long as you
swipe over the widget's bounding box, it will work.

.. note::

    If you want to control the state with a single touch instead of a swipe,
    use the :class:`ToggleButton` instead.

Kv Example::

    BoxLayout:
        Label:
            text: 'power up'
        Switch:
            id: switch
        Label:
            text: 'woooooooooooh' if switch.active else ''
    )Widget)	Animation)BooleanPropertyObjectPropertyNumericPropertyc                   @   sL   e Zd ZdZedZedddZedZ	edZ
dd Zd	d
 Zdd ZdS )SwitchzASwitch class. See module documentation for more information.
    FNT)Z	allownoner   c                 C   s>   | j s| jd k	rd S | j|j s$d S ||  d| _|| _dS )Nr   T)disabledtouch_controlZcollide_pointposZgrabtouch_distanceselftouch r   3/tmp/pip-unpacked-wheel-xzebddm3/kivy/uix/switch.pyon_touch_downY   s    
zSwitch.on_touch_downc                 C   s    |j | k	rd S |j|j | _dS )NT)grab_currentxoxr   r   r   r   r   on_touch_movec   s    
zSwitch.on_touch_movec                 C   sh   |j | k	rd S ||  t|j|j dk r8| j | _n| jdk| _tt| jddd	|  d | _
dS )N   g      ?Zout_quadg?)active_norm_postdT)r   Zungrababsr   r   activer   r   intstartr	   r   r   r   r   on_touch_upi   s    

zSwitch.on_touch_up)__name__
__module____qualname____doc__r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   7   s   	
r   __main__)runTouchAppN)r"   Zkivy.uix.widgetr   Zkivy.animationr   Zkivy.propertiesr   r   r   r   r   Z	kivy.baser$   r   r   r   r   <module>   s   1A