a
    §ˆc›  ã                   @   s^   d Z ddlZddlZddlmZ ddlmZ ddl	m
Z
 G dd„ dejƒZG dd	„ d	e
ƒZdS )
zš Defines the HTML "editor" for the wxPython user interface toolkit.
    HTML editors interpret and display HTML-formatted text, but do not
    modify it.
é    N)ÚStré   )ÚEditorc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚURLResolvingHtmlWindowzXOverrides OnOpeningURL method of HtmlWindow to append the base URL
    local links.
    c                 C   s   t j | |¡ || _|| _d S )N)ÚwhÚ
HtmlWindowÚ__init__Úopen_externallyÚbase_url)ÚselfÚparentr	   r
   © r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/html_editor.pyr       s    zURLResolvingHtmlWindow.__init__c                 C   sH   | j rD| ¡ }| jr(| d¡s(| j| }| d¡s:d| }t |¡ dS )zBHandle the base url and opening in a new browser window for links.)úhttp://úhttps://)úfile://r   r   r   N)r	   ZGetHrefr
   Ú
startswithÚ
webbrowserZopen_new)r   Z	link_infoÚurlr   r   r   ÚOnLinkClicked%   s    

z$URLResolvingHtmlWindow.OnLinkClickedc                 C   sB   | j r4tj |¡s4| dd| j f¡s4tj| j | fS tj|fS dS )zíAccording to the documentation, this method is supposed to be called
        for both images and link clicks, but it appears to only be called
        for image loading, hence the base url handling code in
        OnLinkClicked.
        r   r   N)r
   ÚosÚpathÚisabsr   r   ZHTML_REDIRECTZ	HTML_OPEN)r   Úurl_typer   r   r   r   ÚOnOpeningURL/   s    ÿ
þýz#URLResolvingHtmlWindow.OnOpeningURLN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s   
r   c                   @   s2   e Zd ZdZdZeƒ Zdd„ Zdd„ Zdd„ Z	d	S )
ÚSimpleEditorzASimple style of editor for HTML, which displays interpreted HTML.Tc                 C   s@   t || jj| jƒ| _| j d¡ | jj| _|  | jjdd¡ dS )z\Finishes initializing the editor by creating the underlying toolkit
        widget.
        é   r
   ÚfromN)r   Úfactoryr	   r
   ÚcontrolZ
SetBordersZ
sync_valueZbase_url_name)r   r   r   r   r   ÚinitL   s    ÿ
zSimpleEditor.initc                 C   s*   | j }| jjr| j |¡}| j |¡ dS )zYUpdates the editor when the object trait changes external to the
        editor.
        N)Z	str_valuer"   Zformat_textZ
parse_textr#   ZSetPage)r   Útextr   r   r   Úupdate_editorX   s    zSimpleEditor.update_editorc                 C   s,   | j }| d¡s|d7 }|| j_ |  ¡  d S )Nú/)r
   Úendswithr#   r&   )r   r   r   r   r   Ú_base_url_changedc   s
    
zSimpleEditor._base_url_changedN)
r   r   r   r   Z
scrollabler   r
   r$   r&   r)   r   r   r   r   r   ?   s   r   )r   Úos.pathr   r   Zwx.htmlÚhtmlr   Z
traits.apir   Zeditorr   r   r   r   r   r   r   r   Ú<module>   s   $