a
    §ˆc|  ã                   @   s’   d Z ddlZddlmZmZ ddlmZ ddlmZ z,ddlm	Z	 G dd	„ d	e	j
ƒZe	jZd
ZW n ey|   ejZdZY n0 G dd„ deƒZdS )z• Defines the HTML "editor" for the QT4 user interface toolkit.
    HTML editors interpret and display HTML-formatted text, but do not
    modify it.
é    N)ÚQtCoreÚQtGui)ÚStré   )ÚEditor)ÚQtWebKitc                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚExternallyOpeningWebPagea²  QWebEnginePage subclass that opens links in system browser

        This subclass is only used when we are given a QWebEnginePage which is
        pretending to be a QWebPage and we want the open_external feature
        of the Editor.

        This overrides the acceptNavigationRequest method to open links
        in an external browser.  All other navigation requests are handled
        internally as per the base class.
        c                    s2   |t jjkrt | ¡ ¡ dS tƒ  |||¡S d S )NF)r   ÚQWebPageZNavigationTypeLinkClickedÚ
webbrowserÚopen_newÚtoStringÚsuperÚacceptNavigationRequest)ÚselfÚurlÚtypeZisMainFrame©Ú	__class__© ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/html_editor.pyr   *   s    z0ExternallyOpeningWebPage.acceptNavigationRequest)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r   r   r      s   r   TFc                       sJ   e Zd ZdZdZeƒ Zdd„ Z‡ fdd„Zdd„ Z	d	d
„ Z
dd„ Z‡  ZS )ÚSimpleEditorzSimple style editor for HTML.Tc                 C   s´   t ƒ | _| j tjjjtjjj¡ | jjr”t	rx| j 
¡ }t|dƒr`| tjj¡ |j | j¡ q”t| jƒ}| j |¡ n| j d¡ | jj | j¡ | jj| _|  | jjdd¡ dS )z\Finishes initializing the editor by creating the underlying toolkit
        widget.
        ÚsetLinkDelegationPolicyFÚbase_urlÚfromN)ÚWebViewÚcontrolZsetSizePolicyr   ZQSizePolicyÚPolicyZ	ExpandingÚfactoryÚopen_externallyÚHAS_WEB_VIEWÚpageÚhasattrr   r   r	   ZDelegateAllLinksÚlinkClickedÚconnectÚ_link_clickedr   ZsetPageZsetOpenLinksÚanchorClickedr   Z
sync_valueZbase_url_name)r   Úparentr%   r   r   r   ÚinitK   s$    ÿ

ÿ

zSimpleEditor.initc                    sX   | j durJ| jjrJtr:| j  ¡ }t|dƒrJ|j | j¡ n| j j	 | j¡ t
ƒ  ¡  dS )z&Disposes of the contents of an editor.Nr   )r    r"   r#   r$   r%   r&   r'   Z
disconnectr)   r*   r   Údispose)r   r%   r   r   r   r-   k   s    

zSimpleEditor.disposec                 C   sd   | j }| jjr| j |¡}| jrTtrT| j}| d¡s<|d7 }| j |t	j
 |¡¡ n| j |¡ dS )zYUpdates the editor when the object trait changes external to the
        editor.
        ú/N)Z	str_valuer"   Zformat_textZ
parse_textr   r$   Úendswithr    ZsetHtmlr   ZQUrlZfromLocalFile)r   Útextr   r   r   r   Úupdate_editory   s    

zSimpleEditor.update_editorc                 C   s   |   ¡  d S ©N)r1   )r   r   r   r   Ú_base_url_changedŠ   s    zSimpleEditor._base_url_changedc                 C   s   t  | ¡ ¡ d S r2   )r
   r   r   )r   r   r   r   r   r)   �   s    zSimpleEditor._link_clicked)r   r   r   r   Z
scrollabler   r   r,   r-   r1   r3   r)   r   r   r   r   r   r   >   s    r   )r   r
   Z	pyface.qtr   r   Z
traits.apir   Zeditorr   r   r	   r   ZQWebViewr   r$   Ú	ExceptionZQTextBrowserr   r   r   r   r   Ú<module>   s   
