o
    û›hW.  ã                   @   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   úQc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/external/qt_loaders.pyÚ__init__9   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 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
   4   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_apiQ   s
   ÿr(   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 )	zçReturn 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   [   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   r-   r.   r+   r,   Úappendr   r2   r   Ú__version_info__)r&   r   r   ÚrequiredZsubmodÚspecr   r   r   r   Úhas_bindingx   s$   
þþ
r>   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 )z„Return 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   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)r>   r   ÚQT_API_PYQT_DEFAULTr+   )r&   Úcurrentr   r   r   Ú
can_import¶   s   rF   r)   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   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   ó^   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   rP   r&   r   r   r   Úimport_pyqt5æ   ó   
rV   c                  C   rN   )zX
    Import PyQt6

    ImportErrors raised within this function are non-recoverable
    r   rO   rP   )r   r3   r5   r6   r4   rH   rI   rJ   rK   rQ   rR   rS   rT   r+   rU   r   r   r   Úimport_pyqt6ü   rW   rX   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   rY   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   ÚQtPrintSupportrP   )r   r4   r3   r5   r6   r[   rQ   rR   rS   rT   r.   )r4   r3   r5   r6   r[   rP   r   r   r   Úimport_pyside2  s   
r\   c                  C   s�   dd„ } ddl m}m}m}m}m} t d¡}|j 	|j¡ |j
dk r2|j 	|j¡ |j 	|j¡ n|j 	| |ƒ¡ |j 	| |ƒ¡ |||tfS )zZ
    Import PySide6

    ImportErrors raised within this function are non-recoverable
    c                    s   ‡ fdd„t ˆ ƒD ƒS )Nc                    s"   i | ]}|  d ¡s|tˆ |ƒ“qS )Ú_)Ú
startswithÚgetattr)Ú.0Úname©Úmoduler   r   Ú
<dictcomp>4  s    ý
ÿz5import_pyside6.<locals>.get_attrs.<locals>.<dictcomp>)Údirrb   r   rb   r   Ú	get_attrs3  s   
þz!import_pyside6.<locals>.get_attrsr   rZ   rP   )é   é   )r   r4   r3   r5   r6   r[   rQ   rR   rS   rT   r;   r,   )rf   r4   r3   r5   r6   r[   rP   r   r   r   Úimport_pyside6,  s   

ri   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 dtjv rOtjd= 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)
    r7   )rL   z'Invalid Qt API %r, valid values are: %sz, c                 S   s   g | ]}d | ‘qS )z%rr   )r`   Úkr   r   r   Ú
<listcomp>v  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
    )r+   rX   r,   ri   r-   rV   r.   r\   r2   rY   r0   rM   r1   r   rD   ÚRuntimeErrorÚjoinÚkeysrF   r(   ÚosÚenvironr   r   r>   )Zapi_optionsÚloadersr&   Úresultr   r   r   Úload_qtI  sF   ôÿÿ

úôÿru   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__)ra   ©rm   r3   r   r   Ú_enum   s
   ÿ
þzenum_factory.<locals>._enum)r   )rm   r3   r|   r   r{   r   Úenum_factory�  s   r}   )r)   )&r!   Úimportlib.abcÚ	importlibr   rq   rQ   Ú	functoolsr   r   rw   r+   r,   r-   r.   r0   r1   r2   rD   r"   ÚabcÚMetaPathFinderr
   r%   Ú	meta_pathÚinsertr(   r   r>   r/   rF   rM   rV   rX   rY   r\   ri   ru   r}   r   r   r   r   Ú<module>   sP    ô
(
$	T