
VG;                 @   sh  d  d l  Z  d  d l Z d  d l Z e j j Z d d l m Z m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z e j Z e j  Z  e j! Z! e j" Z" e j# Z# e j$ Z$ e j% Z% e j& Z& e  j' d d  f k r6e( Z) e* Z+ n e, Z) e- Z+ Gd d   d e.  Z/ d d   Z0 d S)	    N   )	TYPE_NONETYPE_INTERFACE	TYPE_CHAR
TYPE_UCHARTYPE_BOOLEANTYPE_INT	TYPE_UINT	TYPE_LONG
TYPE_ULONG
TYPE_INT64TYPE_UINT64	TYPE_ENUM
TYPE_FLAGS
TYPE_FLOATTYPE_DOUBLETYPE_STRINGTYPE_POINTER
TYPE_BOXED
TYPE_PARAMTYPE_OBJECTTYPE_PYOBJECT
TYPE_GTYPE	TYPE_STRVTYPE_VARIANT   c               @   s  e  Z d  Z d Z e e e e e e	 e
 e e e e e i Z e d e d e d e e e e e e e e e d/ i Z e e e e e d1 e d3 e e e e e e e e i Z e d e d e d e d e d e d e d e d e d i	 Z  Gd	 d
   d
 e!  Z" d d d d d d e# j$ d d d d 	 Z% d d   Z& d d   Z' d d   Z( d d   Z) d d   Z* d d   Z+ d d   Z, d d   Z- d d   Z. d  d!   Z/ d" d#   Z0 d$ d%   Z1 d& d'   Z2 d( d)   Z3 d* d+   Z4 d, d-   Z5 d S)4Propertya  Creates a new Property which when used in conjunction with
    GObject subclass will create a Python property accessor for the
    GObject ParamSpec.

    :param callable getter:
        getter to get the value of the property
    :param callable setter:
        setter to set the value of the property
    :param type type:
        type of property
    :param default:
        default value, must match the property type.
    :param str nick:
        short description
    :param str blurb:
        long description
    :param GObject.ParamFlags flags:
        parameter flags
    :keyword minimum:
        minimum allowed value (int, float, long only)
    :keyword maximum:
        maximum allowed value (int, float, long only)

    .. code-block:: python

         class MyObject(GObject.Object):
             prop = GObject.Property(type=str)

         obj = MyObject()
         obj.prop = 'value'

         obj.prop  # now is 'value'

    The API is similar to the builtin :py:func:`property`:

    .. code-block:: python

        class AnotherObject(GObject.Object):
            value = 0

            @GObject.Property
            def prop(self):
                'Read only property.'
                return 1

            @GObject.Property(type=int)
            def propInt(self):
                'Read-write integer property.'
                return self.value

            @propInt.setter
            def propInt(self, value):
                self.value = value
    r      ?   r   @    g        c               @   s   e  Z d  Z d d   Z d S)zProperty.__metaclass__c             C   s   d S)Nz<class 'GObject.Property'> )selfr!   r!   4/usr/lib/python3/dist-packages/gi/_propertyhelper.py__repr__   s    zProperty.__metaclass__.__repr__N)__name__
__module____qualname__r$   r!   r!   r!   r#   __metaclass__   s   r(   Nc
       
      C   s  d  |  _  | d  k r t } |  j |  |  _ |  j |  |  _ |  j   t | t  sd t	 d   | |  _
 t | t  s t	 d   | |  _ | |  _ | |  _ | r | r |  j } n9 | r | r |  j } n  | r | r |  j } |  j } |  j |  | |  _ | d  k	 rK| |  j   k  rWt	 d |  j |  j   f   n |  j   } | |  _ |	 d  k	 r|	 |  j   k rt	 d |  j |  j   f   n |  j   }	 |	 |  _ d  |  _ d  S)Nznick must be a stringzblurb must be a stringz+Minimum for type %s cannot be lower than %dz,Maximum for type %s cannot be higher than %d)nameobject_type_from_pythontype_get_defaultdefault_check_default
