a
    §ˆcI  ã                   @   sd  d Z ddlmZ ejjdejjdejdejdejjdej	dejj
dejd	iZejjejejejejejjejjej	ej	ejj
ejj
ejejd
œZejjejjejjejjejjejjejjejjejjddœ
Zejjdejjdejjdejjdejjdejjdejjdejjdejjdddi
ZejjejjejjdœZdd„ e ¡ D ƒZ dd„ Z!dd„ Z"dd„ Z#d S )!z¹
Font conversion utilities

This module provides facilities for converting between pyface Font objects
and Qt QFont objects, trying to keep as much similarity as possible between
them.
é    )ÚQFontÚdefaultÚfantasyÚserifÚcursiveú
sans-serifÚ	monospaceÚ
typewriter)r   r   Z
decorativer   Zromanr   Úscriptr   Zswissr   Zmodernr	   Zteletypeéc   )
éd   éÈ   i,  i�  iô  iX  i¼  i   i„  iè  Zthinzextra-lightÚlightÚnormalZmediumz	demi-boldZboldz
extra-boldZblackzextra-heavy)r   ZobliqueZitalicc                 C   s   i | ]\}}||“qS © r   )Ú.0ÚkeyÚvaluer   r   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/ui/qt4/font.pyÚ
<dictcomp>N   ó    r   c                 C   s  t ƒ }g }d}| jD ]$}|tvr,| |¡ q|du r|}q|rTt|dƒrT| |¡ n|rf| |d ¡ |dur|| t| ¡ | | j	¡ | 
t| j ¡ | t| jƒ¡ | t| j ¡ | d| jv ¡ | d| jv ¡ | d| jv ¡ d| jv �r| t jj¡ |S )zÖ Convert a Pyface font to a Qfont.

    Parameters
    ----------
    font : pyface.font.Font
        The Pyface font to convert.

    Returns
    -------
    qt_font : QFont
        The best matching Qt font.
    NÚsetFamiliesr   Ú	underlineÚstrikethroughÚoverlineú
small-caps)r   ÚfamilyÚgeneric_family_to_qt_familyÚappendÚhasattrr   Z	setFamilyZsetStyleHintZsetPointSizeFÚsizeZ	setWeightÚweight_to_qt_weightZweight_Z
setStretchÚintÚstretchZsetStyleÚstyle_to_qt_styleÚstyleZsetUnderlineÚdecorationsZsetStrikeOutZsetOverlineÚvariantsZsetCapitalizationÚCapitalizationÚ	SmallCaps)ÚfontZqt_fontÚfamiliesZdefault_familyr   r   r   r   Úfont_to_toolkit_fontQ   s0    
r,   c                 C   sê   g }|   ¡ r| |   ¡ ¡ t| dƒr2| |  ¡ ¡ | t|  ¡  ¡ |  ¡ }t|  	¡  }t
|  ¡ tƒ}|  ¡ }|dkrzd}tƒ }|  ¡ tjjkrš| d¡ tƒ }|  ¡ r²| d¡ |  ¡ rÄ| d¡ |  ¡ rÖ| d¡ |||||||dœS )	a   Convert a QFont to a dictionary of font properties.

    Parameters
    ----------
    toolkit_font : QFont
        The Qt QFont to convert.

    Returns
    -------
    properties : dict
        Font properties suitable for use in creating a Pyface Font.
    r+   r   g      Y@r   r   r   r   )r   r    Úweightr#   r%   r'   r&   )r   r   r   Úextendr+   Úqt_family_to_generic_familyZ	styleHintZ
pointSizeFÚqt_style_to_styler%   Úmap_to_nearestr-   Úqt_weight_to_weightr#   ÚsetZcapitalizationr   r(   r)   Úaddr   Z	strikeOutr   )Ztoolkit_fontr   r    r%   r-   r#   r'   r&   r   r   r   Útoolkit_font_to_properties   s<    




ùr5   c                 C   sJ   | |v r||  S d}d}|D ]$}t | | ƒ|k rt | | ƒ}|}q|| S )au   Given mapping with keys from 0 and 99, return closest value.

    Parameters
    ----------
    target : int
        The value to map.
    mapping : dict
        A dictionary with integer keys ranging from 0 to 99.

    Returns
    -------
    value : any
        The value corresponding to the nearest key.  In the case of a tie,
        the first value is returned.
    r   N)Úabs)ÚtargetÚmappingZdistanceZnearestr   r   r   r   r1   ²   s    r1   N)$Ú__doc__Zpyface.qt.QtGuir   Z	StyleHintZAnyStyleÚSystemZ
DecorativeZSerifZCursiveZ	SansSerifZ	MonospaceZ
TypeWriterr/   r   ZWeightZThinZ
ExtraLightZLightZNormalZMediumZDemiBoldZBoldZ	ExtraBoldZBlackr!   r2   ÚStyleZStyleNormalZStyleObliqueZStyleItalicr$   Úitemsr0   r,   r5   r1   r   r   r   r   Ú<module>   sl   øóööý.3