a
    §ˆc."  ã                   @   s´   d 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 g d¢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..
é    )ÚQtCoreÚQtGui)ÚToolkitEditorFactoryé   )ÚSimpleEditorÚ
TextEditorÚReadonlyEditor)ÚEditor)Ú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¡S )zYReturns a QFont object corresponding to a specified object's font
        trait.
        )r   ÚQFontÚvalue)ÚselfÚeditor© r   ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/font_editor.pyÚto_qt4_fontI   s    z ToolkitEditorFactory.to_qt4_fontc                 C   s   |S )z1Gets the application equivalent of a QFont value.r   ©r   Úfontr   r   r   Úfrom_qt4_fontO   s    z"ToolkitEditorFactory.from_qt4_fontc                 C   s`   t jjjdt jjjdi | ¡ d¡}t jjjdt jjj	di | 
¡ d¡}d| ¡ | ¡ ||f S )zDReturns the text representation of the specified object trait value.z Lightz BoldÚ z Slantz Italicz%s point %s%s%s)r   r   ZWeightZLightZBoldÚgetÚweightÚStyleZStyleObliqueZStyleItalicÚstyleÚ	pointSizeÚfamily)r   r   r   r   r   r   r   Ústr_fontS   s    ÿ

þýüzToolkitEditorFactory.str_fontN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   F   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¡\}}|r6| j |¡| _|  ¡  dS )z.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_editorj   s    ÿzSimpleFontEditor.popup_editorc                    s   t ƒ  ¡  t| ƒ dS )ú[Updates the editor when the object trait changes externally to the
        editor.
        N©Úsuperr&   Úset_font©r   ©Ú	__class__r   r   r&   t   s    
zSimpleFontEditor.update_editorc                 C   s   | j  |¡S ©z:Returns the text representation of a specified font value.©r$   r   r   r   r   r   Ústring_value{   s    zSimpleFontEditor.string_value)r   r    r!   r"   r)   r&   r3   Ú__classcell__r   r   r/   r   r#   d   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 )ÚCustomFontEditora   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  ¡ | _t  | j¡}| dddd¡ t  | j¡ | _}|j 	| j
¡ | |¡ t  ¡ }t  ¡  | _}| d¡ |j 	| j¡ | |¡ t  ¡  | _}| t¡ |j 	| j¡ | |¡ d | _| _| |¡ dS )z\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   s.   t | j ¡ ƒ| _|  | j | ¡¡ |  ¡  dS )z@Handles the user changing the contents of the font text control.N)Ústrr7   Útextr   Ú	_set_fontr$   r   r&   r.   r   r   r   r9   ¨   s    zCustomFontEditor.update_objectc                 C   sd   | j  ¡ }| | j¡ | | j¡ t| j ¡ ƒ}| 	|¡ | j
 |¡| _| j | j¡ |  |¡ dS )z6Handles the user modifying one of the font components.N)r:   ZcurrentFontZsetBoldr>   Z	setItalicr?   Úintr<   ZcurrentTextÚsetPointSizer$   r   r   r7   ZsetTextr6   rD   )r   r'   Zpszr   r   r   r;   ®   s    

z$CustomFontEditor.update_object_partsc                 C   sp   | j  | ¡}| ¡ | _| ¡ | _| j |¡ zt 	t
| ¡ ƒ¡}W n ty^   t 	d¡}Y n0 | j |¡ dS )r*   r   N)r$   r   Zboldr>   Zitalicr?   r:   ZsetCurrentFontr=   ÚindexrB   r   Ú
ValueErrorr<   ZsetCurrentIndex)r   r   Úidxr   r   r   r&   ½   s    

zCustomFontEditor.update_editorc                 C   s   | j  |¡S r1   r2   r   r   r   r   r3   Ï   s    zCustomFontEditor.string_valuec                 C   s   | j | j| jgS )z9Returns the editor's control for indicating error status.)r7   r:   r<   r.   r   r   r   Úget_error_controlÓ   s    z"CustomFontEditor.get_error_controlc                 C   s$   |  td| ¡ ƒ¡ | j |¡ dS )z=Sets the font used by the text control to the specified font.é
   N)rF   Úminr   r7   ÚsetFontr   r   r   r   rD   Ù   s    zCustomFontEditor._set_fontN)r   r    r!   r"   rA   r9   r;   r&   r3   rJ   rD   r   r   r   r   r5   €   s   r5   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 ¡ ƒ| _dS )z;Handles the user changing the contents of the edit control.N)rB   r%   rC   r   r.   r   r   r   r9   å   s    zTextFontEditor.update_objectc                    s   t ƒ  ¡  t| ƒ dS ©zYUpdates the editor when the object trait changes external to the
        editor.
        Nr+   r.   r/   r   r   r&   é   s    
zTextFontEditor.update_editorc                 C   s   | j  |¡S r1   r2   r   r   r   r   r3   ð   s    zTextFontEditor.string_value)r   r    r!   r"   r9   r&   r3   r4   r   r   r/   r   rN   ß   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| ƒ dS rO   r+   r.   r/   r   r   r&   û   s    
z ReadonlyFontEditor.update_editorc                 C   s   | j  |¡S r1   r2   r   r   r   r   r3     s    zReadonlyFontEditor.string_value)r   r    r!   r"   r&   r3   r4   r   r   r/   r   rP   õ   s   rP   c                 C   s   | j  | j | ¡¡ dS )z9Sets the editor control's font to match a specified font.N)r%   rM   r$   r   )r   r   r   r   r-     s    r-   N)r"   Z	pyface.qtr   r   Ztraitsui.editors.font_editorr   ZBaseToolkitEditorFactoryZeditor_factoryr   ZBaseSimpleEditorr   ZBaseTextEditorr   ZBaseReadonlyEditorr   r	   r=   r#   r5   rN   rP   r-   ZCustomEditorr   r   r   r   Ú<module>   s   _