U
    Pe6                     @   s   d Z dZddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZ ddlmZ G dd deZG d	d
 d
eZedkrddlmZ ddlmZ ddlmZ G dd deZe   dS )a  Splitter
======

.. versionadded:: 1.5.0

.. image:: images/splitter.jpg
    :align: right

The :class:`Splitter` is a widget that helps you re-size its child
widget/layout by letting you re-size it via dragging the boundary or
double tapping the boundary. This widget is similar to the
:class:`~kivy.uix.scrollview.ScrollView` in that it allows only one
child widget.

Usage::

    splitter = Splitter(sizable_from = 'right')
    splitter.add_widget(layout_or_widget_instance)
    splitter.min_size = 100
    splitter.max_size = 250

To change the size of the strip/border used for resizing::

    splitter.strip_size = '10pt'

To change its appearance::

    splitter.strip_cls = your_custom_class

You can also change the appearance of the `strip_cls`, which defaults to
:class:`SplitterStrip`, by overriding the `kv` rule in your app:

.. code-block:: kv

    <SplitterStrip>:
        horizontal: True if self.parent and self.parent.sizable_from[0] in ('t', 'b') else False
        background_normal: 'path to normal horizontal image' if self.horizontal else 'path to vertical normal image'
        background_down: 'path to pressed horizontal image' if self.horizontal else 'path to vertical pressed image'

)Splitter    )Factory)Button)OptionPropertyNumericPropertyObjectPropertyListPropertyBooleanProperty)	BoxLayoutc                   @   s   e Zd ZdZdS )SplitterStripzdClass used for the graphical representation of a
    :class:`kivy.uix.splitter.SplitterStripe`.
    N)__name__
__module____qualname____doc__ r   r   5/tmp/pip-unpacked-wheel-xzebddm3/kivy/uix/splitter.pyr   7   s   r   c                       s   e Zd ZdZeddddgZeeZe	dddZ
edZedZedZed	Zed
ddZedZedZdZ fddZ fddZd, fdd	Z fddZdd Zdd Zdd Zdd Zd d! Zd"d# Zed$d% Z d&d' Z!d(d) Z"d*d+ Z#  Z$S )-r   a	  See module documentation.

    :Events:
        `on_press`:
            Fired when the splitter is pressed.
        `on_release`:
            Fired when the splitter is released.

    .. versionchanged:: 1.6.0
        Added `on_press` and `on_release` events.

       left)r   righttopbottom)optionsZ10ptZ100ptZ500ptg        NT)Z	allownoneF)on_press
on_releasec                    sN   d | _ d | _tt| jf | | j}| j}|d| |d| |d| j d S )Nmax_sizemin_sizeparent)
_container_stripsuperr   __init___do_sizefbind_rebind_parent)selfkwargsZdo_sizer"   	__class__r   r   r       s    

zSplitter.__init__c                    s  |j s
d S tt|}|j}|rf|j|jd |j|jd |j|jd | j|dd |	|j |j
}t||st|trt|}|  |_}|jd }|dkrd|_|j|_d	|_|j|d
d |j|d
d n8d|_|j|_d|_|j|dd |j|dd d}|dkr,d}||| |j|jd |j|jd |j|jd | j|_| j|dd d S )N)Zon_touch_down)Zon_touch_move)Zon_touch_updisabled)r(   r   lrN   Z
horizontalwidth)
strip_size)r-   NZverticalheightr-   r+   b)r   r   r   r   unbind
strip_down
strip_movestrip_upsetterremove_widget	strip_cls
isinstancestrr   getsizable_from	size_hintr/   r.   Zorientationbindr0   
add_widgetr(   )r$   instancer=   supZ_strpclssz_frmindexr&   r   r   on_sizable_from   sH    





zSplitter.on_sizable_fromr   c                    st   | j s
|stdS || _ | jd }|dkr2d|_nd|_d}|dkrHd}tt| j||f|| | | | j d S )NzSplitter accepts only one Childr   r)   r-   r1   )	r   	Exceptionr=   size_hint_xsize_hint_yr   r   r@   rF   )r$   widgetrE   argsr%   rD   r&   r   r   r@      s    

