3
8ßL]\?  ã               @   s  d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
ZmZmZ ddlmZ dd	lmZmZ d
dddddddddddddddgZdddgZdddgZdaG dd „ d eƒZG d!d"„ d"eƒZG d#d$„ d$eƒZG d%d&„ d&eƒZG d'd(„ d(eƒZd)d*„ ZG d+d,„ d,ejƒZeZ
eZeZeZdS )-zm Defines the various font editors and the font editor factory, for the
    wxPython user interface toolkit..
é    )Úabsolute_importN)ÚBool)ÚToolkitEditorFactoryé   )ÚSimpleEditorÚ
TextEditorÚReadonlyEditor)ÚEditor)ÚTraitsUIPanelÚ
disconnectÚ8Ú9Ú10Z11Z12Z14Z16Z18Z20Z22Z24Z26Z28Z36Z48Z72ZNormalZSlantZItalicZLightZBoldc               @   s@   e Zd ZdZedƒZedƒZdd„ Zdd„ Zdd„ Z	d	d
„ Z
dS )r   z/ wxPython editor factory for font editors.
    Fc             C   s2   |j }tj|jƒ |jƒ |jƒ |jƒ |jƒ |jƒ ƒS )z[ Returns a wxFont object corresponding to a specified object's font
        trait.
        )	ÚvalueÚwxÚFontÚGetPointSizeZ	GetFamilyÚGetStyleÚ	GetWeightZGetUnderlinedÚGetFaceName)ÚselfÚeditorÚfont© r   ú=/tmp/pip-install-5sebvq2j/traitsui/traitsui/wx/font_editor.pyÚ
to_wx_fontR   s    zToolkitEditorFactory.to_wx_fontc             C   s   |S )zC Gets the application equivalent of a wxPython Font value.
        r   )r   r   r   r   r   Úfrom_wx_font_   s    z!ToolkitEditorFactory.from_wx_fontc             C   sP   t jdt jdij|jƒ dƒ}t jdt jdij|jƒ dƒ}d|jƒ |j	ƒ ||f S )zN Returns the text representation of the specified object trait value.
        z Lightz BoldÚ z Slantz Italicz%s point %s%s%s)
r   ZFONTWEIGHT_LIGHTZFONTWEIGHT_BOLDÚgetr   ZFONTSTYLE_SLANTZFONTSTYLE_ITALICr   r   r   )r   r   ÚweightÚstyler   r   r   Ústr_fonth   s    zToolkitEditorFactory.str_fontc             C   s   t dkrttƒ j ƒ ƒa t S )z9 Returns a list of all available font facenames.
        N)Ú	facenamesÚsortedÚFontEnumerator)r   r   r   r   Úall_facenamesv   s    z"ToolkitEditorFactory.all_facenamesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú
show_styleÚshow_weightr   r   r!   r%   r   r   r   r   r   G   s   	r   c                   s0   e Zd ZdZdd„ Z‡ fdd„Zdd„ Z‡  ZS )ÚSimpleFontEditorzÜ Simple style of font editor, which displays a text field that contains
        a text representation of the font value (using that font if possible).
        Clicking the field displays a font selection dialog box.
    c             C   s`   t jƒ }|j| jj| ƒƒ t j| j|ƒ}|jƒ t jkrT| jj	|j
ƒ jƒ ƒ| _| jƒ  |jƒ  dS )z8 Invokes the pop-up editor for an object trait.
        N)r   ZFontDataZSetInitialFontÚfactoryr   Z
FontDialogÚcontrolZ	ShowModalZID_OKr   ZGetFontDataZGetChosenFontr   Úupdate_editorZDestroy)r   ÚeventZ	font_dataÚdialogr   r   r   Úpopup_editorŽ   s    zSimpleFontEditor.popup_editorc                s   t t| ƒjƒ  t| ƒ dS )z` Updates the editor when the object trait changes externally to the
            editor.
        N)Úsuperr,   r/   Úset_font)r   )Ú	__class__r   r   r/   Ÿ   s    zSimpleFontEditor.update_editorc             C   s   | j j|ƒS )zD Returns the text representation of a specified font value.
        )r-   r!   )r   r   r   r   r   Ústring_valueª   s    zSimpleFontEditor.string_value)r&   r'   r(   r)   r2   r/   r6   Ú__classcell__r   r   )r5   r   r,   „   s   r,   c                   s@   e Zd ZdZdd„ Z‡ fdd„Zdd„ Zdd	„ Zd
d„ Z‡  Z	S )ÚCustomFontEditorz÷ Custom style of font editor, which displays the following:

        * A combo box containing all available type face names.
        * A combo box containing the available type sizes.
        * A combo box containing the available type styles
    c             C   s´  t |dƒ | _}tjtjƒ}tjtjƒ}| jjƒ }tj|dtj	ddƒtj
dd	ƒ|ƒ }| _|j|dtjƒ tj||jƒ | jƒ tj|d
tj	ddƒtj
ddƒtƒ }| _|j|dtjtjB dƒ tj||jƒ | jƒ | jj�r0tj|dtj	ddƒtj
ddƒtƒ| _|j| jdtjtjB dƒ tj|| jjƒ | jƒ | jj�rŽtj|dtj	ddƒtj
ddƒtƒ| _|j| jdtjtjB dƒ tj|| jjƒ | jƒ |j|dtjƒ |j|ƒ | jƒ  dS )za Finishes initializing the editor by creating the underlying toolkit
            widget.
        r   r   é   é   Néÿÿÿÿr;   r;   r;   r;   r;   r;   r;   r;   r;   r;   r;   r;   )r
   r.   r   ZBoxSizerZVERTICALZ
