U
    Pe                     @   s   d Z dZddlmZ ddlmZmZ ddlmZ G dd deZ	e
dkrdd	lmZ dd
lmZ e	 ZeddD ]Zede dZee qpee dS )a  
PageLayout
==========

.. image:: images/pagelayout.gif
    :align: right

The :class:`PageLayout` class is used to create a simple multi-page
layout, in a way that allows easy flipping from one page to another using
borders.

:class:`PageLayout` does not currently honor the
:attr:`~kivy.uix.widget.Widget.size_hint`,
:attr:`~kivy.uix.widget.Widget.size_hint_min`,
:attr:`~kivy.uix.widget.Widget.size_hint_max`, or
:attr:`~kivy.uix.widget.Widget.pos_hint` properties.

.. versionadded:: 1.8.0

Example:

.. code-block:: kv

    PageLayout:
        Button:
            text: 'page1'
        Button:
            text: 'page2'
        Button:
            text: 'page3'

Transitions from one page to the next are made by swiping in from the border
areas on the right or left hand side. If you wish to display multiple widgets
in a page, we suggest you use a containing layout. Ideally, each page should
consist of a single :mod:`~kivy.uix.layout` widget that contains the remaining
widgets on that page.
)
PageLayout    )Layout)NumericPropertyDictProperty)	Animationc                       sf   e Zd ZdZedZedZedZedddZ	 fddZ
d	d
 Zdd Zdd Zdd Z  ZS )r   zEPageLayout class. See module documentation for more information.
    r   Z50dpg      ?Zin_quad)dtc                    s^   t t| jf | | j}| j}|d| |d| |d| |d| |d| |d| d S )Nborderpageparentchildrensizepos)superr   __init___trigger_layoutfbind)selfkwargsZtriggerr   	__class__ 7/tmp/pip-unpacked-wheel-xzebddm3/kivy/uix/pagelayout.pyr   R   s    




zPageLayout.__init__c                 G   s   t | jd }| j}| j\}}| j}| j}|d }| j}	| j| }
tt	| jD ]\}}||k rf|}nV||kr|sx|}q||kr|| }q|| }n(||d kr|s|	| }q|	| }n|	}||_|
|_t
f ||d| j| qPd S )N          @)xy)lenr   heightr   r
   r	   rightwidth	enumeratereversedr   anim_kwargsstart)r   largsZ
l_childrenhZx_parentZy_parentpr	   half_borderr   r    icr   r   r   r   	do_layout^   s@    





zPageLayout.do_layoutc                 C   s   | j s| j|j r| jsd S | j| j d  }| j|j  krH|jk rdn nd|jd< ||  dS |j|j  kr~| jk rn nd|jd< ||  dS |	|S )Nr   previousr
   Tnext)
disabledZcollide_pointr   r   r
   r   udZgrabr   on_touch_down)r   touchr
   r   r   r   r0      s"    




zPageLayout.on_touch_downc                 C   sD  |j | krd S | j}| j}|d }| j| d  }|jd dkr.|t| jd k rt| j| jd|j|j	    | j| j| d  _
|dkr|dkr|n|}|t| jd k r|n|}tt| j
| |j
|j  | j| | j
| | j| d  _
|dkr:t| j
||j|j	   | j
| | j|  _
n|jd dkr:|dkrxt| j
|d|j	|j    | j
| j| d  _
|t| jd k r|dkr|n|}|t| jd k r|n|}tt| j| |j
|j  | j
| | j| | j| d  _
|t| jd k r:t| j||j|j	   | j| | j| d  _
||S )Nr   r   r
   r,      r-      )grab_currentr
   r	   r   r/   r   minr   ZsxZosxr   maxoxon_touch_move)r   r1   r'   r	   r(   r
   Zb_rightZb_leftr   r   r   r8      s^    


zPageLayout.on_touch_movec                 C   s   |j | kr|jd dkrDt|j|j | j | jkrD|  jd8  _nB|jd dkr~t|j|j | j | jkr~|  jd7  _n|   |	|  t
| jdkr| j| j d  |S d S )Nr
   r,   r   r-   )r4   r/   absr   r7   r    swipe_thresholdr
   r   Zungrabr   r   on_touch_up)r   r1   r   r   r   r;      s    

zPageLayout.on_touch_up)__name__
__module____qualname____doc__r   r
   r	   r:   r   r#   r   r+   r0   r8   r;   __classcell__r   r   r   r   r   .   s   	$6r   __main__)runTouchApp)Buttonr      zpage%s)textN)r?   __all__Zkivy.uix.layoutr   Zkivy.propertiesr   r   Zkivy.animationr   r   r<   Z	kivy.baserB   Zkivy.uix.buttonrC   plranger)   bZ
add_widgetr   r   r   r   <module>   s   & 3