ó
&9_[c           @   sF  d  Z  d d l 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 i d e 6d e 6d e 6d e	 6d e 6d e
 6Z d e f d     YZ e   Z e j j d e  d   Z d   Z d   Z d   Z e j d  k r e Z n  d   Z d   Z d d  Z d   Z d   Z d   Z d   Z d S(!   sD  
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
i˙˙˙˙N(   t   partial(   t   check_versiont   pyqtt   pyqt5t   pyqtv1t   pyqtdefaultt   pysidet   pyside2t   PySide2t   PySidet   PyQt4t   PyQt5t   ImportDenierc           B   s5   e  Z d  Z d   Z d   Z d d  Z d   Z RS(   sf   Import Hook that will guard against bad Qt imports
    once IPython commits to a specific binding
    c         C   s   t    |  _ d  S(   N(   t   sett   _ImportDenier__forbidden(   t   self(    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   __init__'   s    c         C   s'   t  j j | d   |  j j |  d  S(   N(   t   syst   modulest   popt   NoneR   t   add(   R   t   module_name(    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   forbid*   s    c         C   s!   | r
 d  S| |  j  k r |  Sd  S(   N(   R   (   R   t   fullnamet   path(    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   find_module.   s    c         C   s   t  d | t   f   d  S(   Nsi   
    Importing %s disabled by IPython, which has
    already imported an Incompatible QT Binding: %s
    (   t   ImportErrort
   loaded_api(   R   R   (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   load_module4   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyR   "   s
   		i    c         C   sÍ   |  t  k r6 t j d  t j d  t j d  n  |  t k rl t j d  t j d  t j d  n] |  t k r˘ t j d  t j d  t j d  n' t j d  t j d  t j d  d S(   s[   Commit to a particular API, and trigger ImportErrors on subsequent
       dangerous importsR	   R
   R   R   N(   t   QT_API_PYSIDE2t   IDR   t   QT_API_PYSIDEt   QT_API_PYQT5(   t   api(    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt
   commit_api>   s    c           C   sf   d t  j k r) t   d k r" t St Sn9 d t  j k r< t Sd t  j k rO t Sd t  j k rb t Sd S(   sÖ   Return which API is loaded, if any

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

    Returns
    -------
    None, 'pyside2', 'pyside', 'pyqt', 'pyqt5', or 'pyqtv1'
    s   PyQt4.QtCorei   s   PySide.QtCores   PySide2.QtCores   PyQt5.QtCoreN(	   R   R   t   qtapi_versiont   QT_API_PYQTt   QT_API_PYQTv1R#   R!   R$   R   (    (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyR   T   s    
c         C   sŔ   t  |  } d d l } y t |  } | j d | j  | j d | j  | j d | j  |  t t f k r | j d | j  n  |  t k r˘ t | j	 d  St
 SWn t k
 rť t SXd S(   sg  Safely check for PyQt4/5, PySide or PySide2, without importing submodules

    Supports Python <= 3.3

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

       Returns
       -------
       True if the relevant module appears to be importable
    i˙˙˙˙Nt   QtCoret   QtGuit   QtSvgt	   QtWidgetss   1.0.3(   t   api_to_modulet   impt
   __import__R   t   __path__R$   R!   R#   R   t   __version__t   TrueR   t   False(   R%   R   R/   t   mod(    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   has_bindingl   s    
c         C   sÇ   t  |  } d d l m } d d d g } |  t t f k rK | j d  n  xM | D]E } y | d | | f  } Wn t k
 r t SX| d k rR t SqR W|  t	 k rĂ d d l
 } t | j d	  St S(
   so  Safely check for PyQt4/5, PySide or PySide2, without importing submodules

    Supports Python >= 3.4

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

        Returns
        -------
        True if the relevant module appears to be importable
     i˙˙˙˙(   t	   find_specR*   R+   R,   R-   s   %s.%sNs   1.0.3(   R.   t   importlib.utilR7   R$   R!   t   appendR   R4   R   R#   R	   R   R2   R3   (   R%   R   R7   t   requiredt   submodt   specR	   (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   has_binding_new   s     
i   i   c          C   sO   y d d l  }  Wn t k
 r$ d SXy |  j d  SWn t k
 rJ d SXd S(   s   Return which QString API has been set, if any

    Returns
    -------
    The QString API version (1 or 2), or None if not set
    i˙˙˙˙Nt   QString(   t   sipR   t   getapit
   ValueError(   R?   (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyR'   ž   s    c         C   sL   t  |   s t St   } |  t k r8 | t t d g k S| |  d g k Sd S(   s?   Safely query whether an API is importable, without importing itN(   R6   R4   R   t   QT_API_PYQT_DEFAULTR(   R)   R   (   R%   t   current(    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt
   can_importĎ   s    	i   c         C   sÎ   d d l  } |  d k	 r; | j d |   | j d |   n  d d l m } m } m } t | j d  s t	 d | j   n  | j
 | _ | j | _ | j d  }  |  d k r¸ t n t } | | | | f S(	   sč   
    Import PyQt4

    Parameters
    ----------
    version : 1, 2, or None
      Which QString/QVariant API to use. Set to None to use the system
      default

    ImportErrors rasied within this function are non-recoverable
    i˙˙˙˙NR>   t   QVariant(   R+   R*   R,   s   4.7s'   IPython requires PyQt4 >= 4.7, found %si   (   R?   R   t   setapiR
   R+   R*   R,   R   t   PYQT_VERSION_STRR   t
   pyqtSignalt   Signalt   pyqtSlott   SlotR@   R)   R(   (   t   versionR?   R+   R*   R,   R%   (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   import_pyqt4Ű   s    c          C   s   d d l  }  d d l m } m } m } m } | j | _ | j | _	 t
 j d  } | j j | j  | j j | j  t } | | | | f S(   sX   
    Import PyQt5

    ImportErrors rasied within this function are non-recoverable
    i˙˙˙˙N(   R*   R,   R-   R+   t   QtGuiCompat(   R?   R   R*   R,   R-   R+   RH   RI   RJ   RK   t   typest
   ModuleTypet   __dict__t   updateR$   (   R?   R*   R,   R-   R+   RN   R%   (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   import_pyqt5   s    "c          C   s,   d d l  m }  m } m } | |  | t f S(   sY   
    Import PySide

    ImportErrors raised within this function are non-recoverable
    i˙˙˙˙(   R+   R*   R,   (   R	   R+   R*   R,   R#   (   R+   R*   R,   (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   import_pyside  s    c          C   s   d d l  m }  m } m } m } m } t j d  } | j j	 |  j  | j j	 | j  | j j	 | j  | | | t
 f S(   sZ   
    Import PySide2

    ImportErrors raised within this function are non-recoverable
    i˙˙˙˙(   R+   R*   R,   R-   t   QtPrintSupportRN   (   R   R+   R*   R,   R-   RU   RO   RP   RQ   RR   R!   (   R+   R*   R,   R-   RU   RN   (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   import_pyside2   s    (c      	   C   s  i t  t 6t t 6t t 6t t 6t t d d t	 6t t d d t 6} xĘ |  D] } | | k r  t d | d j g  | j   D] } d | ^ q}  f   n  t |  s˛ qO n  | |   } | d } t |  | SWt d t   t t  t t  t t  t t  |  f   d S(	   s˝  
    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 becaues they aren't installed, or because
    an incompatible library has already been installed)
    RL   i   s'   Invalid Qt API %r, valid values are: %ss   , s   %ri˙˙˙˙s@  
    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
    N(   RV   R!   RT   R#   RM   R(   RS   R$   R    R)   R   RB   t   RuntimeErrort   joint   keysRD   R&   R   R   R6   (   t   api_optionst   loadersR%   t   kt   result(    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   load_qt1  s2    9

					(   i   i   (   R    R   RO   t	   functoolsR    t   IPython.utils.versionR   R(   R$   R)   RB   R#   R!   R.   t   objectR   R"   t	   meta_patht   insertR&   R   R6   R=   t   version_infoR'   RD   RM   RS   RT   RV   R^   (    (    (    s:   lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   <module>
   s@   

				'	(			%				