3
8ßL]  ã               @   st   d Z ddlmZ ddlZddlZddlj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.
é    )Úabsolute_importN)ÚStr)ÚToolkitEditorFactoryé   )ÚEditorc               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚURLResolvingHtmlWindowz] Overrides OnOpeningURL method of HtmlWindow to append the base URL
        local links.
    c             C   s   t jj| |ƒ || _|| _d S )N)ÚwhÚ
HtmlWindowÚ__init__Úopen_externallyÚbase_url)ÚselfÚparentr   r   © r   ú=/tmp/pip-install-5sebvq2j/traitsui/traitsui/wx/html_editor.pyr
   4   s    zURLResolvingHtmlWindow.__init__c             C   sJ   | j rF|jƒ }| jr*|jdƒ r*| j| }|jdƒs<d| }tj|ƒ dS )zL Handle the base url and opening in a new browser window for links.
        úhttp://úhttps://úfile://N)r   r   )r   r   r   )r   ZGetHrefr   Ú
startswithÚ
webbrowserZopen_new)r   Z	link_infoÚurlr   r   r   ÚOnLinkClicked9   s    

z$URLResolvingHtmlWindow.OnLinkClickedc             C   s<   | j r2tjj|ƒ r2|jdd| j fƒ r2| j | S tj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.
        zhttp://zhttps://N)r   ÚosÚpathÚisabsr   r   Z	HTML_OPEN)r   Úurl_typer   r   r   r   ÚOnOpeningURLE   s    
z#URLResolvingHtmlWindow.OnOpeningURLN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r   r   r   /   s   r   c               @   s0   e Zd ZdZdZeZdd„ Zdd„ Zdd„ Z	d	S )
ÚSimpleEditorzG Simple style of editor for HTML, which displays interpreted HTML.
    Tc             C   s@   t || jj| jƒ| _| jjdƒ | jj| _| j| jjddƒ dS )za 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   Úinith   s    

zSimpleEditor.initc             C   s*   | j }| jjr| jj|ƒ}| jj|ƒ dS )z^ Updates 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 }|jdƒs|d7 }|| j_ | jƒ  d S )Nú/)r   Úendswithr%   r(   )r   r   r   r   r   Ú_base_url_changedƒ   s
    
zSimpleEditor._base_url_changedN)
r   r   r   r    Z
scrollabler   r   r&   r(   r+   r   r   r   r   r!   V   s   r!   )r    Ú
__future__r   Úos.pathr   r   Zwx.htmlÚhtmlr   Z
traits.apir   Ztraitsui.editors.html_editorr   Úeditorr   r	   r   r!   r   r   r   r   Ú<module>   s   
'