
    MhW.                     P   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ej        j                  Z e            Zej                            de           d Zd Zd Zd Zd Zd"dZd Zd Z d Z!d Z"d Z#d  Z$d! Z%dS )#aD  
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                   &    e Zd ZdZd Zd ZddZdS )ImportDenierzfImport Hook that will guard against bad Qt imports
    once IPython commits to a specific binding
    c                 ,    t                      | _        d S N)set_ImportDenier__forbidden)selfs    [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/external/qt_loaders.py__init__zImportDenier.__init__9   s    55    c                 z    t           j                            |d            | j                            |           d S r   )sysmodulespopr   add)r   module_names     r   forbidzImportDenier.forbid<   s5    T***[)))))r   Nc                 d    |rd S || j         v r"t          d|dt                      d          d S )Nz
    Importing zQ disabled by IPython, which has
    already imported an Incompatible QT Binding: 
    )r   ImportError
loaded_api)r   fullnamepathtargets       r   	find_speczImportDenier.find_spec@   sQ     	Ft'''+
 88Z\\\\	+   ('r   r   )__name__
__module____qualname____doc__r   r#   r+    r   r   r   r   4   sP         ! ! !* * *
 
 
 
 
 
r   r   c                     t          t                                                    }|                    t          |                     |D ]}t                              |           dS )zXCommit to a particular API, and trigger ImportErrors on subsequent
    dangerous importsN)r   api_to_modulevaluesremoveIDr#   )apir   mods      r   
commit_apir8   Q   s^     -&&(())GNN=%&&&  
		# r   c                      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          rt          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_PYSIDEr0   r   r   r'   r'   [   s     {~&& 	)	*	* 		(	( 
	)	*	* 		(	( ??a  		)	) 4r   c                 $   t           |          }ddlm} g d}| t          t          t
          t          fv r|                    d           |D ]*}	  ||d|          }| dS # t          $ r Y  dS w xY w| t          k    rd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	QtWidgets.NF)   r      T)r2   importlib.utilr+   r>   r?   r<   r=   appendr&   rC   r   __version_info__)r6   r"   r+   requiredsubmodspecr   s          r   has_bindingrR   x   s      $K((((((+++H
|^\>JJJ$$$ 	 		9VV<==D
 |uu 	  	 	 	555	 m&)334s   A$$
A32A3c                      	 ddl } n*# t          $ r 	 ddlm }  n# t          $ r Y Y dS w xY wY nw xY w	 |                     d          S # t          $ r Y dS w xY 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)rU   r&   r   getapi
ValueErrorrT   s    r   r@   r@      s    



   	!!!!!!! 	 	 	FFF	 "!	zz)$$$   s5    
..
(.(..A 
AAc                 x    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)rR   r'   QT_API_PYQT_DEFAULTr<   )r6   currents     r   
can_importr\      sK    s ullG
!!!<...3+%%r   r:   c                 L   ddl }| ,|                    d|            |                    d|            ddlm}m}m} |j        dk     rt          d|j        z            |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   NrV   QVariantrF   rE   rG   i  z'IPython requires PyQt4 >= 4.7, found %srJ   )rU   setapir   rF   rE   rG   PYQT_VERSIONr&   PYQT_VERSION_STR
pyqtSignalSignalpyqtSlotSlotrW   rB   rA   )versionrU   rF   rE   rG   r6   s         r   import_pyqt4rh      s     JJJ

9g&&&

:w'''**********X%%C 12 3 3 	3 %FM/FK jj##G"a<<--[C5%$$r   c                     ddl m} m}m}m} | j        | _        | j        | _        t          j
        d          }|j                            |j                   |j                            |j                   t          }| |||fS )zX
    Import PyQt5

    ImportErrors raised within this function are non-recoverable
    r   rE   rG   rH   rF   QtGuiCompat)r   rE   rG   rH   rF   rc   rd   re   rf   types
