
    "e                          d Z ddlZddlmZ ddlmZ dZdZdZdZ	d	Z
d
Z G d de      Z e       Zej                  j!                  e       d Zd Zd Zd Zd ZddZd Zd Zd Zd Zy)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)check_versionpyqtpyqtv1pyqtdefaultpysidepyside2pyqt5c                   *    e Zd ZdZd Zd ZddZd Zy)ImportDenierzfImport Hook that will guard against bad Qt imports
    once IPython commits to a specific binding
    c                 "    t               | _        y N)set_ImportDenier__forbidden)selfs    :/usr/lib/python3/dist-packages/pydev_ipython/qt_loaders.py__init__zImportDenier.__init__   s    5    c                 z    t         j                  j                  |d        | j                  j	                  |       y r   )sysmodulespopr   add)r   module_names     r   forbidzImportDenier.forbid!   s(    T*[)r   Nc                 *    |ry || j                   v r| S y r   )r   )r   fullnamepaths      r   find_modulezImportDenier.find_module%   s     t'''K (r   c                 6    t        d|dt               d      )Nz
    Importing zQ disabled by IPython, which has
    already imported an Incompatible QT Binding: 
    )ImportError
loaded_api)r   r   s     r   load_modulezImportDenier.load_module+   s     Z\# $ 	$r   r   )__name__
__module____qualname____doc__r   r   r   r$    r   r   r   r      s    !*$r   r   c                     | t         k(  r+t        j                  d       t        j                  d       yt        j                  d       t        j                  d       y)z[Commit to a particular API, and trigger ImportErrors on subsequent
       dangerous importsPyQt4PyQt5PySidePySide2N)QT_API_PYSIDEIDr   )apis    r   
commit_apir2   6   s<     m
		'
		'
		(
		)r   c                      dt         j                  v rt               dk(  rt        S t        S dt         j                  v rt
        S dt         j                  v rt        S dt         j                  v rt        S y)zReturn which API is loaded, if any

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

    Returns
    -------
    None, 'pyside', 'pyside2', 'pyqt', or 'pyqtv1'
    zPyQt4.QtCore   zPySide.QtCorezPySide2.QtCorezPyQt5.QtCoreN)r   r   qtapi_versionQT_API_PYQTQT_API_PYQTv1r/   QT_API_PYSIDE2QT_API_PYQT5r)   r   r   r#   r#   B   s_     $?a  	CKK	'	S[[	(	3;;	&r   c                 (   t         dt        dt        dt        dt        dt
        di}||    }ddl}	 t        |      }dD ]$  }|j                  j                  |d|      $ y	 | t         k(  rt        |j                  d
      S y# t        $ r Y y	w xY w)a1  Safely check for PyQt4 or PySide, without importing
       submodules

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

       Returns
       -------
       True if the relevant module appears to be importable
    r-   r.   r+   r,   r   N)QtCoreQtGuiQtSvg.Fz1.0.3T)r/   r8   r6   r7   QT_API_PYQT_DEFAULTr9   	importlib
__import__util	find_specr   __version__r"   )r1   r   r@   modchecks        r   has_bindingrG   Z   s      !(!9 '&K c"K% 2 	E~~'';(FGO	
 - ':: s   0B "B $B 	BBc                  l    	 ddl } 	 | j                  d      S # t        $ r Y yw xY w# t        $ r Y y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QString)sipr"   getapi
ValueError)rJ   s    r   r5   r5      sE    zz)$$    s    ' 	$$	33c                 t    t        |       syt               }| t        k(  r|t        t        t
        dfv S || dfv S )z?Safely query whether an API is importable, without importing itFN)rG   r#   r?   r6   r7   r9   )r1   currents     r   
can_importrO      s@    slG
!!;|TJJJ3+%%r   c                 Z   ddl }| $|j                  d|        |j                  d|        ddlm}m}m} t        |j                  d      st        d|j                  z        |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   NrI   QVariantr<   r;   r=   z4.7z'IPython requires PyQt4 >= 4.7, found %s   )rJ   setapir+   r<   r;   r=   r   PYQT_VERSION_STRr"   
pyqtSignalSignalpyqtSlotSlotrK   r7   r6   )versionrJ   r<   r;   r=   r1   s         r   import_pyqt4r[      s     

9g&

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

    ImportErrors raised within this function are non-recoverable
    r   rR   )	r,   r<   r;   r=   rV   rW   rX   rY   r9   rR   s      r   import_pyqt5r]      s3     +* %%FM//FK5%--r   c                  *    ddl m} m}m} || |t        fS )zY
    Import PySide

    ImportErrors raised within this function are non-recoverable
    r   rR   )r-   r<   r;   r=   r/   rR   s      r   import_pysider_      s     ,+5%..r   c                  *    ddl m} m}m} || |t        fS )zZ
    Import PySide2

    ImportErrors raised within this function are non-recoverable
    r   rR   )r.   r<   r;   r=   r/   rR   s      r   import_pyside2ra      s     -,5%..r   c                 6   t         t        t        t        t        t
        t        t        t
        d      t        t        t
        d      t        t        i}| D ]g  }||vr8t        d|dt         dt         dt        dt        dt        dt              t        |      sK ||          }|d   }t        |       |c S  t        dt               d	t!        t              d
t!        t              dt!        t               dt!        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',
        'pyqt', and 'pyqtv1'

    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 becaues they aren't installed, or because
    an incompatible library has already been installed)
    rS   )rZ   NzInvalid Qt API z, valid values are: z, z
    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7 or PySide >= 1.0.3 is available,
    and only one is imported per session.

    Currently-imported Qt library:   z&
    PyQt4 installed:                 z&
    PyQt5 installed:                 z&
    PySide >= 1.0.3 installed:       z&
    PySide2 installed:               z&
    Tried to load:                   r!   )r/   r_   r8   ra   r6   r[   r7   r   r?   r9   r]   RuntimeErrorrO   r2   r"   r#   rG   )api_optionsloadersr1   results       r   load_qtrh      s    4 m~LglA>"GL$$G\G  !gm]K 3\CD D
 # Rj3!"  <{#|$}%~&!  	r   )r4   )r(   r   	functoolsr   pydev_ipython.versionr   r6   r7   r?   r/   r8   r9   objectr   r0   	meta_pathappendr2   r#   rG   r5   rO   r[   r]   r_   ra   rh   r)   r   r   <module>rn      s   	   / # $6 $2 ^   R 	0)X"	&"%J.//Cr   