ó
–"‰]c           @  s”  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l m Z m	 Z	 m
 Z
 m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z d d l m Z e Z i d d	 6d
 d 6d d 6d d 6d d 6d d 6Z i e d d d ƒ d 6e d d d ƒ d 6d d 6d d 6Z d „  Z d d$ d „  ƒ  YZ d e f d „  ƒ  YZ  d  e f d! „  ƒ  YZ! d" e f d# „  ƒ  YZ" d S(%   sW  

Iconic Font
===========

A lightweight module handling iconic fonts.

It is designed to provide a simple way for creating QIcons from glyphs.

From a user's viewpoint, the main entry point is the ``IconicFont`` class which
contains methods for loading new iconic fonts with their character map and
methods returning instances of ``QIcon``.

iÿÿÿÿ(   t   print_functionN(   t   QObjectt   QPointt   QRectt   Qt(   t   QColort   QFontt   QFontDatabaset   QIcont   QIconEnginet   QPaintert   QPixmapt
   QTransform(   t   QApplication(   t   unichrt    b06871f281fee6b241d60582ae9369b9s   fontawesome4.7-webfont.ttft    6a745dc6a0871f350b0219f5a2678838s    fontawesome5-regular-webfont.ttft    acf50f59802f20d8b45220eaae532a1cs   fontawesome5-solid-webfont.ttft    ed2b8bf117160466ba6220a8f1da54a4s   fontawesome5-brands-webfont.ttft    207966b04c032d5b873fd595a211582es   elusiveicons-webfont.ttft    f558fb5cc12a31989a7e4048b4fba71as   materialdesignicons-webfont.ttfi2   t   colori–   t   color_disabledg      ð?t   opacityt   scale_factorc          K  sª   d d d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d g } xF |  D]> } | | k r‡ |  | t  | <qd d j | ƒ } t | ƒ ‚ qd Wd S(    s?   Set global defaults for the options passed to the icon painter.t   activet   selectedt   disabledt   ont   offt	   on_activet   on_selectedt   on_disabledt
   off_activet   off_selectedt   off_disabledR   t   color_ont	   color_offt   color_activet   color_selectedR   t   color_on_selectedt   color_on_activet   color_on_disabledt   color_off_selectedt   color_off_activet   color_off_disabledt	   animationt   offsetR   t   rotatedt   hflipt   vflips   Invalid option '{0}'N(   t   _default_optionst   formatt   KeyError(   t   kwargst   valid_optionst   kwt   error(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyt   set_global_defaults5   s    						t   CharIconPainterc           B  s    e  Z d  Z d „  Z d „  Z RS(   s   Char icon painter.c         C  s1   x* | D]" } |  j  | | | | | | ƒ q Wd S(   s   Main paint method.N(   t   _paint_icon(   t   selft   iconict   paintert   rectt   modet   statet   optionst   opt(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyt   paintO   s    c         C  s¬  | j  ƒ  | d } | d } i i | d | d f t j 6| d | d f t j 6| d | d f t j 6| d	 | d
 f t j 6t j 6i | d | d f t j 6| d | d f t j 6| d | d f t j 6| d | d f t j 6t j 6}	 |	 | | \ } } | j t	 | ƒ ƒ t
 d | j ƒ  | d ƒ }
 | d } | j d ƒ } | d! k	 rx| j |  | | ƒ n  | j | j | |
 ƒ ƒ d | k rìt | ƒ } | j t
 | d d | j ƒ  ƒ t
 | d d | j ƒ  ƒ ƒ n  d | k rv| d t k rv| j ƒ  d } | j ƒ  d } | j | | ƒ t ƒ  } | j d d ƒ | j | t ƒ | j | | ƒ n  d | k r | d t k r | j ƒ  d } | j ƒ  d } | j | | ƒ t ƒ  } | j d d ƒ | j | t ƒ | j | | ƒ n  d | k rb| j ƒ  d } | j ƒ  d } | j | | ƒ | j | d ƒ | j | | ƒ n  | j | j d d  ƒ ƒ | j | t t j t j Bƒ | ƒ | j ƒ  d! S("   s   Paint a single icon.R   t   charR$   R   R*   R    R)   R   R(   R   R%   R   R-   R#   R,   R!   R+   R"   g      ì?R   t   prefixR.   R/   i    i   R2   g      à?iÿÿÿÿR1   R0   R   g      ð?N(    t   saveR   t   Normalt   Disabledt   Activet   Selectedt   Ont   Offt   setPenR   t   roundt   heightt   gett   Nonet   setupt   setFontt   fontR   t	   translatet   widtht   TrueR   t   scalet   setTransformt   rotatet
   setOpacityt   drawTextt   intR   t   AlignCentert   AlignVCentert   restore(   R=   R>   R?   R@   RA   RB   RC   R   RF   t   color_optionst	   draw_sizeRG   R.   t   x_centert   y_centert	   transfrom(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyR<   T   sr    



!"		#(   t   __name__t
   __module__t   __doc__RE   R<   (    (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyR;   K   s   	t	   FontErrorc           B  s   e  Z d  Z RS(   s   Exception for font errors.(   Rh   Ri   Rj   (    (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRk   ¦   s   t   CharIconEnginec           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s<   Specialization of QIconEngine used to draw font-based icons.c         C  s2   t  t |  ƒ j ƒ  | |  _ | |  _ | |  _ d  S(   N(   t   superRl   t   __init__R>   R?   RC   (   R=   R>   R?   RC   (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRn   ®   s    		c         C  s)   |  j  j |  j | | | | |  j ƒ d  S(   N(   R?   RE   R>   RC   (   R=   R?   R@   RA   RB   (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRE   ´   s    	c         C  sN   t  | ƒ } | j t j ƒ |  j t | ƒ t t d d ƒ | ƒ | | ƒ | S(   Ni    (   R   t   fillR   t   transparentRE   R
   R   R   (   R=   t   sizeRA   RB   t   pm(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyt   pixmap¸   s    .(   Rh   Ri   Rj   Rn   RE   Rs   (    (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRl   ª   s   		t
   IconicFontc           B  sb   e  Z d  Z d „  Z d
 d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(   s%   Main class for managing iconic fonts.c         G  se   t  t |  ƒ j ƒ  t ƒ  |  _ i  |  _ i  |  _ i  |  _ i  |  _ x | D] } |  j	 | Œ  qJ Wd S(   sÌ  IconicFont Constructor.

        Parameters
        ----------
        ``*args``: tuples
            Each positional argument is a tuple of 3 or 4 values:
            - The prefix string to be used when accessing a given font set,
            - The ttf font filename,
            - The json charmap filename,
            - Optionally, the directory containing these files. When not
              provided, the files will be looked for in ``./fonts/``.
        N(
   Rm   Rt   Rn   R;   R?   t   painterst   fontnamet   charmapt
   icon_cachet	   load_font(   R=   t   argst   fargs(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRn   Ã   s    				c         C  sÁ  d „  } | d k rE t j j t j j t j j t ƒ ƒ d ƒ } n  t j ƒ  d k	 r½t	 j
 t j j | | ƒ ƒ } t	 j | ƒ } | rž | d |  j | <n$ t d j t j j | | ƒ ƒ ƒ ‚ t t j j | | ƒ d ƒ # } t j | d | ƒ|  j | <Wd QXt s½t j | d ƒ }	 |	 d k	 rºt j ƒ  }
 t t j j | | ƒ d ƒ   } | j ƒ  } |
 j | ƒ Wd QX|
 j ƒ  } | |	 k r·t d	 j t j j | | ƒ ƒ ƒ ‚ q·qºq½n  d S(
   sÔ  Loads a font file and the associated charmap.

        If ``directory`` is None, the files will be looked for in ``./fonts/``.

        Parameters
        ----------
        prefix: str
            Prefix string to be used when accessing a given font set
        ttf_filename: str
            Ttf font filename
        charmap_filename: str
            Charmap filename
        directory: str or None, optional
            Directory for font and charmap files
        c         S  s8   i  } x+ |  D]# } t  t |  | d ƒ ƒ | | <q W| S(   Ni   (   R   R_   (   t   objt   resultt   key(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyt   hookê   s    !t   fontsi    uÈ   Font at '{0}' appears to be empty. If you are on Windows 10, please read https://support.microsoft.com/en-us/kb/3053676 to know how to prevent Windows from blocking the fonts that come with QtAwesome.t   rt   object_hookNt   rbu   Font is corrupt at: '{0}'(   RS   t   ost   patht   joint   dirnamet   realpatht   __file__R   t   instanceR   t   addApplicationFontt   applicationFontFamiliesRv   Rk   R4   t   opent   jsont   loadRw   t   SYSTEM_FONTSt
   MD5_HASHESRR   t   hashlibt   md5t   readt   updatet	   hexdigest(   R=   RG   t   ttf_filenamet   charmap_filenamet	   directoryR   t   id_t   loadedFontFamiliest   codest   ttf_hasht   hashert   ft   contentt   ttf_calculated_hash_code(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRy   Ù   s4    		'	!"	c         O  s(  d j  | | ƒ } | |  j k r| j d i  g t | ƒ ƒ } | } t | ƒ t | ƒ k r‚ d j  t | ƒ ƒ } t | ƒ ‚ n  t j ƒ  d k	 rg  } xD t t | ƒ ƒ D]0 } | | }	 | j	 |  j
 |	 | | | ƒ ƒ q­ W| }
 |  j |  j |
 ƒ |  j | <qt j d ƒ t ƒ  Sn  |  j | S(   s>   Return a QIcon object corresponding to the provided icon name.s   {}{}RC   s$   "options" must be a list of size {0}s9   You need to have a running QApplication to use QtAwesome!N(   R4   Rx   t   popt   lent	   ExceptionR   RŠ   RS   t   ranget   appendt   _parse_optionst   _icon_by_painterR?   t   warningst   warnR   (   R=   t   namesR6   t	   cache_keyt   options_listt   general_optionsR9   t   parsed_optionst   it   specific_optionst   api_options(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyt   icon  s&    

c         C  s¸  t  t |  } | j | ƒ d d d d d d d d d	 d
 d d g } | j d | ƒ } | j d | ƒ } | j d | ƒ } | j d | ƒ }	 | j d |	 ƒ }
 | j d | ƒ } | j d |	 ƒ } | j d |
 ƒ } | j d	 | ƒ } | j d
 |	 ƒ } | j d |
 ƒ } | j d | ƒ } i | d 6| d 6| d 6|	 d 6|
 d 6| d 6| d 6| d 6| d	 6| d
 6| d 6| d 6} g  | D] } | j | | ƒ ^ q} |  j | ƒ \ } } | j t  t | | f Œ  ƒ ƒ | j i | d 6ƒ | j d ƒ } | j d | ƒ | j d | d ƒ | j d | d ƒ | j d | d ƒ | j d | d ƒ | j d | d ƒ | j d | ƒ | j d | d ƒ | j d | d ƒ | j d | d ƒ | S(   NRF   R   R   R   R   R   R   R   R    R!   R"   R#   RG   R   R$   R&   R'   R)   R(   R*   R   R%   R,   R+   R-   (   t   dictR3   R•   RR   t   _get_prefix_charst   zipt
   setdefault(   R=   R±   R®   t   nameRC   t   icon_kwRF   R   R   R   R   R   R   R   R    R!   R"   R#   t	   icon_dictR8   R«   RG   t   charsR   (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyR§   2  sZ    

%c         C  sÊ   g  } x· | D]¯ } d | k r° | j  d ƒ \ } } | |  j k r’ | |  j | k rq | j |  j | | ƒ q­ d j | | ƒ } t | ƒ ‚ q¼ d j | ƒ } t | ƒ ‚ q t d ƒ ‚ q W| | f S(   Nt   .s%   Invalid icon name "{0}" in font "{1}"s   Invalid font prefix "{0}"s   Invalid icon name(   t   splitRw   R¦   R4   R¤   (   R=   R«   R»   R¸   RG   t   nR9   (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRµ   j  s    c         C  sJ   t  |  j | ƒ } | j t | ƒ ƒ | d d k rF | j d ƒ n  | S(   s:   Return a QFont corresponding to the given prefix and size.iÿÿÿÿt   st   Solid(   R   Rv   t   setPixelSizeRP   t   setStyleName(   R=   RG   Rq   RV   (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRV   ~  s
    c         C  s   | |  j  | <d S(   s»  Associate a user-provided CharIconPainter to an icon name.

        The custom icon can later be addressed by calling
        icon('custom.NAME') where NAME is the provided name for that icon.

        Parameters
        ----------
        name: str
            name of the custom icon
        painter: CharIconPainter
            The icon painter, implementing
            ``paint(self, iconic, painter, rect, mode, state, options)``
        N(   Ru   (   R=   R¸   R?   (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyt   set_custom_icon†  s    c         K  sF   t  t |  } | |  j k r; |  j | } |  j | | ƒ St ƒ  Sd S(   s7   Return the custom icon corresponding to the given name.N(   R´   R3   Ru   R¨   R   (   R=   R¸   R6   RC   R?   (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyt   _custom_icon–  s
    c         C  s   t  |  | | ƒ } t | ƒ S(   s3   Return the icon corresponding to the given painter.(   Rl   R   (   R=   R?   RC   t   engine(    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyR¨   Ÿ  s    N(   Rh   Ri   Rj   Rn   RS   Ry   R³   R§   Rµ   RV   RÃ   RÄ   R¨   (    (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyRt   ¿   s   	<		8					(    (#   Rj   t
   __future__R    RŽ   R„   R’   R©   t   qtpy.QtCoreR   R   R   R   t
   qtpy.QtGuiR   R   R   R   R	   R
   R   R   t   qtpy.QtWidgetsR   t   sixR   t   FalseR   R‘   R3   R:   R;   R¤   Rk   Rl   Rt   (    (    (    s4   lib/python2.7/site-packages/qtawesome/iconic_font.pyt   <module>   s6   ":

	[