U
    Pe                     @   sP  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 G dd deZG dd	 d	eZed
krLd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ddddZeedd ee edddeddZejejd eddZ e!dD ],Z"ee#e"dZ$e$jej%d e e$ qee  e%  e  dS ) a  
Popup
=====

.. versionadded:: 1.0.7

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

The :class:`Popup` widget is used to create modal popups. By default, the popup
will cover the whole "parent" window. When you are creating a popup, you
must at least set a :attr:`Popup.title` and :attr:`Popup.content`.

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


.. versionchanged:: 1.4.0
    The :class:`Popup` class now inherits from
    :class:`~kivy.uix.modalview.ModalView`. The :class:`Popup` offers a default
    layout with a title and a separation bar.

Examples
--------

Example of a simple 400x400 Hello world popup::

    popup = Popup(title='Test popup',
        content=Label(text='Hello world'),
        size_hint=(None, None), size=(400, 400))

By default, any click outside the popup will dismiss/close it. If you don't
want that, you can set
:attr:`~kivy.uix.modalview.ModalView.auto_dismiss` to False::

    popup = Popup(title='Test popup', content=Label(text='Hello world'),
                  auto_dismiss=False)
    popup.open()

To manually dismiss/close the popup, use
:attr:`~kivy.uix.modalview.ModalView.dismiss`::

    popup.dismiss()

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

    # create content and add to the popup
    content = Button(text='Close me!')
    popup = Popup(content=content, auto_dismiss=False)

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

    # open the popup
    popup.open()

Same thing in KV language only with :class:`Factory`:

.. code-block:: kv

    #:import Factory kivy.factory.Factory
    <MyPopup@Popup>:
        auto_dismiss: False
        Button:
            text: 'Close me!'
            on_release: root.dismiss()

    Button:
        text: 'Open popup'
        on_release: Factory.MyPopup().open()

.. note::

    Popup is a special widget. Don't try to add it as a child to any other
    widget. If you do, Popup will be handled like an ordinary widget and
    won't be created hidden in the background.

    .. code-block:: kv

        BoxLayout:
            MyPopup:  # bad!

Popup Events
------------

There are two events available: `on_open` which is raised when the popup is
opening, and `on_dismiss` which is raised when the popup is closed.
For `on_dismiss`, you can prevent the
popup from closing by explicitly returning True from your callback::

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

)PopupPopupException    )DEFAULT_FONT)	ModalView)StringPropertyObjectPropertyOptionPropertyNumericPropertyColorPropertyc                   @   s   e Zd ZdZdS )r   zrPopup exception, fired when multiple content widgets are added to the
    popup.

    .. versionadded:: 1.4.0
    N)__name__
__module____qualname____doc__ r   r   2/tmp/pip-unpacked-wheel-xzebddm3/kivy/uix/popup.pyr   p   s   r   c                       s   e Zd ZdZedZedZedddddgdZ	ee
Zed	Zed
d
d
d
gZeddddgZedZed	Z fddZdd Zdd Z fddZ  ZS )r   a  Popup class. See module documentation for more information.

    :Events:
        `on_open`:
            Fired when the Popup is opened.
        `on_dismiss`:
            Fired when the Popup is closed. If the callback returns True, the
            dismiss will be canceled.
    zNo titleZ14spleftcenterrightZjustify)optionsN   g?g?g?g      ?Z2dpc                    s8   | j r| jrtd|| _ntt| j|f|| d S )Nz)Popup can have only one widget as content)
_containercontentr   superr   
add_widget)selfZwidgetargskwargs	__class__r   r   r      s    zPopup.add_widgetc                 C   s    | j r| j   | j | d S N)r   clear_widgetsr   r   instancevaluer   r   r   
on_content   s    
zPopup.on_contentc                 C   s2   |d ks| j d krd S | j  | j| j  d S r   )r   r   r    r   r!   r   r   r   on__container   s    
zPopup.on__containerc                    s&   | j r| j|j rdS tt| |S )NT)disabledZcollide_pointposr   r   on_touch_down)r   touchr   r   r   r(      s    zPopup.on_touch_down)r   r   r   r   r   titler	   Z
title_sizer   Ztitle_alignr   Z
title_fontr   r   r
   Ztitle_colorZseparator_colorZseparator_heightr   r   r$   r%   r(   __classcell__r   r   r   r   r   x   s"   
	 


	r   __main__)runTouchApp)Button)Label)
GridLayout)Windowr   )colsZCancelN(   )textZsize_hint_yheightzThis is a hello world)r4   z
Test popup)NN)   r6   T)r*   Z	size_hintsizer   r&   )Z
on_release   	   )&r   __all__Zkivy.core.textr   Zkivy.uix.modalviewr   Zkivy.propertiesr   r   r   r	   r
   	Exceptionr   r   r   Z	kivy.baser-   Zkivy.uix.buttonr.   Zkivy.uix.labelr/   Zkivy.uix.gridlayoutr0   Zkivy.core.windowr1   r   Zcontent_cancelr   ZpopupbindZdismissZlayoutrangexstrZbtnopenr   r   r   r   <module>   s>   gw


  

