o
    ˷e+                     @   s  d Z ddlZddlZddlZddlmZmZ ddlZdZ	dZ
dZdZdZd	Zd
ZdZe	de
dedededededediZG dd dejjZe Zejde dd Zdd Zdd Zdd Zdd Zd/d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 )0aD  
This module contains factory functions that attempt
to return Qt submodules from the various python Qt bindings.

It also protects against double-importing Qt with different
bindings, which is unstable and likely to crash

This is used primarily by qt and qt_for_kernel, and shouldn't
be accessed directly from the outside
    N)partial	lru_cachepyqt6pyside6pyqt5pyside2pyqtpyqtv1pysidepyqtdefaultPyQt6PySide6PyQt5PySide2PySidePyQt4c                   @   s*   e Zd ZdZdd Zdd Zd	ddZdS )
ImportDenierzfImport Hook that will guard against bad Qt imports
    once IPython commits to a specific binding
    c                 C   s   t  | _d S N)set_ImportDenier__forbidden)self r   R/var/www/ideatree/venv/lib/python3.10/site-packages/IPython/external/qt_loaders.py__init__6   s   zImportDenier.__init__c                 C   s   t j|d  | j| d S r   )sysmodulespopr   add)r   module_namer   r   r   forbid9   s   zImportDenier.forbidNc                 C   s(   |rd S || j v rtd|t f d S )Nzi
    Importing %s disabled by IPython, which has
    already imported an Incompatible QT Binding: %s
    )r   ImportError
loaded_api)r   fullnamepathtargetr   r   r   	find_spec=   s   
zImportDenier.find_specr   )__name__
__module____qualname____doc__r   r   r%   r   r   r   r   r   1   s
    r   c                 C   s2   t t }|t|   |D ]}t| qdS )zXCommit to a particular API, and trigger ImportErrors on subsequent
    dangerous importsN)r   api_to_modulevaluesremoveIDr   )apir   modr   r   r   
commit_apiN   s
   r0   c                   C   sr   t jdrtS t jdrtS t jdrtS t jdr tS t jdr/t dkr-tS t	S t jdr7t
S dS )	zReturn which API is loaded, if any

    If this returns anything besides None,
    importing any other Qt binding is unsafe.

    Returns
    -------
    None, 'pyside6', 'pyqt6', 'pyside2', 'pyside', 'pyqt', 'pyqt5', 'pyqtv1'
    zPyQt6.QtCorezPySide6.QtCorezPyQt5.QtCorezPySide2.QtCorezPyQt4.QtCore   zPySide.QtCoreN)r   r   getQT_API_PYQT6QT_API_PYSIDE6QT_API_PYQT5QT_API_PYSIDE2qtapi_versionQT_API_PYQTQT_API_PYQTv1QT_API_PYSIDEr   r   r   r   r!   X   s   

r!   c              	   C   s   t |  }ddlm} g d}| ttttfv r|d |D ]}z
|d||f }W n ty4   Y  dS w |du r< dS q| t	krJddl
}|jdkS d	S )
a5  Safely check for PyQt4/5, PySide or PySide2, without importing submodules

    Parameters
    ----------
    api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
        Which module to check for

    Returns
    -------
    True if the relevant module appears to be importable
    r   )r%   )QtCoreQtGuiQtSvg	QtWidgetsz%s.%sFN)   r      T)r*   importlib.utilr%   r5   r6   r3   r4   appendr    r:   r   __version_info__)r.   r   r%   requiredsubmodspecr   r   r   r   has_bindingu   s$   

rG   c                  C   sj   zddl } W n ty#   zddlm }  W n ty    Y Y dS w Y nw z| dW S  ty4   Y dS w )zReturn which QString API has been set, if any

    Returns
    -------
    The QString API version (1 or 2), or None if not set
    r   NsipQString)rI   r    r   getapi
ValueErrorrH   r   r   r   r7      s   r7   c                 C   s2   t | sdS t }| tkr|tdfv S || dfv S )z?Safely query whether an API is importable, without importing itFN)rG   r!   QT_API_PYQT_DEFAULTr3   )r.   currentr   r   r   
can_import   s   rO   r1   c                 C   s   ddl }| dur|d|  |d|  ddlm}m}m} |jdk r*td|j |j	|_
|j|_|d} | dkr=tnt}||||fS )	z
    Import PyQt4

    Parameters
    ----------
    version : 1, 2, or None
        Which QString/QVariant API to use. Set to None to use the system
        default
    ImportErrors raised within this function are non-recoverable
    r   NrJ   QVariantr<   r;   r=   i  z'IPython requires PyQt4 >= 4.7, found %sr?   )rI   setapir   r<   r;   r=   PYQT_VERSIONr    PYQT_VERSION_STR
