U
    -e,                     @   s  d Z ddl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_cacheZpyqt6Zpyside6Zpyqt5Zpyside2ZpyqtZpyqtv1ZpysideZ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   \/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/IPython/external/qt_loaders.py__init__8   s    zImportDenier.__init__c                 C   s   t j|d  | j| d S r   )sysmodulespopr   add)r   module_namer   r   r   forbid;   s    zImportDenier.forbidNc                 C   s(   |rd S || j k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_spec)N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r
   3   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_apiP   s    r(   c                   C   st   t jdrtS t jdr tS t jdr0tS t jdr@tS t jdr`t dkrZtS t	S nt jdrpt
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   Z   s    

r   c              	   C   s   t |  }ddlm} dddg}| ttttfkr8|d |D ]@}z|d||f }W n tk
rl   Y  dS X |d	kr< dS q<| t	krd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   r-   r.   r+   r,   appendr   r2   r   __version_info__)r&   r   r   requiredZsubmodspecr   r   r   r   has_bindingw   s     



r>   c                  C   st   zddl } W n> tk
rJ   zddlm }  W n tk
rD   Y Y dS X Y nX z| dW S  tk
rn   Y dS X dS )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)r@   r   r   getapi
ValueErrorr?   r   r   r   r/      s    r/   c                 C   s6   t | sdS t }| tkr&|tdfkS || dfkS dS )z?Safely query whether an API is importable, without importing itFN)r>   r   QT_API_PYQT_DEFAULTr+   )r&   currentr   r   r   
can_import   s    rF   r)   c                 C   s   ddl }| dk	r(|d|  |d|  ddlm}m}m} |jdk rTtd|j |j	|_
|j|_|d} | dkrzt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   NrA   ZQVariantr4   r3   r5   i  z'IPython requires PyQt4 >= 4.7, found %sr7   )r@   Zsetapir	   r4   r3   r5   ZPYQT_VERSIONr   ZPYQT_VERSION_STR
pyqtSignalSignalpyqtSlotSlotrB   r1   r0   )versionr@   r4   r3   r5   r&   r   r   r   import_pyqt4   s    

rM   c                  C   s^   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   r3   r5   r6   r4   QtGuiCompat)r   r3   r5   r6   r4   rH   rI   rJ   rK   types
ModuleType__dict__updater-   r3   r5   r6   r4   rO   r&   r   r   r   import_pyqt5   s    
rU   c                  C   s^   ddl m} m}m}m} | j| _| j| _t	
d}|j|j |j|j t}| |||fS )zX
    Import PyQt6

    ImportErrors raised within this function are non-recoverable
    r   rN   rO   )r   r3   r5   r6   r4   rH   rI   rJ   rK   rP   rQ   rR   rS   r+   rT   r   r   r   import_pyqt6   s    
rV   c                  C   s    ddl m} m}m} || |tfS )zY
    Import PySide

    ImportErrors raised within this function are non-recoverable
    r   rG   )r   r4   r3   r5   r2   rG   r   r   r   import_pyside  s    rW   c                  C   s\   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   r4   r3   r5   r6   QtPrintSupportrO   )r   r4   r3   r5   r6   rY   rP   rQ   rR   rS   r.   r4   r3   r5   r6   rY   rO   r   r   r   import_pyside2  s    
r[   c                  C   s\   ddl m} m}m}m}m} td}|j	| j |j	|j |j	|j |||t
fS )zZ
    Import PySide6

    ImportErrors raised within this function are non-recoverable
    r   rX   rO   )r   r4   r3   r5   r6   rY   rP   rQ   rR   rS   r,   rZ   r   r   r   import_pyside6+  s    
r\   c                 C   s   t ttttttttt	t
ttttddtti}| D ]Z}||kr`td|ddd | D f t|sjq0||  }|d }t| |  S dtjkrtjd= td	t tttt tttt| f d
S )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)
    r7   )rL   z'Invalid Qt API %r, valid values are: %sz, c                 S   s   g | ]}d | qS )z%rr   ).0kr   r   r   
<listcomp>i  s     zload_qt.<locals>.<listcomp>QT_APIaQ  
    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7, PyQt5, PyQt6, PySide >= 1.0.3, PySide2, or
    PySide6 is available, and only one is imported per session.

    Currently-imported Qt library:                              %r
    PyQt5 available (requires QtCore, QtGui, QtSvg, QtWidgets): %s
    PyQt6 available (requires QtCore, QtGui, QtSvg, QtWidgets): %s
    PySide2 installed:                                          %s
    PySide6 installed:                                          %s
    Tried to load:                                              %r
    N)r+   rV   r,   r\   r-   rU   r.   r[   r2   rW   r0   rM   r1   r   rD   RuntimeErrorjoinkeysrF   r(   osenvironr   r   r>   )Zapi_optionsloadersr&   resultr   r   r   load_qt<  sV           
 

ri   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
attrgetterr+   
rpartitionr   r   __package__)namera   r3   r   r   _enum  s
    
zenum_factory.<locals>._enum)r   )ra   r3   rq   r   rp   r   enum_factory  s    rr   )r)   )&r!   importlib.abc	importlibr   re   rP   	functoolsr   r   rk   r+   r,   r-   r.   r0   r1   r2   rD   r"   abcMetaPathFinderr
   r%   	meta_pathinsertr(   r   r>   r/   rF   rM   rU   rV   rW   r[   r\   ri   rr   r   r   r   r   <module>   s^   
        
(
$	T