ó
_y]c           @   sU  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 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 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    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   LooseVersionc         C   s3   y t  |   t  |  k SWn t k
 r. t SXd S(   s   compare versionsN(   R   t	   TypeErrort   True(   t   at   b(    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   check_version   s    t   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(   s`   Import Hook that will guard against bad Qt imports
    once committed to a specific binding
    c         C   s   t    |  _ d  S(   N(   t   sett   _ImportDenier__forbidden(   t   self(    (    s3   lib/python2.7/site-packages/qtconsole/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(    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   forbid1   s    c         C   s!   | r
 d  S| |  j  k r |  Sd  S(   N(   R   (   R   t   fullnamet   path(    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   find_module5   s    c         C   s   t  d | t   f   d  S(   Nsk   
    Importing %s disabled by QtConsole, which has
    already imported an incompatible Qt Binding: %s
    (   t   ImportErrort
   loaded_api(   R   R   (    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   load_module;   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R"   (    (    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyR   )   s
   		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(    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt
   commit_apiE   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', 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   (    (    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyR!   [   s    
c         C   sŢ   t  |  } d d l } yŻ t |  } | j d t | j   | j d t | j   | j d t | j   |  t k s |  t k r¤ | j d t | j   n  |  t k rŔ t	 | j
 d  St SWn t k
 rŮ t SXd S(   sn  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   listt   __path__R)   R&   R(   R   t   __version__R   R    t   False(   R*   R   R4   t   mod(    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   has_bindings   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(
   sZ  Safely check for PyQt4/5 or PySide, without importing submodules

    Supports Python >= 3.4

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

        Returns
        -------
        True if the relevant module appears to be importable
     i˙˙˙˙(   t	   find_specR/   R0   R1   R2   s   %s.%sNs   1.0.3(   R3   t   importlib.utilR<   R)   R&   t   appendR    R9   R   R(   R   R   R8   R   (   R*   R   R<   t   requiredt   submodt   specR   (    (    s3   lib/python2.7/site-packages/qtconsole/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(   RD   (    (    s3   lib/python2.7/site-packages/qtconsole/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(   R;   R9   R!   t   QT_API_PYQT_DEFAULTR-   R.   R   (   R*   t   current(    (    s3   lib/python2.7/site-packages/qtconsole/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˙˙˙˙NRC   t   QVariant(   R0   R/   R1   s   4.7s)   QtConsole requires PyQt4 >= 4.7, found %si   (   RD   R   t   setapiR   R0   R/   R1   R   t   PYQT_VERSION_STRR    t
   pyqtSignalt   Signalt   pyqtSlott   SlotRE   R.   R-   (   t   versionRD   R0   R/   R1   R*   (    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   import_pyqt4ă   s    c          C   sŞ   d d l  m }  m } m } m } m } d d l } |  j |  _ |  j	 |  _
 t j d  } | j j | j  | j j | j  | j j | j  t } |  | | | f S(   sX   
    Import PyQt5

    ImportErrors rasied within this function are non-recoverable
    i˙˙˙˙(   R/   R1   R2   R0   t   QtPrintSupportNt   QtGuiCompat(   R   R/   R1   R2   R0   RS   RD   RM   RN   RO   RP   t   typest
   ModuleTypet   __dict__t   updateR)   (   R/   R1   R2   R0   RS   RD   RT   R*   (    (    s3   lib/python2.7/site-packages/qtconsole/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˙˙˙˙(   R0   R/   R1   (   R   R0   R/   R1   R(   (   R0   R/   R1   (    (    s3   lib/python2.7/site-packages/qtconsole/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˙˙˙˙(   R0   R/   R1   R2   RS   RT   (   R   R0   R/   R1   R2   RS   RU   RV   RW   RX   R&   (   R0   R/   R1   R2   RS   RT   (    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   import_pyside2+  s    (c      	   C   s1  i t  t 6t t 6t t 6t t 6t t d d t	 6t t d d t 6} t   } | rc | g }  n  xÇ |  D] } | | k rť t d | d j g  | j   D] } d | ^ q  f   n  t |  sÍ qj n  | |   } | d } t |  | SWt d | t t  t t  t t  t t  |  f   d S(	   sĎ  
    Import Qt, given a preference list of permissible bindings.

    It is safe to call this function multiple times.  If a Qt binding
    has already been loaded, it will be returned regardless of the
    preference list.

    Parameters
    ----------
    api_options: List of strings
        The order of APIs to try. Valid items are 'pyside2', 'pyside', '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
    (because they aren't installed).
    RQ   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 installed:                 %s
    PyQt5 installed:                 %s
    PySide >= 1.0.3 installed:       %s
    PySide2 installed:               %s
    Tried to load:                   %r
    N(   R[   R&   RZ   R(   RR   R-   RY   R)   R    R.   R   RG   R!   t   RuntimeErrort   joint   keysRI   R+   R    R;   (   t   api_optionst   loaderst   loadedR*   t   kt   result(    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   load_qt<  s6    
	9

				c          C   sz   t    }  |  t k r( d d l m } nN |  t k rG d d l m } n/ |  t k rf d d l m } n d d l m } | S(   s)   Load QTest module from the loaded QT API.i˙˙˙˙(   t   QTest(	   R!   R)   t   PyQt5.QtTestRe   R(   t   PySide.QtTestR&   t   PySide2.QtTestt   PyQt4.QtTest(   R*   Re   (    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt
   load_qtest  s    	(   i   i   (!   R%   R   RU   t	   functoolsR    t   distutils.versionR   R   R-   R)   R.   RG   R(   R&   R3   t   objectR   R'   t	   meta_pathR>   R+   R!   R;   RB   t   version_infoR,   RI   RR   RY   RZ   R[   Rd   Rj   (    (    (    s3   lib/python2.7/site-packages/qtconsole/qt_loaders.pyt   <module>
   sD   		

				(	(			%		
		I