a
    ay$                     @   s   d Z ddlmZmZmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZmZ ddiZd	d
 Zdd Zdd ZdddZdd Zdd Zdd ZG dd dejZdS )z
qtawesome
=========

Font-Awesome and other iconic fonts for PyQt / PySide applications.

.. currentmodule:: qtawesome

.. autosummary::
   :toctree: _generate

   icon
   load_font
   charmap
   font
   set_defaults
    )QtCore	QtWidgetsQtGui   )__version__version_info)PulseSpin)
IconicFontset_global_defaultsiconicNc                 C   s*   | j  D ]}tj|}|s
 dS q
dS )zValidate instance's font ids are loaded to QFontDatabase.

    It is possible that QFontDatabase was reset or QApplication was recreated
    in both cases it is possible that font is not available.
    FT)Zfontidsvaluesr   ZQFontDatabaseZapplicationFontFamilies)instZfont_idZfont_families r   1lib/python3.9/site-packages/qtawesome/__init__.pyhas_valid_font_ids   s    r   c                   C   sJ   t d dur tt d s dt d< t d du rBtddddddt d< t d S )	z
    Return the singleton instance of IconicFont.

    Functions ``icon``, ``load_font``, ``charmap``, ``font`` and
    ``set_defaults`` all rebind to methods of the singleton instance of IconicFont.
    r   N)fazfontawesome4.7-webfont.ttfz#fontawesome4.7-webfont-charmap.json)Zfa5z fontawesome5-regular-webfont.ttfz)fontawesome5-regular-webfont-charmap.json)Zfa5szfontawesome5-solid-webfont.ttfz'fontawesome5-solid-webfont-charmap.json)Zfa5bzfontawesome5-brands-webfont.ttfz(fontawesome5-brands-webfont-charmap.json)Zeizelusiveicons-webfont.ttfz!elusiveicons-webfont-charmap.json)Zmdizmaterialdesignicons-webfont.ttfz(materialdesignicons-webfont-charmap.json)	_resourcer   r
   r   r   r   r   	_instance/   s    

r   c                  O   s   t  j| i |S )a  
    Return a QIcon object corresponding to the provided icon name(s).

    This function is the main interface of qtawesome. 

    It can be used to create a QIcon instance from a single glyph 
    or from a list of glyphs that are displayed on the top of each other.
    Such icon stacks are generally used to combine multiple glyphs to make
    more complex icons.

    Glyph names are specified by strings, of the form ``prefix.name``.
    The ``prefix`` corresponds to the font to be used and ``name`` is the
    name of the icon.

     - The prefix corresponding to Font-Awesome 4.x is 'fa'
     - The prefix corresponding to Font-Awesome 5.x (regular) is 'fa5'
     - The prefix corresponding to Font-Awesome 5.x (solid) is 'fa5s'
     - The prefix corresponding to Font-Awesome 5.x (brands) is 'fa5b'
     - The prefix corresponding to Elusive-Icons is 'ei'
     - The prefix corresponding to Material-Design-Icons is 'mdi'

    When requesting a single glyph, options (such as color or positional offsets)
    can be passed as keyword arguments::

        import qtawesome as qta

        music_icon = qta.icon(
            'fa5s.music',
            color='blue',
            color_active='orange')

    When requesting multiple glyphs, the `options` keyword argument contains
    the list of option dictionaries to be used for each glyph::

        camera_ban = qta.icon('fa5s.camera', 'fa5s.ban', options=[{
                'scale_factor': 0.5,
                'active': 'fa5s.balance-scale'
            }, {
                'color': 'red',
                'opacity': 0.7
            }])

    Qt's ``QIcon`` object has four modes

        - ``Normal``: The user is not interacting with the icon, but the
          functionality represented by the icon is available.
        - ``Disabled``: The functionality corresponding to the icon is not
          available.
        - ``Active``: The functionality corresponding to the icon is available.
          The user is interacting with the icon, for example, moving the mouse
          over it or clicking it.
        - ``Selected``: The item represented by the icon is selected.
 
    The glyph for the Normal mode is the one specified with the main positional
    argument.

     - ``color``: icon color in the ``Normal`` mode.

    The following four options will apply to the icon regardless of the mode.

     - ``offset``: tuple (x, y) corresponding to the horizontal and vertical
       offsets for the glyph, specified as a proportion of the icon size.
     - ``animation``: animation object for the icon.
     - ``scale_factor``: multiplicative scale factor to be used for the glyph. 

    The following options apply to the different modes of the icon

     - ``active``: name of the glyph to be used when the icon is ``Active``.
     - ``color_active``: the corresponding icon color.

     - ``disabled``: name of the glyph to be used when the icon is ``Disabled``.
     - ``color_disabled``: the corresponding icon color.

     - ``selected``: name of the glyph to be used when the icon is ``Selected``.
     - ``color_selected``: the corresponding icon color.

    Default values for these options can be specified via the function
    ``set_defaults``. If unspecified, the default defaults are::

        {
            'opacity': 1.0,
            'scale_factor': 1.0
            'color': QColor(50, 50, 50),
            'color_disabled': QColor(150, 150, 150),
        }

    If no default value is provided for ``active``, ``disabled`` or ``selected``
    the glyph specified for the ``Normal`` mode will be used.

    )r   icon)nameskwargsr   r   r   r   R   s    [r   c                 C   s   t  | |||S )ah  
    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
        Character map filename
    directory: str or None, optional
        Directory for font and charmap files

    Example
    -------
    The spyder ide uses qtawesome and uses a custom font for spyder-specific
    icons::

        qta.load_font('spyder', 'spyder.ttf', 'spyder-charmap.json')

    )r   	load_font)prefixZttf_filenameZcharmap_filenameZ	directoryr   r   r   r      s    r   c                 C   s   |  d\}}t j| | S )z
    Return the character map used for a given font.

    Returns
    -------
    return_value: dict
        The dictionary mapping the icon names to the corresponding unicode character.

    .)splitr   charmap)Zprefixed_namer   namer   r   r   r      s    