pyqtSignalSignalpyqtSlotSlotrK   r9   r8   )versionrI   r<   r;   r=   r.   r   r   r   import_pyqt4   s   

rZ   c                  C   ^   ddl m} m}m}m} | j| _| j| _t	
d}|j|j |j|j t}| |||fS )zX
    Import PyQt5

    ImportErrors raised within this function are non-recoverable
    r   r;   r=   r>   r<   QtGuiCompat)r   r;   r=   r>   r<   rU   rV   rW   rX   types
ModuleType__dict__updater5   r;   r=   r>   r<   r]   r.   r   r   r   import_pyqt5      
rc   c                  C   r[   )zX
    Import PyQt6

    ImportErrors raised within this function are non-recoverable
    r   r\   r]   )r   r;   r=   r>   r<   rU   rV   rW   rX   r^   r_   r`   ra   r3   rb   r   r   r   import_pyqt6   rd   re   c                  C   s    ddl m} m}m} || |tfS )zY
    Import PySide

    ImportErrors raised within this function are non-recoverable
    r   rQ   )r   r<   r;   r=   r:   rQ   r   r   r   import_pyside  s   rf   c                  C   \   ddl m} m}m}m}m} td}|j	| j |j	|j |j	|j |||t
fS )zZ
    Import PySide2

    ImportErrors raised within this function are non-recoverable
    r   r<   r;   r=   r>   QtPrintSupportr]   )r   r<   r;   r=   r>   ri   r^   r_   r`   ra   r6   r<   r;   r=   r>   ri   r]   r   r   r   import_pyside2     
rk   c                  C   rg   )zZ
    Import PySide6

    ImportErrors raised within this function are non-recoverable
    r   rh   r]   )r   r<   r;   r=   r>   ri   r^   r_   r`   ra   r4   rj   r   r   r   import_pyside6)  rl   rm   c                 C   s   t ttttttttt	t
ttttddtti}| D ]-}||vr0td|ddd | D f t|s5q||  }|d }t| |  S tdt tt
tttttt| f )	a  
    Attempt to import Qt, given a preference list
    of permissible bindings

    It is safe to call this function multiple times.

    Parameters
    ----------
    api_options : List of strings
        The order of APIs to try. Valid items are 'pyside', 'pyside2',
        'pyqt', 'pyqt5', 'pyqtv1' and 'pyqtdefault'

    Returns
    -------
    A tuple of QtCore, QtGui, QtSvg, QT_API
    The first three are the Qt modules. The last is the
    string indicating which module was loaded.

    Raises
    ------
    ImportError, if it isn't possible to import any requested
    bindings (either because they aren't installed, or because
    an incompatible library has already been installed)
    r?   )rY   z'Invalid Qt API %r, valid values are: %sz, c                 S   s   g | ]}d | qS )z%rr   ).0kr   r   r   
<listcomp>g  s    zload_qt.<locals>.<listcomp>a@  
    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7, PyQt5, PySide >= 1.0.3 or PySide2 is available,
    and only one is imported per session.

    Currently-imported Qt library:                              %r
    PyQt4 available (requires QtCore, QtGui, QtSvg):            %s
    PyQt5 available (requires QtCore, QtGui, QtSvg, QtWidgets): %s
    PySide >= 1.0.3 installed:                                  %s
    PySide2 installed:                                          %s
    Tried to load:                                              %r
    )r3   re   r4   rm   r5   rc   r6   rk   r:   rf   r8   rZ   r9   r   rM   RuntimeErrorjoinkeysrO   r0   r    r!   rG   )api_optionsloadersr.   resultr   r   r   load_qt:  s>   
rx   c                    s   t d fdd}|S )z@Construct an enum helper to account for PyQt5 <-> PyQt6 changes.Nc                    s,   t  tkr| n| dd tjj S )N.r   )operator
attrgetterr3   
rpartitionr   r   __package__)nameQT_APIr;   r   r   _enum  s
   
zenum_factory.<locals>._enum)r   )r   r;   r   r   r   r   enum_factory  s   r   )r1   )%r)   importlib.abc	importlibr   r^   	functoolsr   r   rz   r3   r4   r5   r6   r8   r9   r:   rM   r*   abcMetaPathFinderr   r-   	meta_pathinsertr0   r!   rG   r7   rO   rZ   rc   re   rf   rk   rm   rx   r   r   r   r   r   <module>   sN    

(
$	K