3
8ßL]¥4  ã               @   sä   d Z ddlmZ ddlmZmZ ddlmZ ddl	m
ZmZmZ ddlmZ ddlZd	d
ddddddddddddddg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G d!d"„ d"eƒZd#d$„ ZeZ
eZeZeZdS )%zi Defines the various font editors and the font editor factory, for the
    PyQt user interface toolkit..
é    )Úabsolute_import)ÚQtCoreÚQtGui)ÚToolkitEditorFactoryé   )ÚSimpleEditorÚ
TextEditorÚReadonlyEditor)ÚEditorNÚ8Ú9Ú10Z11Z12Z14Z16Z18Z20Z22Z24Z26Z28Z36Z48Z72c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r   z+ PyQt editor factory for font editors.
    c             C   s   t j|jƒS )zZ Returns a QFont object corresponding to a specified object's font
        trait.
        )r   ÚQFontÚvalue)ÚselfÚeditor© r   ú>/tmp/pip-install-5sebvq2j/traitsui/traitsui/qt4/font_editor.pyÚto_qt4_font<   s    z ToolkitEditorFactory.to_qt4_fontc             C   s   |S )z; Gets the application equivalent of a QFont value.
        r   )r   Úfontr   r   r   Úfrom_qt4_fontF   s    z"ToolkitEditorFactory.from_qt4_fontc             C   sX   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	ƒ |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   r   ZLightZBoldÚgetÚweightZStyleObliqueZStyleItalicÚstyleÚ	pointSizeÚfamily)r   r   r   r   r   r   r   Ústr_fontO   s    zToolkitEditorFactory.str_fontN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   5   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| ƒ| jƒ\}}|r6| jj|ƒ| _| jƒ  dS )z8 Invokes the pop-up editor for an object trait.
        N)	r   ZQFontDialogZgetFontÚfactoryr   Úcontrolr   r   Úupdate_editor)r   ÚfntÚokr   r   r   Úpopup_editorg   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%   u   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!   r(   r%   r,   Ú__classcell__r   r   )r+   r   r"   ^   s   r"   c               @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )ÚCustomFontEditora1   Custom style of font editor, which displays the following:

        * A text field containing the text representation of the font value
          (using that font if possible).
        * A combo box containing all available type face names.
        * A combo box containing the available type sizes.
    c             C   sÒ   t jƒ | _t j| jƒ}|jddddƒ t j| jƒ | _}|jj	| j
ƒ |j|ƒ t jƒ }t jƒ  | _}|jdƒ |jj	| jƒ |j|ƒ t jƒ  | _}|jtƒ |jj	| jƒ |j|ƒ d | _| _|j|ƒ dS )za Finishes initializing the editor by creating the underlying toolkit
            widget.
        r   FN)r   ZQWidgetr$   ZQVBoxLayoutZsetContentsMarginsZ	QLineEditÚ	str_valueÚ_fontZeditingFinishedÚconnectÚupdate_objectZ	addWidgetZQHBoxLayoutZQFontComboBoxÚ	_facenameZsetEditableZcurrentFontChangedÚupdate_object_partsZ	QComboBoxÚ_point_sizeZaddItemsÚ
PointSizesZcurrentIndexChangedÚ_boldÚ_italicZ	addLayout)r   ÚparentZlayoutr   Zlayout2r$   r   r   r   Úinit—   s"    





zCustomFontEditor.initc             C   s0   t j| jjƒ ƒ| _| j| jj| ƒƒ | jƒ  dS )zJ Handles the user changing the contents of the font text control.
        N)	ÚsixÚ	text_typer0   Útextr   Ú	_set_fontr#   r   r%   )r   r   r   r   r2   º   s    zCustomFontEditor.update_objectc             C   sd   | j jƒ }|j| jƒ |j| jƒ t| jjƒ ƒ}|j	|ƒ | j
j|ƒ| _| jj| jƒ | j|ƒ dS )z@ Handles the user modifying one of the font components.
        N)r3   ZcurrentFontZsetBoldr7   Z	setItalicr8   Úintr5   ZcurrentTextÚsetPointSizer#   r   r   r0   ZsetTextr/   r>   )r   r&   Zpszr   r   r   r4   Å   s    

z$CustomFontEditor.update_object_partsc             C   sr   | j j| ƒ}|jƒ | _|jƒ | _| jj|ƒ ytj	t
|jƒ ƒƒ}W n tk
r`   tj	dƒ}Y nX | jj|ƒ dS )z` Updates the editor when the object trait changes externally to the
            editor.
        r   N)r#   r   Zboldr7   Zitalicr8   r3   ZsetCurrentFontr6   ÚindexÚstrr   Ú
ValueErrorr5   ZsetCurrentIndex)r   r   Úidxr   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   r,   ï   s    zCustomFontEditor.string_valuec             C   s   | j | j| jgS )zC Returns the editor's control for indicating error status.
        )r0   r3   r5   )r   r   r   r   Úget_error_controlø   s    z"CustomFontEditor.get_error_controlc             C   s$   |j td|jƒ ƒƒ | jj|ƒ dS )zG Sets the font used by the text control to the specified font.
        é
   N)r@   Úminr   r0   ÚsetFont)r   r   r   r   r   r>   ÿ   s    zCustomFontEditor._set_fontN)r   r   r    r!   r:   r2   r4   r%   r,   rE   r>   r   r   r   r   r.   Š   s   #	r.   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   t j| jjƒ ƒ| _dS )zE Handles the user changing the contents of the edit control.
        N)r;   r<   r$   r=   r   )r   r   r   r   r2     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)r)   rI   r%   r*   )r   )r+   r   r   r%     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   r,   '  s    zTextFontEditor.string_value)r   r   r    r!   r2   r%   r,   r-   r   r   )r+   r   rI   
  s   	rI   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)r)   rJ   r%   r*   )r   )r+   r   r   r%   :  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   r,   E  s    zReadonlyFontEditor.string_value)r   r   r    r!   r%   r,   r-   r   r   )r+   r   rJ   1  s   rJ   c             C   s   | j j| jj| ƒƒ dS )z? Sets the editor control's font to match a specified font.
    N)r$   rH   r#   r   )r   r   r   r   r*   O  s    r*   )r!   Ú
__future__r   Z	pyface.qtr   r   Ztraitsui.editors.font_editorr   ZBaseToolkitEditorFactoryZeditor_factoryr   ZBaseSimpleEditorr   ZBaseTextEditorr	   ZBaseReadonlyEditorr   r
   r;   r6   r"   r.   rI   rJ   r*   ZCustomEditorr   r   r   r   Ú<module>   s&   
), '