U
    Pe)                     @   s"  d Z dZddlmZ ddlmZmZmZmZm	Z	m
Z
 ddlmZ G dd deZedkrdd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ eddZeedd edddZee eddZedD ],Zede dZej ej!d ee qee e!  e  dS )a  
ModalView
=========

.. versionadded:: 1.4.0

The :class:`ModalView` widget is used to create modal views. By default, the
view will cover the whole "main" window.

Remember that the default size of a Widget is size_hint=(1, 1). If you don't
want your view to be fullscreen, either use size hints with values lower than
1 (for instance size_hint=(.8, .8)) or deactivate the size_hint and use fixed
size attributes.

Examples
--------

Example of a simple 400x400 Hello world view::

    view = ModalView(size_hint=(None, None), size=(400, 400))
    view.add_widget(Label(text='Hello world'))

By default, any click outside the view will dismiss it. If you don't
want that, you can set :attr:`ModalView.auto_dismiss` to False::

    view = ModalView(auto_dismiss=False)
    view.add_widget(Label(text='Hello world'))
    view.open()

To manually dismiss/close the view, use the :meth:`ModalView.dismiss` method of
the ModalView instance::

    view.dismiss()

Both :meth:`ModalView.open` and :meth:`ModalView.dismiss` are bind-able. That
means you can directly bind the function to an action, e.g. to a button's
on_press ::

    # create content and add it to the view
    content = Button(text='Close me!')
    view = ModalView(auto_dismiss=False)
    view.add_widget(content)

    # bind the on_press event of the button to the dismiss function
    content.bind(on_press=view.dismiss)

    # open the view
    view.open()


ModalView Events
----------------

There are four events available: `on_pre_open` and `on_open` which are raised
when the view is opening; `on_pre_dismiss` and `on_dismiss` which are raised
when the view is closed.

For `on_dismiss`, you can prevent the view from closing by explicitly
returning `True` from your callback::

    def my_callback(instance):
        print('ModalView', instance, 'is being dismissed, but is prevented!')
        return True
    view = ModalView()
    view.add_widget(Label(text='Hello world'))
    view.bind(on_dismiss=my_callback)
    view.open()


.. versionchanged:: 1.5.0
    The ModalView can be closed by hitting the escape key on the
    keyboard if the :attr:`ModalView.auto_dismiss` property is True (the
    default).

)	ModalView    )	Animation)StringPropertyBooleanPropertyObjectPropertyNumericPropertyListPropertyColorProperty)AnchorLayoutc                       s  e Zd ZdZedZedddZeddddgZ	e
dZeddddgZedddd	gZedZed
ZedddZedZdZdZ fddZdd Zdd Zdd Z fddZ fddZ 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#d*d+ Z$  Z%S ),r   a  ModalView class. See module documentation for more information.

    :Events:
        `on_pre_open`:
            Fired before the ModalView is opened. When this event is fired
            ModalView is not yet added to window.
        `on_open`:
            Fired when the ModalView is opened.
        `on_pre_dismiss`:
            Fired before the ModalView is closed.
        `on_dismiss`:
            Fired when the ModalView is closed. If the callback returns True,
            the dismiss will be canceled.

    .. versionchanged:: 1.11.0
        Added events `on_pre_open` and `on_pre_dismiss`.

    .. versionchanged:: 2.0.0
        Added property 'overlay_color'.

    .. versionchanged:: 2.1.0
        Marked `attach_to` property as deprecated.

    TN)
deprecated   z5atlas://data/images/defaulttheme/modalview-background   r   gffffff?g?)Z	allownoneZrebindF)on_pre_openon_openon_pre_dismiss
on_dismissc                    s   d | _ tt| jf | d S N)_parentsuperr   __init__)selfkwargs	__class__ 6/tmp/pip-unpacked-wheel-xzebddm3/kivy/uix/modalview.pyr      s    zModalView.__init__c                    s   ddl m}  jrdS | _d _ d |  |j j jd |j	 _	 
d j  
d j |d	drtd
 jd}|j fddd |  nd
 _ d dS )zDisplay the modal in the Window.

        When the view is opened, it will be faded in with an animation. If you
        don't want the animation, use::

            view.open(animation=False)

        r   WindowNTr   Z	on_resizeZon_keyboardcentersize	animationg      ?_anim_alphadc                     s
     dS )Nr   )dispatch)_argsr   r   r   <lambda>       z ModalView.open.<locals>.<lambda>)Zon_completer   )kivy.core.windowr   _is_open_windowr%   
