a
    §cv)  ć                   @   sī   d 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 g d	¢Zg d
¢Zg d¢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..
é    N)ŚBool)ŚToolkitEditorFactoryé   )ŚSimpleEditorŚ
TextEditorŚReadonlyEditor)ŚEditor)ŚTraitsUIPanelŚ
disconnect)Ś8Ś9Ś10Z11Z12Z14Z16Z18Z20Z22Z24Z26Z28Z36Z48Z72)ŚNormalZSlantZItalic)r   Z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 | ” | ” | ” | ” | ” | ” ”S )zZReturns a wxFont object corresponding to a specified object's font
        trait.
        )	ŚvalueŚwxŚFontŚGetPointSizeZ	GetFamilyŚGetStyleŚ	GetWeightZGetUnderlinedŚGetFaceName)ŚselfŚeditorŚfont© r   śZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/font_editor.pyŚ
to_wx_fontM   s    śzToolkitEditorFactory.to_wx_fontc                 C   s   |S )z9Gets 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 | ” d”}t jdt 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   ZFONTWEIGHT_LIGHTZFONTWEIGHT_BOLDŚgetr   ZFONTSTYLE_SLANTZFONTSTYLE_ITALICr   r   r   )r   r   ŚweightŚstyler   r   r   Śstr_font_   s     žżžżüzToolkitEditorFactory.str_fontc                 C   s   t du rtt   ” a t S )ś/Returns a list of all available font facenames.N)Ś	facenamesŚsortedŚFontEnumerator©r   r   r   r   Śall_facenamesp   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 | ”” t  | j|”}| ” t jkrT| j 	| 
”  ” ”| _|  ”  | ”  dS )z.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|  dS )ś[Updates the editor when the object trait changes externally to the
        editor.
        N©Śsuperr2   Śset_fontr'   ©Ś	__class__r   r   r2      s    
zSimpleFontEditor.update_editorc                 C   s   | j  |”S ©z:Returns the text representation of a specified font value.©r0   r"   r   r   r   r   Śstring_value   s    zSimpleFontEditor.string_value)r)   r*   r+   r,   r5   r2   r>   Ś__classcell__r   r   r:   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 tj”}t tj”}| j ” }t |dt 	dd”t 
dd”|” }| _| |dtj” |jtj| j| ” d t |dt 	dd”t 
dd”t” }| _| |dtjtjB d” |jtj| j| ” d | jjr<t |dt 	dd”t 
dd”t”| _| | jdtjtjB d” |jtj| j| j ” d | jjrt |dt 	dd”t 
dd”t”| _| | jdtjtjB d” |jtj| j| j ” d | |dtj” | |” |  ”  dS )z\Finishes initializing the editor by creating the underlying toolkit
        widget.
        é’’’’r   é   )Śidr   é   N)r	   r1   r   ZBoxSizerZVERTICALZ
HORIZONTALr0   r(   ZChoiceZPointŚSizeŚ	_facenameŚAddZEXPANDZBindŚ
EVT_CHOICEŚupdate_object_partsZGetIdŚ
PointSizesŚ_point_sizeŚLEFTr-   ŚStylesŚ_styler.   ŚWeightsŚ_weightZSetSizerZset_tooltip)r   ŚparentZpanelZsizerZsizer2r$   r1   r   r   r   Śinit„   sF    
’
’

’’
’ż
zCustomFontEditor.initc                    sV   t | jtj t | jtj | jjr2t | jtj | jjrHt | j	tj t
  ”  dS )z&Disposes of the contents of an editor.N)r
   rF   r   rH   rK   r0   r-   rN   r.   rP   r8   Śdisposer'   r:   r   r   rS   Ų   s    zCustomFontEditor.disposec                 C   sx   t | j ” }| j ” }tj}| jjr4|| j 	” 7 }tj
}| jjrP|| j 	” 7 }tj|tj|||d}| j |”| _dS )z6Handles the user modifying one of the font components.)ZfaceNameN)ŚintrK   ZGetStringSelectionrF   r   ZFONTSTYLE_NORMALr0   r-   rN   ZGetCurrentSelectionZFONTWEIGHT_NORMALr.   rP   r   ZFONTFAMILY_DEFAULTr   r   )r   r3   Z
point_sizeŚfacenamer!   r    r   r   r   r   rI   ć   s    
’z$CustomFontEditor.update_object_partsc                 C   sp   | j  | ”}z| j | ” ” W n   | j d” Y n0 z| j t| ” ” W n   | j d” Y n0 dS )r6   r   N)	r0   r   rF   ZSetStringSelectionr   ZSetSelectionrK   Śstrr   r   r   r   r   r2   õ   s    zCustomFontEditor.update_editorc                 C   s   | j  |”S r<   r=   r   r   r   r   r>     s    zCustomFontEditor.string_value)
r)   r*   r+   r,   rR   rS   rI   r2   r>   r?   r   r   r:   r   r@      s   3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   | j  ” | _dS )z;Handles the user changing the contents of the edit control.N)r1   ZGetValuer   )r   r3   r   r   r   Śupdate_object  s    zTextFontEditor.update_objectc                    s   t   ”  t|  dS ©zYUpdates the editor when the object trait changes external to the
        editor.
        Nr7   r'   r:   r   r   r2     s    
zTextFontEditor.update_editorc                 C   s   | j  |”S r<   r=   r   r   r   r   r>      s    zTextFontEditor.string_value)r)   r*   r+   r,   rX   r2   r>   r?   r   r   r:   r   rW     s   rW   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 rY   r7   r'   r:   r   r   r2   +  s    
z ReadonlyFontEditor.update_editorc                 C   s   | j  |”S r<   r=   r   r   r   r   r>   2  s    zReadonlyFontEditor.string_value)r)   r*   r+   r,   r2   r>   r?   r   r   r:   r   rZ   %  s   rZ   c                 C   s0   | j  | ”}| td| ” ” | j |” dS )z9Sets the editor control's font to match a specified font.é
   N)r0   r   ZSetPointSizeŚminr   r1   ZSetFont)r   r   r   r   r   r9   <  s    r9   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 S )r#   )Ś
_facenamesZEnumerateFacenamesr'   r   r   r   r$   F  s    zFontEnumerator.facenamesc                 C   s   | j  |” dS )z)Adds a facename to the list of facenames.T)r]   Śappend)r   rU   r   r   r   Ś
OnFacenameL  s    zFontEnumerator.OnFacenameN)r)   r*   r+   r,   r$   r_   r   r   r   r   r&   C  s   r&   )r,   r   Z
traits.apir   Ztraitsui.editors.font_editorr   ZBaseToolkitEditorFactoryZeditor_factoryr   ZBaseSimpleEditorr   ZBaseTextEditorr   ZBaseReadonlyEditorr   r   Śhelperr	   r
   rJ   rM   rO   r$   r/   r@   rW   rZ   r9   r&   ZCustomEditorr   r   r   r   Ś<module>   s*   	7r