ModuleType__dict__updater>   rE   rG   rH   rF   rk   r6   s         r   import_pyqt5rq           655555555555 %FM/FK "=11K///	 2333
C;s**r   c                     ddl m} m}m}m} | j        | _        | j        | _        t          j
        d          }|j                            |j                   |j                            |j                   t          }| |||fS )zX
    Import PyQt6

    ImportErrors raised within this function are non-recoverable
    r   rj   rk   )r   rE   rG   rH   rF   rc   rd   re   rf   rl   rm   rn   ro   r<   rp   s         r   import_pyqt6rt      rr   r   c                  ,    ddl m} m}m} || |t          fS )zY
    Import PySide

    ImportErrors raised within this function are non-recoverable
    r   r_   )r   rF   rE   rG   rC   r_   s      r   import_pysiderv     s1     ,+++++++++5%..r   c                     ddl m} m}m}m}m} t          j        d          }|j        	                    | j                   |j        	                    |j                   |j        	                    |j                   |||t          fS )zZ
    Import PySide2

    ImportErrors raised within this function are non-recoverable
    r   rF   rE   rG   rH   QtPrintSupportrk   )r   rF   rE   rG   rH   ry   rl   rm   rn   ro   r?   )rF   rE   rG   rH   ry   rk   s         r   import_pyside2rz     s     HGGGGGGGGGGGGG "=11K///	 2333 7888;~55r   c                     d } ddl m}m}m}m}m} t          j        d          }|j        	                    |j                   |j
        dk     r?|j        	                    |j                   |j        	                    |j                   nF|j        	                     | |                     |j        	                     | |                     |||t          fS )zZ
    Import PySide6

    ImportErrors raised within this function are non-recoverable
    c                 :      fdt                     D             S )Nc                 \    i | ](}|                     d           |t          |          )S )_)
startswithgetattr).0namemodules     r   
<dictcomp>z5import_pyside6.<locals>.get_attrs.<locals>.<dictcomp>4  sG     
 
 
??3''
'&$''
 
 
r   )dir)r   s   `r   	get_attrsz!import_pyside6.<locals>.get_attrs3  s4    
 
 
 
F
 
 
 	
r   r   rx   rk   )      )r   rF   rE   rG   rH   ry   rl   rm   rn   ro   rN   r=   )r   rF   rE   rG   rH   ry   rk   s          r   import_pyside6r   ,  s    
 
 
 HGGGGGGGGGGGGG "=11K///''##I$6777##N$;<<<<##IIi$8$8999##IIn$=$=>>>;~55r   c                    t           t          t          t          t          t
          t          t          t          t          t          t          t          t          t          d          t          t          i}| D ]}||vrDt          d|dd                    d |                                D                                 t%          |          sZ ||                     }|d         }t'          |           |c S dt(          j        v rt(          j        d= t-          d	t/                      d
t1          t                    dt1          t                     dt1          t                    dt1          t                    d| d          )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)
    rJ   )rg   zInvalid Qt API z, valid values are: z, c                     g | ]}d |z  S )z%rr0   )r   ks     r   
<listcomp>zload_qt.<locals>.<listcomp>v  s     B B Ba B B Br   QT_APIz
    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:                              zA
    PyQt5 available (requires QtCore, QtGui, QtSvg, QtWidgets): zA
    PyQt6 available (requires QtCore, QtGui, QtSvg, QtWidgets): zA
    PySide2 installed:                                          zA
    PySide6 installed:                                          zA
    Tried to load:                                              r%   )r<   rt   r=   r   r>   rq   r?   rz   rC   rv   rA   rh   rB   r   rZ   RuntimeErrorjoinkeysr\   r8   osenvironr&   r'   rR   )api_optionsloadersr6   results       r   load_qtr   I  ss   6 	ll}\w|Q777\G  )
 )
g,dii B B7<<>> B B BCCCEF F F # 	 Rj3 rz!!
8$k L))))L))))N++++N++++%
 
 	
r   c                 @     t          d           fd            }|S )z@Construct an enum helper to account for PyQt5 <-> PyQt6 changes.Nc                      t          j        t          k    r| n|                     d          d                   t          j        j                           S )NrI   r   )operator
attrgetterr<   
rpartitionr   r   __package__)r   r   rE   s    r   _enumzenum_factory.<locals>._enum  sU    
x"l**DD0D0DQ0G
 

+f(
)+ + 	+r   )r   )r   rE   r   s   `` r   enum_factoryr     s;     t__+ + + + + _+ Lr   )r:   )&r/   importlib.abc	importlibr   r   rl   	functoolsr   r   r   r<   r=   r>   r?   rA   rB   rC   rZ   r2   abcMetaPathFinderr   r5   	meta_pathinsertr8   r'   rR   r@   r\   rh   rq   rt   rv   rz   r   r   r   r0   r   r   <module>r      s  	 	     



 				  ( ( ( ( ( ( ( (    #  'I'I87     9=/   2 \^^   Q       :% % %P  ,	& 	& 	&!% !% !% !%H+ + +,+ + +,/ / /6 6 6"6 6 6:Q
 Q
 Q
h
 
 
 
 
r   