HORIZONTALr-   r%   ZChoiceZPointÚSizeÚ	_facenameÚAddZEXPANDÚ
EVT_CHOICEZGetIdÚupdate_object_partsÚ
PointSizesÚ_point_sizeÚLEFTr*   ÚStylesÚ_styler+   ÚWeightsÚ_weightZSetSizerZset_tooltip)r   ÚparentZpanelZsizerZsizer2r"   r.   r   r   r   ÚinitÁ   s8    



zCustomFontEditor.initc                sZ   t | jtjƒ t | jtjƒ | jjr2t | jtjƒ | jjrHt | j	tjƒ t
t| ƒjƒ  dS )z0 Disposes of the contents of an editor.
        N)r   r=   r   r?   rB   r-   r*   rE   r+   rG   r3   r8   Údispose)r   )r5   r   r   rJ   ñ   s    zCustomFontEditor.disposec             C   sx   t | jjƒ ƒ}| jjƒ }tj}| jjr4|| jj	ƒ 7 }tj
}| jjrP|| jj	ƒ 7 }tj|tj|||d�}| jj|ƒ| _dS )z@ Handles the user modifying one of the font components.
        )ZfaceNameN)ÚintrB   ZGetStringSelectionr=   r   ZFONTSTYLE_NORMALr-   r*   rE   ZGetCurrentSelectionZFONTWEIGHT_NORMALr+   rG   r   ZFONTFAMILY_DEFAULTr   r   )r   r0   Z
point_sizeÚfacenamer    r   r   r   r   r   r@     s    
z$CustomFontEditor.update_object_partsc             C   sp   | j j| ƒ}y| jj|jƒ ƒ W n   | jjdƒ Y nX y| jjt|jƒ ƒƒ W n   | jjdƒ Y nX dS )z` Updates the editor when the object trait changes externally to the
            editor.
        r   N)	r-   r   r=   ZSetStringSelectionr   ZSetSelectionrB   Ústrr   )r   r   r   r   r   r/     s    zCustomFontEditor.update_editorc             C   s   | j j|ƒS )zD Returns the text representation of a specified font value.
        )r-   r!   )r   r   r   r   r   r6   +  s    zCustomFontEditor.string_value)
r&   r'   r(   r)   rI   rJ   r@   r/   r6   r7   r   r   )r5   r   r8   ´   s   0r8   c                   s0   e Zd ZdZdd„ Z‡ fdd„Zdd„ Z‡  ZS )ÚTextFontEditorz¨ Text style of font editor, which displays an editable text field
        containing a text representation of the font value (using that font if
        possible).
    c             C   s   | j jƒ | _dS )zE Handles the user changing the contents of the edit control.
        N)r.   ZGetValuer   )r   r0   r   r   r   Úupdate_object?  s    zTextFontEditor.update_objectc                s   t t| ƒjƒ  t| ƒ dS )z^ Updates the editor when the object trait changes external to the
            editor.
        N)r3   rN   r/   r4   )r   )r5   r   r   r/   H  s    zTextFontEditor.update_editorc             C   s   | j j|ƒS )zD Returns the text representation of a specified font value.
        )r-   r!   )r   r   r   r   r   r6   S  s    zTextFontEditor.string_value)r&   r'   r(   r)   rO   r/   r6   r7   r   r   )r5   r   rN   5  s   	rN   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚReadonlyFontEditorz­ Read-only style of font editor, which displays a read-only text field
        containing a text representation of the font value (using that font if
        possible).
    c                s   t t| ƒjƒ  t| ƒ dS )z^ Updates the editor when the object trait changes external to the
            editor.
        N)r3   rP   r/   r4   )r   )r5   r   r   r/   g  s    z ReadonlyFontEditor.update_editorc             C   s   | j j|ƒS )zD Returns the text representation of a specified font value.
        )r-   r!   )r   r   r   r   r   r6   r  s    zReadonlyFontEditor.string_value)r&   r'   r(   r)   r/   r6   r7   r   r   )r5   r   rP   ]  s   rP   c             C   s0   | j j| ƒ}|jtd|jƒ ƒƒ | jj|ƒ dS )z? Sets the editor control's font to match a specified font.
    é
   N)r-   r   ZSetPointSizeÚminr   r.   ZSetFont)r   r   r   r   r   r4   |  s    r4   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )r$   z An enumeration of fonts.
    c             C   s   g | _ | jƒ  | j S )z9 Returns a list of all available font facenames.
        )Ú
_facenamesZEnumerateFacenames)r   r   r   r   r"   �  s    zFontEnumerator.facenamesc             C   s   | j j|ƒ dS )z3 Adds a facename to the list of facenames.
        T)rS   Úappend)r   rL   r   r   r   Ú
OnFacenameš  s    zFontEnumerator.OnFacenameN)r&   r'   r(   r)   r"   rU   r   r   r   r   r$   ˆ  s   r$   ) r)   Ú
__future__r   r   Z
traits.apir   Ztraitsui.editors.font_editorr   ZBaseToolkitEditorFactoryZeditor_factoryr   ZBaseSimpleEditorr   ZBaseTextEditorr   ZBaseReadonlyEditorr   r	   Úhelperr
   r   rA   rD   rF   r"   r,   r8   rN   rP   r4   r$   ZCustomEditorr   r   r   r   Ú<module>   s0   	

	=0 (