()
Initialise PyQt4
Initialise PyQt4
Initialise PyQt4
def _pyqt4():
    """Initialise PyQt4"""

    import sip

    # Validation of envivornment variable. Prevents an error if
    # the variable is invalid since it's just a hint.
    try:
        hint = int(QT_SIP_API_HINT)
    except TypeError:
        hint = None  # Variable was None, i.e. not set.
    except ValueError:
        raise ImportError("QT_SIP_API_HINT=%s must be a 1 or 2")

    for api in ("QString",
                "QVariant",
                "QDate",
                "QDateTime",
                "QTextStream",
                "QTime",
                "QUrl"):
        try:
            sip.setapi(api, hint or 2)
        except AttributeError:
            raise ImportError("PyQt4 < 4.6 isn't supported by Qt.py")
        except ValueError:
            actual = sip.getapi(api)
            if not hint:
                raise ImportError("API version already set to %d" % actual)
            else:
                # Having provided a hint indicates a soft constraint, one
                # that doesn't throw an exception.
                sys.stderr.write(
                    "Warning: API '%s' has already been set to %d.\n"
                    % (api, actual)
                )

    import PyQt4 as module
    extras = ["uic"]
    try:
        import sip
        extras.append(sip.__name__)
    except ImportError:
        sip = None

    _setup(module, extras)
    if hasattr(Qt, "_sip"):
        Qt.QtCompat.wrapInstance = _wrapinstance
        Qt.QtCompat.getCppPointer = _getcpppointer
        Qt.QtCompat.delete = sip.delete

    if hasattr(Qt, "_uic"):
        Qt.QtCompat.loadUi = _loadUi

    if hasattr(Qt, "_QtGui"):
        setattr(Qt, "QtWidgets", _new_module("QtWidgets"))
        setattr(Qt, "_QtWidgets", Qt._QtGui)
        if hasattr(Qt._QtGui, "QX11Info"):
            setattr(Qt, "QtX11Extras", _new_module("QtX11Extras"))
            Qt.QtX11Extras.QX11Info = Qt._QtGui.QX11Info

        Qt.QtCompat.setSectionResizeMode = \
            Qt._QtGui.QHeaderView.setResizeMode

    if hasattr(Qt, "_QtCore"):
        Qt.__binding_version__ = Qt._QtCore.PYQT_VERSION_STR
        Qt.__qt_version__ = Qt._QtCore.QT_VERSION_STR

    _reassign_misplaced_members("PyQt4")

    # QFileDialog QtCompat decorator
    def _standardizeQFileDialog(some_function):
        """Decorator that makes PyQt4 return conform to other bindings"""
        def wrapper(*args, **kwargs):
            ret = (some_function(*args, **kwargs))

            # PyQt4 only returns the selected filename, force it to a
            # standard return of the selected filename, and a empty string
            # for the selected filter
            return ret, ''

        wrapper.__doc__ = some_function.__doc__
        wrapper.__name__ = some_function.__name__

        return wrapper

    decorators = {
        "QFileDialog": {
            "getOpenFileName": _standardizeQFileDialog,
            "getOpenFileNames": _standardizeQFileDialog,
            "getSaveFileName": _standardizeQFileDialog,
        }
    }
    _build_compatibility_members('PyQt4', decorators)
def _pyqt4 ( ) : import sip # Validation of envivornment variable. Prevents an error if # the variable is invalid since it's just a hint. try : hint = int ( QT_SIP_API_HINT ) except TypeError : hint = None # Variable was None, i.e. not set. except ValueError : raise ImportError ( "QT_SIP_API_HINT=%s must be a 1 or 2" ) for api in ( "QString" , "QVariant" , "QDate" , "QDateTime" , "QTextStream" , "QTime" , "QUrl" ) : try : sip . setapi ( api , hint or 2 ) except AttributeError : raise ImportError ( "PyQt4 < 4.6 isn't supported by Qt.py" ) except ValueError : actual = sip . getapi ( api ) if not hint : raise ImportError ( "API version already set to %d" % actual ) else : # Having provided a hint indicates a soft constraint, one # that doesn't throw an exception. sys . stderr . write ( "Warning: API '%s' has already been set to %d.\n" % ( api , actual ) ) import PyQt4 as module extras = [ "uic" ] try : import sip extras . append ( sip . __name__ ) except ImportError : sip = None _setup ( module , extras ) if hasattr ( Qt , "_sip" ) : Qt . QtCompat . wrapInstance = _wrapinstance Qt . QtCompat . getCppPointer = _getcpppointer Qt . QtCompat . delete = sip . delete if hasattr ( Qt , "_uic" ) : Qt . QtCompat . loadUi = _loadUi if hasattr ( Qt , "_QtGui" ) : setattr ( Qt , "QtWidgets" , _new_module ( "QtWidgets" ) ) setattr ( Qt , "_QtWidgets" , Qt . _QtGui ) if hasattr ( Qt . _QtGui , "QX11Info" ) : setattr ( Qt , "QtX11Extras" , _new_module ( "QtX11Extras" ) ) Qt . QtX11Extras . QX11Info = Qt . _QtGui . QX11Info Qt . QtCompat . setSectionResizeMode = Qt . _QtGui . QHeaderView . setResizeMode if hasattr ( Qt , "_QtCore" ) : Qt . __binding_version__ = Qt . _QtCore . PYQT_VERSION_STR Qt . __qt_version__ = Qt . _QtCore . QT_VERSION_STR _reassign_misplaced_members ( "PyQt4" ) # QFileDialog QtCompat decorator def _standardizeQFileDialog ( some_function ) : """Decorator that makes PyQt4 return conform to other bindings""" def wrapper ( * args , * * kwargs ) : ret = ( some_function ( * args , * * kwargs ) ) # PyQt4 only returns the selected filename, force it to a # standard return of the selected filename, and a empty string # for the selected filter return ret , '' wrapper . __doc__ = some_function . __doc__ wrapper . __name__ = some_function . __name__ return wrapper decorators = { "QFileDialog" : { "getOpenFileName" : _standardizeQFileDialog , "getOpenFileNames" : _standardizeQFileDialog , "getSaveFileName" : _standardizeQFileDialog , } } _build_compatibility_members ( 'PyQt4' , decorators )