3
8ßL]¥  ã               @   sà   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	Z	ej
jej
jej
jej
jej
jej
jdœZej
jej
jdœZej
jej
jdœZd	d
dgZdd„ Zdd„ ZG dd„ dej
ƒZG dd„ deƒZdd„ Zeeƒ eƒ ed�ZdS )z) Trait definition for a PyQt-based font.
é    )Úabsolute_import)ÚQtGui)ÚTraitÚTraitHandlerÚ
TraitErrorN)ÚdefaultZ
decorativeZromanÚscriptZswissZmodern)ZslantZitalic)ÚlightZboldÚptZpointÚfamilyc             C   sp   t jjdt jjdij| jƒ dƒ}t jjdt jjdij| jƒ dƒ}d}| j	ƒ rPd}d| j
ƒ tj| jƒ ƒ|||f S )z; Converts a QFont into a string description of itself.
    z Lightz BoldÚ z Slantz Italicz
 underlinez%s point %s%s%s%s)r   ÚQFontÚLightÚBoldÚgetÚweightÚStyleObliqueÚStyleItalicÚstyleÚ	underlineÚ	pointSizeÚsixÚ	text_typer   )Úfontr   r   r   © r   ú=/tmp/pip-install-5sebvq2j/traitsui/traitsui/qt4/font_trait.pyÚfont_to_str=   s    r   c          
   C   sL  t | tjƒrt| ƒS d}d}tjj}tjj}d}g }x¨| jƒ D ]œ}|jƒ }|tkrrtjƒ }	|	j	t| ƒ |	j
ƒ }q>|tkr„t| }q>|tkr–t| }q>|dkr¤d}q>|tkr>|dkrÐyt|ƒ}w>W n   Y nX |j|ƒ q>W |rìdj|ƒ}|rút|ƒ}
ntƒ }
|
j|ƒ |
j|ƒ |
j|ƒ |dk�r>|
jtjjƒ jƒ ƒ n
|
j|ƒ |
S )z: Create a TraitFont object from a string description.
    Nr   Fr   Tú )Ú
isinstancer   r   Ú
TraitsFontZStyleNormalZNormalÚsplitÚlowerÚfont_familiesZsetStyleHintZdefaultFamilyÚfont_stylesÚfont_weightsÚ
font_noiseÚintÚappendÚjoinZsetStyleZ	setWeightZsetUnderlineZsetPointSizeZQApplicationr   r   )ÚvalueZ
point_sizer   r   r   r   ZfacenameÚwordZlwordÚfZfntr   r   r   Úcreate_traitsfontO   sP    









r,   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )r   z A Traits-specific QFont.
    c             C   s   t t| ƒffS )z= Returns the pickleable form of a TraitsFont object.
        )r,   r   )ÚselfÚprotocolr   r   r   Ú__reduce_ex__�   s    zTraitsFont.__reduce_ex__c             C   s   t | ƒS )z/ Returns a printable form of the font.
        )r   )r-   r   r   r   Ú__str__™   s    zTraitsFont.__str__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r/   r0   r   r   r   r   r   ‰   s   	r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTraitPyQtFontzŸ Ensures that values assigned to a trait attribute are valid font
    descriptor strings; the value actually assigned is the corresponding
    TraitsFont.
    c             C   s8   |dkrdS yt |ƒS    Y nX t||dt|ƒƒ‚dS )z¨ Validates that the value is a valid font descriptor string. If so,
        it returns the corresponding TraitsFont; otherwise, it raises a
        TraitError.
        Nza font descriptor string)r,   r   Úrepr)r-   ÚobjectÚnamer)   r   r   r   Úvalidate¬   s    zTraitPyQtFont.validatec             C   s   dS )NzXa string describing a font (e.g. '12 pt bold italic swiss family Arial' or 'default 12')r   )r-   r   r   r   Úinfo¼   s    zTraitPyQtFont.infoN)r1   r2   r3   r4   r9   r:   r   r   r   r   r5   £   s   r5   c              O   s   ddl m} || |ŽS )Nr   )ÚToolkitEditorFactory)Ztraitsui.qt4.font_editorr;   )ÚargsZtraitsr;   r   r   r   Úget_font_editorË   s    r=   )Úeditor)r4   Ú
__future__r   Z	pyface.qtr   Z
traits.apir   r   r   r   r   ZAnyStyleZ
DecorativeZSerifZ	SansSerifZ
TypeWriterr"   r   r   r#   r   r   r$   r%   r   r,   r   r5   r=   ZPyQtFontr   r   r   r   Ú<module>   s*   
:(