r   c                 C   s   t  | |S )a  
    Return the font corresponding to the specified prefix.

    This can be used to render text using the iconic font directly::

        import qtawesome as qta
        from qtpy import QtWidgets

        label = QtWidgets.QLabel(unichr(0xf19c) + ' ' + 'Label')
        label.setFont(qta.font('fa', 16))

    Parameters
    ----------
    prefix: str
        prefix string of the loaded font
    size: int
        size for the font

    )r   font)r   sizer   r   r   r      s    r   c                  K   s   t f i | S )z
    Set default options for icons.

    The valid keyword arguments are:

    'active', 'animation', 'color', 'color_active', 'color_disabled',
    'color_selected', 'disabled', 'offset', 'scale_factor', 'selected'.

    )r   )r   r   r   r   set_defaults   s    
r    c                       s<   e Zd ZdZ fddZdd Zdd Z fdd	Z  ZS )

IconWidgetaN  
    IconWidget gives the ability to display an icon as a widget

    if supports the same arguments as icon()
    for example
    music_icon = qta.IconWidget('fa5s.music',
                                color='blue',
                                color_active='orange')

    it also have setIcon() and setIconSize() functions
    c                    s@   t  j|dd d | _tdd| _| t|i | d S )Nparent)r"      )	super__init__get_iconr   ZQSize_sizesetIconr   )selfr   r   	__class__r   r   r%     s    zIconWidget.__init__c                 C   s   || _ | || j dS )z
        set a new icon()

        Parameters
        ----------
        _icon: qtawesome.icon
            icon to set
        N)r'   	setPixmappixmapr(   )r*   r'   r   r   r   r)     s    	zIconWidget.setIconc                 C   s
   || _ dS )z~
        set icon size

        Parameters
        ----------
        size: QtCore.QSize
            size of the icon
        N)r(   )r*   r   r   r   r   setIconSize  s    	zIconWidget.setIconSizec                    s,   | j r| | j | j t j|i |S )N)r'   r-   r.   r(   r$   update)r*   argsr   r+   r   r   r0   (  s    zIconWidget.update)	__name__
__module____qualname____doc__r%   r)   r/   r0   __classcell__r   r   r+   r   r!      s
   r!   )N)r5   Zqtpyr   r   r   Z_versionr   r   Z	animationr   r	   Ziconic_fontr
   r   r   r   r   r   r   r   r   r    ZQLabelr!   r   r   r   r   <module>   s   #^