zSplitter.add_widgetc                    s,   t t| j|f|| || jkr(d | _d S N)r   r   r8   r   )r$   rJ   rK   r%   r&   r   r   r8      s    
zSplitter.remove_widgetc                 O   s   |  | j d S rL   )r8   r   )r$   rK   r%   r   r   r   clear_widgets   s    zSplitter.clear_widgetsc                 C   s(   |j |j sdS ||  | d d S )NFr   )Zcollide_pointposZgrabdispatch)r$   rA   touchr   r   r   r4     s    
zSplitter.strip_downc                 C   s   d S rL   r   r$   r   r   r   r     s    zSplitter.on_pressc                 C   sD   | j d k	r| j j| jd | jd k	r2|j| jd || _ |   d S )N)size)_bound_parentr3   rescale_parent_proportionr   r?   )r$   rA   Z
new_parentr   r   r   r#     s    

zSplitter._rebind_parentc                 G   sj   | j s
d S | jrf| j}| jdkrD|| j j }t| jt|| j| _n"|| j j	 }t| jt|| j| _	d S )N)r   r   )
r   rescale_with_parent_parent_proportionr=   r0   maxr   minr   r.   )r$   rK   Zparent_proportionZ
new_heightZ	new_widthr   r   r   rT     s    

z"Splitter.rescale_parent_proportionc                 C   sD   | j d dkr(t| jt| j| j| _nt| jt| j| j| _d S )Nr   r)   )r=   rW   r   rX   r.   r   r0   )r$   rA   valuer   r   r   r!      s    zSplitter._do_sizec                 C   sJ   | dkr|}n|}|dkrdS |dkr2||kr2dS |dk rF||krFdS dS )N)r*   r2   r   FTr   )rD   ZdiffrN   ZminposZmaxposcmpr   r   r   
_is_moving&  s    zSplitter._is_movingc                 C   s  |j |k	rdS | j}| j}| jd }|dkr|j}| j}| j}| |||j||sXd S | jr|dkr|| | j	jkr| j	j| }n$|dkr|| | j	jk r| j	j| }|dkr|d9 }| j
rd | _
| jdkr|  j|7  _nd| _| j}	t|t|	|| _| j| j	j | _n|j}
| j}| j}| ||
|j||s:d S | jr|dkrl||
 | j	jk rl| j	j| }
n(|d	kr||
 | j	jkr| j	j| }
|dkr|
d9 }
| jrd | _| jdkr|  j|
7  _nd| _| j}t|t||| _| j| j	j | _d S )
NFr   tr2   r]   r2   r-   r*   r+   )grab_currentr   r   r=   Zdyyr   r[   keep_within_parentr   rI   r0   rW   rX   rV   Zdxxr   rH   r.   )r$   rA   rP   r   r   rD   Zdiff_yZself_yZself_topr0   Zdiff_xZself_xZ
self_rightr.   r   r   r   r5   4  s`    





zSplitter.strip_movec                 C   s   |j |k	rd S |jr| j}| j}| jd }| j}|dkrl| jrDd | _|d | ||d  krd|| _q|| _n2| jrxd | _|d | ||d  kr|| _	n|| _	|
| | d d S )Nr   r\   r-   r   )r_   Zis_double_tapr   r   r=   rR   rI   r0   rH   r.   ZungrabrO   )r$   rA   rP   r   r   rD   sr   r   r   r6   m  s(    


zSplitter.strip_upc                 C   s   d S rL   r   rQ   r   r   r   r     s    zSplitter.on_release)r   )%r   r   r   r   r   Zborderr   r   r9   r   r=   r   r/   r   r   rV   rS   r	   ra   rU   Z
__events__r    rF   r@   r8   rM   r4   r   r#   rT   r!   staticmethodr[   r5   r6   r   __classcell__r   r   r&   r   r   >   s6   	
	.
9r   __main__)App)FloatLayoutc                   @   s   e Zd Zdd ZdS )SplitterAppc                 C   s   t  }t }|t  |t  t }|t  |t  |t  tdddidd}tdddd	}|t  || || td
d}|| d|_|| || |S )N)r-         ?r   r-   r   )r>   Zpos_hintr=   r   r,   Z   )r=   r>   r.   )rj   r-   )r>   r   )rh   r
   r@   r   r   r=   )r$   rootZbxZbx2ZsplZspl1Zspl2r   r   r   build  s6     





zSplitterApp.buildN)r   r   r   rm   r   r   r   r   ri     s   ri   N)r   __all__Zkivy.factoryr   Zkivy.uix.buttonr   Zkivy.propertiesr   r   r   r   r	   Zkivy.uix.boxlayoutr
   r   r   r   Zkivy.apprg   Zkivy.uix.floatlayoutrh   ri   runr   r   r   r   <module>   s   -  P