add_widgetbind_align_center_handle_keyboardr   Zfbindgetr   _anim_durationstartr#   )r   r&   r   r   Zanir   r'   r   open   s(    	

zModalView.openc                 O   sj   | j s
dS | d | ddkr6|dddk	r6dS |ddrXtd| jd	|  nd
| _|   dS )a   Close the view if it is open.

        If you really want to close the view, whatever the on_dismiss
        event returns, you can use the *force* keyword argument::

            view = ModalView()
            view.dismiss(force=True)

        When the view is dismissed, it will be faded out before being
        removed from the parent. If you don't want this animation, use::

            view.dismiss(animation=False)

        Nr   r   TforceFr!   g        r"   r   )r+   r%   r1   r   r2   r3   r#   _real_remove_widget)r   r&   r   r   r   r   dismiss   s    
zModalView.dismissc                 G   s   | j r| jj| _d S r   )r+   r,   r   )r   r&   r   r   r   r/      s    zModalView._align_centerc                    s   t  || dS )NT)r   	on_motion)r   etypemer   r   r   r8     s    zModalView.on_motionc                    s*   | j |j | _| jr| jr&t | dS )z touch down event handler. T)Zcollide_pointpos_touch_started_insideauto_dismissr   on_touch_downr   touchr   r   r   r>     s    zModalView.on_touch_downc                    s   | j r| jrt | dS )z touch moved event handler. T)r=   r<   r   on_touch_mover?   r   r   r   rA     s    zModalView.on_touch_movec                    s0   | j r| jdkr|   nt | d| _dS )z touch up event handler. FNT)r=   r<   r7   r   on_touch_upr?   r   r   r   rB     s
    
zModalView.on_touch_upc                 C   s   |dkr| j r|   dS )z animation progress callback. r   N)r+   r6   )r   Z	_instancevaluer   r   r   on__anim_alpha  s    zModalView.on__anim_alphac                 C   s:   | j s
d S | j|  | jj| j| jd d| _ d | _d S )Nr   F)r+   r,   Zremove_widgetZunbindr/   r0   r'   r   r   r   r6   "  s    zModalView._real_remove_widgetc                 C   s   dS )z! default pre-open event handler. Nr   r'   r   r   r   r   ,  s    zModalView.on_pre_openc                 C   s   dS )z default open event handler. Nr   r'   r   r   r   r   /  s    zModalView.on_openc                 C   s   dS )z$ default pre-dismiss event handler. Nr   r'   r   r   r   r   2  s    zModalView.on_pre_dismissc                 C   s   dS )z  default dismiss event handler. Nr   r'   r   r   r   r   5  s    zModalView.on_dismissc                 G   s   |dkr| j r|   dS d S )N   T)r=   r7   )r   r,   keyr&   r   r   r   r0   8  s    zModalView._handle_keyboard)&__name__
__module____qualname____doc__r   r=   r   Z	attach_tor	   Zbackground_colorr   Z
backgroundr   ZborderZoverlay_colorr   r#   r2   r,   r+   r<   Z
__events__r   r4   r7   r/   r8   r>   rA   rB   rD   r6   r   r   r   r   r0   __classcell__r   r   r   r   r   V   s<   	

r   __main__)runTouchApp)Buttonr   )Label)
GridLayoutr   )colszThis is a hello world)text)NN)   rS   )Z	size_hintr       	   z	click me )Z
on_releaseN)"rJ   __all__Zkivy.animationr   Zkivy.propertiesr   r   r   r   r   r	   Zkivy.uix.anchorlayoutr
   r   rG   Z	kivy.baserM   Zkivy.uix.buttonrN   r*   r   Zkivy.uix.labelrO   Zkivy.uix.gridlayoutrP   contentr-   viewZlayoutrangexZbtnr.   r4   r   r   r   r   <module>   s0   L  i




