ó
ćNXc           @   să   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
 e f d     YZ 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 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   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(    (    sS   /data/av2000/mvv/env_mvv/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(    (    sS   /data/av2000/mvv/env_mvv/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(    (    sS   /data/av2000/mvv/env_mvv/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   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   load_module+   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/external/qt_loaders.pyR      s
   		c         C   sp   |  t  k r) t j d  t j d  nC |  t k rR t j d  t j d  n t j d  t j d  d S(   s[   Commit to a particular API, and trigger ImportErrors on subsequent
       dangerous importst   PyQt4t   PyQt5t   PySideN(   t   QT_API_PYSIDEt   IDR   t   QT_API_PYQT5(   t   api(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/external/qt_loaders.pyt
   commit_api5   s    c           C   sS   d t  j k r) t   d k r" t St Sn& d t  j k r< t Sd t  j k rO 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, 'pyside', 'pyqt', or 'pyqtv1'
    s   PyQt4.QtCorei   s   PySide.QtCores   PyQt5.QtCoreN(   R   R   t   qtapi_versiont   QT_API_PYQTt   QT_API_PYQTv1R   R!   R   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/external/qt_loaders.pyR   D   s    
c         C   să   i d t  6d t 6d t 6d t 6d t 6} | |  } d d l } y t |  } | j d | j  | j d | j  | j d | j  |  t k rŠ | j d	 | j  n  |  t  k rĹ t	 | j
 d
  St SWn t k
 rŢ t SXd S(   s=  Safely check for PyQt4/5 or PySide, without importing
       submodules

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

       Returns
       -------
       True if the relevant module appears to be importable
    R   R   R   i˙˙˙˙Nt   QtCoret   QtGuit   QtSvgt	   QtWidgetss   1.0.3(   R   R%   R&   R!   t   QT_API_PYQT_DEFAULTt   impt
   __import__R   t   __path__R   t   __version__t   TrueR   t   False(   R"   R   R,   t   mod(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   has_bindingZ   s&    


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(   R5   (    (    sS   /data/av2000/mvv/env_mvv/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(   R3   R1   R   R+   R%   R&   R   (   R"   t   current(    (    sS   /data/av2000/mvv/env_mvv/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˙˙˙˙NR4   t   QVariant(   R(   R'   R)   s   4.7s'   IPython requires PyQt4 >= 4.7, found %si   (   R5   R   t   setapiR   R(   R'   R)   R   t   PYQT_VERSION_STRR   t
   pyqtSignalt   Signalt   pyqtSlott   SlotR6   R&   R%   (   t   versionR5   R(   R'   R)   R"   (    (    sS   /data/av2000/mvv/env_mvv/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(   R5   R   R'   R)   R*   R(   R=   R>   R?   R@   t   typest
   ModuleTypet   __dict__t   updateR!   (   R5   R'   R)   R*   R(   RC   R"   (    (    sS   /data/av2000/mvv/env_mvv/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)   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   import_pysideß   s    c      	   C   s	  i t  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 | ^ qv  f   n  t |  sŤ qH n  | |   } | d } t |  | SWt d 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',
        '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)
    RA   i   s'   Invalid Qt API %r, valid values are: %ss   , s   %ri˙˙˙˙sm  
    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7, PyQt5 or PySide >= 1.0.3 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
    Tried to load:                   %r
    N(   RI   R   RB   R%   RH   R!   R    R&   R   R+   t   RuntimeErrort   joint   keysR9   R#   R   R   R3   (   t   api_optionst   loadersR"   t   kt   result(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   load_qté   s,    
9


				(   R   R   RD   t	   functoolsR    t   IPython.utils.versionR   R%   R!   R&   R+   R   t   objectR   R    t	   meta_patht   appendR#   R   R3   R$   R9   RB   RH   RI   RQ   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/external/qt_loaders.pyt   <module>
   s*   				,		%		