isinstance_basestring	TypeErrornickblurb__doc__flags_readonly_setter_writeonly_getter_default_getter_default_settergetterfset_get_minimumminimum_get_maximummaximum_exc)
r"   r;   setterr,   r.   r3   r4   r6   r>   r@   r!   r!   r#   __init__   sL    	
									zProperty.__init__c             C   s#   d |  j  p d t j |  j  f S)Nz<GObject Property %s (%s)>z(uninitialized))r)   _gobjectZ	type_namer,   )r"   r!   r!   r#   r$      s    zProperty.__repr__c             C   sv   | d  k r |  Sd  |  _  y |  j |  } Wn" t k
 rP t j   d  } Yn X|  j  rr |  j  } d  |  _  |  | S)N)rA   fget	Exception	traceback	print_exc)r"   instanceklassvalueexcr!   r!   r#   __get__   s    	
			zProperty.__get__c             C   sS   | d  k r t   d  |  _ | j |  j |  |  j rO |  j } d  |  _ |  d  S)N)r2   rA   Zset_propertyr)   )r"   rI   rK   rL   r!   r!   r#   __set__   s    				zProperty.__set__c             C   s   |  j  |  S)z;Allows application of the getter along with init arguments.)r;   )r"   rE   r!   r!   r#   __call__   s    zProperty.__call__c             C   s.   | j  r! | j  |  _ | j  |  _  | |  _ |  S)z8Set the getter function to fget. For use as a decorator.)r5   r4   rE   )r"   rE   r!   r!   r#   r;      s
    		zProperty.getterc             C   s%   | |  _  |  j s! |  j j |  _ |  S)z8Set the setter function to fset. For use as a decorator.)r<   r)   rE   r%   )r"   r<   r!   r!   r#   rB   	  s    		zProperty.setterc             C   s   | |  j  k r |  j  | St | t  r] t | t j t j t j t j t j	 f  r] | j
 S| t t t t t t t t t t t t t t t t t t t t t t  f k r | St! d | f   d  S)NzUnsupported type: %r)"_type_from_pytype_lookupr0   r,   
