U
    PeB                     @   s   d Z 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
mZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZ eedkreded   ed eed Zeed ZG dd deZG dd deZedkre   dS )aa  
KViewer
=======

KViewer, for KV-Viewer, is a simple tool allowing you to dynamically display
a KV file, taking its changes into account (thanks to watchdog). The
idea is to facilitate design using the KV language. It's somewhat related to
the KivyCatalog demo, except it uses an on-disc file, allowing the user to use
any editor.

You can use the script as follows::

    python kviewer.py ./test.kv

This will display the test.kv and automatically update the display when the
file changes.

.. note: This scripts uses watchdog to listen for file changes. To install
   watchdog::

   pip install watchdog

    )argv)Builder)App)Window)Clock
mainthread)Label)Observer)FileSystemEventHandler)dirnamebasenamejoin   zusage: %s filename.kv   c                       s$   e Zd Z fddZdd Z  ZS )	KvHandlerc                    s"   t t| jf | || _|| _d S N)superr   __init__callbacktarget)selfr   r   kwargs	__class__ 6/tmp/pip-unpacked-wheel-xzebddm3/kivy/tools/kviewer.pyr   0   s    zKvHandler.__init__c                 C   s   t |j| jkr|   d S r   )r   Zsrc_pathr   r   )r   eventr   r   r   on_any_event5   s    zKvHandler.on_any_event)__name__
__module____qualname__r   r   __classcell__r   r   r   r   r   /   s   r   c                       s(   e Zd Z fddZedd Z  ZS )KvViewerAppc                    s>   t  }|t| jtt |  t| jd t	t
|  S )Nr   )r	   scheduler   updateTARGETPATHstartr   Zschedule_oncer   r"   build)r   or   r   r   r(   ;   s
    zKvViewerApp.buildc              
   G   s   t ttt tjd d  D ]}t| qztt 	ttt W nH t
k
r } z*ttt|dd rr|jnt|d W 5 d }~X Y nX d S )Nmessage)text)r   Zunload_filer   r&   r%   r   childrenZremove_widgetZ
add_widgetZ	load_file	Exceptionr   getattrr*   str)r   argswer   r   r   r$   B   s    zKvViewerApp.update)r   r   r    r(   r   r$   r!   r   r   r   r   r"   :   s   r"   __main__N)__doc__sysr   Z	kivy.langr   Zkivy.appr   Zkivy.core.windowr   Z
kivy.clockr   r   Zkivy.uix.labelr   Zwatchdog.observersr	   Zwatchdog.eventsr
   os.pathr   r   r   lenprintexitr&   r%   r   r"   r   runr   r   r   r   <module>   s$   