issubclassrD   ZGObjectZGEnumZGFlagsZGBoxedZ
GInterface	__gtype__r   r   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   )r"   Ztype_r!   r!   r#   r+     s"    		zProperty._type_from_pythonc             C   s&   | d  k	 r | S|  j  j |  j d   S)N)_default_lookupgetr,   )r"   r.   r!   r!   r#   r-   '  s    zProperty._get_defaultc             C   s  |  j  } |  j } | t k r@ | d k r@ t d | f   n| t k rg | d  k	 rt d   n| t k r | d  k	 rt d   nqt j | t  r | d  k r t d   qt j | |  st d | | f   nt j | t	  r#t j | |  st d | | f   n t j | t
  r| d  k	 rt | t  sft d	 t |    x | D]4 } t  |  t t f k rmt d
 t |    qmWnW t j | t  r| d  k	 rt | d  st j | t  rt d | | f   d  S)NTFz%default must be True or False, not %rz)object types does not have default valuesz(GType types does not have default valuesz%enum properties needs a default valuez'enum value %s must be an instance of %rz(flags value %s must be an instance of %rzStrv value %s must be a listz'Strv value %s must contain only stringsrR   z*variant value %s must be an instance of %r)TF)r,   r.   r   r2   r   r   rD   Z	type_is_ar   r   r   r0   listreprstrbytesr   hasattr)r"   ptyper.   valr!   r!   r#   r/   ,  s>    		#zProperty._check_defaultc             C   s   |  j  j |  j d   S)N)_min_value_lookuprT   r,   )r"   r!   r!   r#   r=   M  s    zProperty._get_minimumc             C   s   |  j  j |  j d   S)N)_max_value_lookuprT   r,   )r"   r!   r!   r#   r?   P  s    zProperty._get_maximumc             C   s   t  | d |  j |  d  S)N_property_helper_)setattrr)   )r"   rI   rK   r!   r!   r#   r:   W  s    zProperty._default_setterc             C   s   t  | d |  j |  j  S)Nr^   )getattrr)   r.   )r"   rI   r!   r!   r#   r9   Z  s    zProperty._default_getterc             C   s)   t  d |  j t |  j f  |  _ d  S)Nz%s property of %s is read-only)r2   r)   r,   r%   rA   )r"   rI   rK   r!   r!   r#   r7   ]  s    zProperty._readonly_setterc             C   s)   t  d |  j t |  j f  |  _ d  S)Nz%s property of %s is write-only)r2   r)   r,   r%   rA   )r"   rI   r!   r!   r#   r8   a  s    zProperty._writeonly_getterc          	   C   s  |  j  } | t t t t t t t t f k rH |  j	 |  j
 |  j f } n | t k s | t k s | j t  s | j t  s | j t  r |  j f } nN | t t f k r f  } n3 | j t  s | j t  r f  } n t |   |  j  |  j |  j f | |  j f S)N)r,   r   r	   r
   r   r   r   r   r   r>   r@   r.   r   r   Zis_ar   r   r   r   r   r   r   NotImplementedErrorr3   r4   r6   )r"   rZ   argsr!   r!   r#   get_pspec_argsi  s    			zProperty.get_pspec_argsl            l         l            l    l            l    )6r%   r&   r'   r5   _longr
   intr   boolr   floatr   rW   r   r*   r   rP   r	   r   r   r   
G_MAXFLOATG_MAXDOUBLEG_MININT	G_MINLONGr   r\   	G_MAXUINT
G_MAXULONGG_MAXINT	G_MAXLONGr]   rS   r,   r(   rD   ZPARAM_READWRITErC   r$   rM   rN   rO   r;   rB   r+   r-   r/   r=   r?   r:   r9   r7   r8   rc   r!   r!   r!   r#   r   3   sh   66	
!r   c                sj    j  j d i   } g  } x   j  j   D] \ } } t | t  r+ | j sX | | _ | j | k r | | j | j   k r q+ t d | j   | j   | | j <| j |  q+ W| s d S|   _	 d   j  k s d   j  k r6xH | D]@ } | j
 | j k s| j | j k r t d   j f   q Wd d   } |   _   f d	 d
   } |   _ d S)z
    Scans the given class for instances of Property and merges them
    into the classes __gproperties__ dict if it exists or adds it if not.
    __gproperties__z0Property %s was already found in __gproperties__Ndo_get_propertydo_set_propertyzGObject subclass %r defines do_get/set_property and it also uses a property with a custom setter or getter. This is not allowedc             S   s%   | j  j d d  } t |  | d   S)N-_)r)   replacer`   )r"   pspecr)   r!   r!   r#   obj_get_property  s    z,install_properties.<locals>.obj_get_propertyc                sA   | j  j d d  } t   | d   } | r= | j |  |  d  S)Nrs   rt   )r)   ru   r`   r<   )r"   rv   rK   r)   prop)clsr!   r#   obj_set_property  s    z,install_properties.<locals>.obj_set_property)__dict__rT   itemsr0   r   r)   rc   
ValueErrorappendrp   rE   r9   r<   r:   r2   r%   rq   rr   )ry   ZgpropertiesZpropsr)   rx   rw   rz   r!   )ry   r#   install_properties|  s2    			$	r   )1sysrG   Zgi._giZgiZ_girD   Z
_constantsr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rh   ri   rj   rn   rl   rk   ro   rm   version_inforW   r1   re   rd   Z
basestringZlongr*   r   r   r!   r!   r!   r#   <module>   s(   									 J