Uploaded Test files

This commit is contained in:
Batuhan Berk Başoğlu 2020-11-12 11:05:57 -05:00
parent f584ad9d97
commit 2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides Qt3DAnimation classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError, PYSIDE_VERSION
from .py3compat import PY2
if PYQT5:
from PyQt5.Qt3DAnimation import *
elif PYSIDE2:
if not PY2 or (PY2 and PYSIDE_VERSION < '5.12.4'):
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026
import PySide2.Qt3DAnimation as __temp
import inspect
for __name in inspect.getmembers(__temp.Qt3DAnimation):
globals()[__name[0]] = __name[1]
else:
raise PythonQtError('A bug in Shiboken prevents this')
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides Qt3DCore classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError, PYSIDE_VERSION
from .py3compat import PY2
if PYQT5:
from PyQt5.Qt3DCore import *
elif PYSIDE2:
if not PY2 or (PY2 and PYSIDE_VERSION < '5.12.4'):
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026
import PySide2.Qt3DCore as __temp
import inspect
for __name in inspect.getmembers(__temp.Qt3DCore):
globals()[__name[0]] = __name[1]
else:
raise PythonQtError('A bug in Shiboken prevents this')
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides Qt3DExtras classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError, PYSIDE_VERSION
from .py3compat import PY2
if PYQT5:
from PyQt5.Qt3DExtras import *
elif PYSIDE2:
if not PY2 or (PY2 and PYSIDE_VERSION < '5.12.4'):
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026
import PySide2.Qt3DExtras as __temp
import inspect
for __name in inspect.getmembers(__temp.Qt3DExtras):
globals()[__name[0]] = __name[1]
else:
raise PythonQtError('A bug in Shiboken prevents this')
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides Qt3DInput classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError, PYSIDE_VERSION
from .py3compat import PY2
if PYQT5:
from PyQt5.Qt3DInput import *
elif PYSIDE2:
if not PY2 or (PY2 and PYSIDE_VERSION < '5.12.4'):
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026
import PySide2.Qt3DInput as __temp
import inspect
for __name in inspect.getmembers(__temp.Qt3DInput):
globals()[__name[0]] = __name[1]
else:
raise PythonQtError('A bug in Shiboken prevents this')
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides Qt3DLogic classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError, PYSIDE_VERSION
from .py3compat import PY2
if PYQT5:
from PyQt5.Qt3DLogic import *
elif PYSIDE2:
if not PY2 or (PY2 and PYSIDE_VERSION < '5.12.4'):
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026
import PySide2.Qt3DLogic as __temp
import inspect
for __name in inspect.getmembers(__temp.Qt3DLogic):
globals()[__name[0]] = __name[1]
else:
raise PythonQtError('A bug in Shiboken prevents this')
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides Qt3DRender classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError, PYSIDE_VERSION
from .py3compat import PY2
if PYQT5:
from PyQt5.Qt3DRender import *
elif PYSIDE2:
if not PY2 or (PY2 and PYSIDE_VERSION < '5.12.4'):
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026
import PySide2.Qt3DRender as __temp
import inspect
for __name in inspect.getmembers(__temp.Qt3DRender):
globals()[__name[0]] = __name[1]
else:
raise PythonQtError('A bug in Shiboken prevents this')
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2019- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtChart classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
if PYQT5:
try:
from PyQt5 import QtChart as QtCharts
except ImportError:
raise PythonQtError('The QtChart module was not found. '
'It needs to be installed separately for PyQt5.')
elif PYSIDE2:
from PySide2.QtCharts import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2014-2015 Colin Duquesnoy
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
Provides QtCore classes and functions.
"""
from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
if PYQT5:
from PyQt5.QtCore import *
from PyQt5.QtCore import pyqtSignal as Signal
from PyQt5.QtCore import pyqtSlot as Slot
from PyQt5.QtCore import pyqtProperty as Property
from PyQt5.QtCore import QT_VERSION_STR as __version__
# For issue #153
from PyQt5.QtCore import QDateTime
QDateTime.toPython = QDateTime.toPyDateTime
# Those are imported from `import *`
del pyqtSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR
elif PYSIDE2:
from PySide2.QtCore import *
try: # may be limited to PySide-5.11a1 only
from PySide2.QtGui import QStringListModel
except:
pass
import PySide2.QtCore
__version__ = PySide2.QtCore.__version__
elif PYQT4:
from PyQt4.QtCore import *
# Those are things we inherited from Spyder that fix crazy crashes under
# some specific situations. (See #34)
from PyQt4.QtCore import QCoreApplication
from PyQt4.QtCore import Qt
from PyQt4.QtCore import pyqtSignal as Signal
from PyQt4.QtCore import pyqtSlot as Slot
from PyQt4.QtCore import pyqtProperty as Property
from PyQt4.QtGui import (QItemSelection, QItemSelectionModel,
QItemSelectionRange, QSortFilterProxyModel,
QStringListModel)
from PyQt4.QtCore import QT_VERSION_STR as __version__
from PyQt4.QtCore import qInstallMsgHandler as qInstallMessageHandler
# QDesktopServices has has been split into (QDesktopServices and
# QStandardPaths) in Qt5
# This creates a dummy class that emulates QStandardPaths
from PyQt4.QtGui import QDesktopServices as _QDesktopServices
class QStandardPaths():
StandardLocation = _QDesktopServices.StandardLocation
displayName = _QDesktopServices.displayName
DesktopLocation = _QDesktopServices.DesktopLocation
DocumentsLocation = _QDesktopServices.DocumentsLocation
FontsLocation = _QDesktopServices.FontsLocation
ApplicationsLocation = _QDesktopServices.ApplicationsLocation
MusicLocation = _QDesktopServices.MusicLocation
MoviesLocation = _QDesktopServices.MoviesLocation
PicturesLocation = _QDesktopServices.PicturesLocation
TempLocation = _QDesktopServices.TempLocation
HomeLocation = _QDesktopServices.HomeLocation
DataLocation = _QDesktopServices.DataLocation
CacheLocation = _QDesktopServices.CacheLocation
writableLocation = _QDesktopServices.storageLocation
# Those are imported from `import *`
del pyqtSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR, qInstallMsgHandler
elif PYSIDE:
from PySide.QtCore import *
from PySide.QtGui import (QItemSelection, QItemSelectionModel,
QItemSelectionRange, QSortFilterProxyModel,
QStringListModel)
from PySide.QtCore import qInstallMsgHandler as qInstallMessageHandler
del qInstallMsgHandler
# QDesktopServices has has been split into (QDesktopServices and
# QStandardPaths) in Qt5
# This creates a dummy class that emulates QStandardPaths
from PySide.QtGui import QDesktopServices as _QDesktopServices
class QStandardPaths():
StandardLocation = _QDesktopServices.StandardLocation
displayName = _QDesktopServices.displayName
DesktopLocation = _QDesktopServices.DesktopLocation
DocumentsLocation = _QDesktopServices.DocumentsLocation
FontsLocation = _QDesktopServices.FontsLocation
ApplicationsLocation = _QDesktopServices.ApplicationsLocation
MusicLocation = _QDesktopServices.MusicLocation
MoviesLocation = _QDesktopServices.MoviesLocation
PicturesLocation = _QDesktopServices.PicturesLocation
TempLocation = _QDesktopServices.TempLocation
HomeLocation = _QDesktopServices.HomeLocation
DataLocation = _QDesktopServices.DataLocation
CacheLocation = _QDesktopServices.CacheLocation
writableLocation = _QDesktopServices.storageLocation
import PySide.QtCore
__version__ = PySide.QtCore.__version__
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtDataVisualization classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
if PYQT5:
from PyQt5.QtDataVisualization import *
elif PYSIDE2:
# https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026
import PySide2.QtDataVisualization as __temp
import inspect
for __name in inspect.getmembers(__temp.QtDataVisualization):
globals()[__name[0]] = __name[1]
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2014-2015 Colin Duquesnoy
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
Provides QtDesigner classes and functions.
"""
from . import PYQT5, PYQT4, PythonQtError
if PYQT5:
from PyQt5.QtDesigner import *
elif PYQT4:
from PyQt4.QtDesigner import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,157 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2014-2015 Colin Duquesnoy
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
Provides QtGui classes and functions.
.. warning:: Only PyQt4/PySide QtGui classes compatible with PyQt5.QtGui are
exposed here. Therefore, you need to treat/use this package as if it were
the ``PyQt5.QtGui`` module.
"""
import warnings
from . import PYQT5, PYQT4, PYSIDE, PYSIDE2, PythonQtError
if PYQT5:
from PyQt5.QtGui import *
elif PYSIDE2:
from PySide2.QtGui import *
elif PYQT4:
try:
# Older versions of PyQt4 do not provide these
from PyQt4.QtGui import (QGlyphRun, QMatrix2x2, QMatrix2x3,
QMatrix2x4, QMatrix3x2, QMatrix3x3,
QMatrix3x4, QMatrix4x2, QMatrix4x3,
QMatrix4x4, QTouchEvent, QQuaternion,
QRadialGradient, QRawFont, QStaticText,
QVector2D, QVector3D, QVector4D,
qFuzzyCompare)
except ImportError:
pass
from PyQt4.Qt import QKeySequence, QTextCursor
from PyQt4.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
QBrush, QClipboard, QCloseEvent, QColor,
QConicalGradient, QContextMenuEvent, QCursor,
QDoubleValidator, QDrag,
QDragEnterEvent, QDragLeaveEvent, QDragMoveEvent,
QDropEvent, QFileOpenEvent, QFocusEvent, QFont,
QFontDatabase, QFontInfo, QFontMetrics,
QFontMetricsF, QGradient, QHelpEvent,
QHideEvent, QHoverEvent, QIcon, QIconDragEvent,
QIconEngine, QImage, QImageIOHandler, QImageReader,
QImageWriter, QInputEvent, QInputMethodEvent,
QKeyEvent, QLinearGradient,
QMouseEvent, QMoveEvent, QMovie,
QPaintDevice, QPaintEngine, QPaintEngineState,
QPaintEvent, QPainter, QPainterPath,
QPainterPathStroker, QPalette, QPen, QPicture,
QPictureIO, QPixmap, QPixmapCache, QPolygon,
QPolygonF, QRegExpValidator, QRegion, QResizeEvent,
QSessionManager, QShortcutEvent, QShowEvent,
QStandardItem, QStandardItemModel,
QStatusTipEvent, QSyntaxHighlighter, QTabletEvent,
QTextBlock, QTextBlockFormat, QTextBlockGroup,
QTextBlockUserData, QTextCharFormat,
QTextDocument, QTextDocumentFragment,
QTextDocumentWriter, QTextFormat, QTextFragment,
QTextFrame, QTextFrameFormat, QTextImageFormat,
QTextInlineObject, QTextItem, QTextLayout,
QTextLength, QTextLine, QTextList, QTextListFormat,
QTextObject, QTextObjectInterface, QTextOption,
QTextTable, QTextTableCell, QTextTableCellFormat,
QTextTableFormat, QTransform,
QValidator, QWhatsThisClickedEvent, QWheelEvent,
QWindowStateChangeEvent, qAlpha, qBlue,
qGray, qGreen, qIsGray, qRed, qRgb,
qRgba, QIntValidator)
# QDesktopServices has has been split into (QDesktopServices and
# QStandardPaths) in Qt5
# It only exposes QDesktopServices that are still in pyqt5
from PyQt4.QtGui import QDesktopServices as _QDesktopServices
class QDesktopServices():
openUrl = _QDesktopServices.openUrl
setUrlHandler = _QDesktopServices.setUrlHandler
unsetUrlHandler = _QDesktopServices.unsetUrlHandler
def __getattr__(self, name):
attr = getattr(_QDesktopServices, name)
new_name = name
if name == 'storageLocation':
new_name = 'writableLocation'
warnings.warn(("Warning QDesktopServices.{} is deprecated in Qt5"
"we recommend you use QDesktopServices.{} instead").format(name, new_name),
DeprecationWarning)
return attr
QDesktopServices = QDesktopServices()
elif PYSIDE:
from PySide.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
QBrush, QClipboard, QCloseEvent, QColor,
QConicalGradient, QContextMenuEvent, QCursor,
QDoubleValidator, QDrag,
QDragEnterEvent, QDragLeaveEvent, QDragMoveEvent,
QDropEvent, QFileOpenEvent, QFocusEvent, QFont,
QFontDatabase, QFontInfo, QFontMetrics,
QFontMetricsF, QGradient, QHelpEvent,
QHideEvent, QHoverEvent, QIcon, QIconDragEvent,
QIconEngine, QImage, QImageIOHandler, QImageReader,
QImageWriter, QInputEvent, QInputMethodEvent,
QKeyEvent, QKeySequence, QLinearGradient,
QMatrix2x2, QMatrix2x3, QMatrix2x4, QMatrix3x2,
QMatrix3x3, QMatrix3x4, QMatrix4x2, QMatrix4x3,
QMatrix4x4, QMouseEvent, QMoveEvent, QMovie,
QPaintDevice, QPaintEngine, QPaintEngineState,
QPaintEvent, QPainter, QPainterPath,
QPainterPathStroker, QPalette, QPen, QPicture,
QPictureIO, QPixmap, QPixmapCache, QPolygon,
QPolygonF, QQuaternion, QRadialGradient,
QRegExpValidator, QRegion, QResizeEvent,
QSessionManager, QShortcutEvent, QShowEvent,
QStandardItem, QStandardItemModel,
QStatusTipEvent, QSyntaxHighlighter, QTabletEvent,
QTextBlock, QTextBlockFormat, QTextBlockGroup,
QTextBlockUserData, QTextCharFormat, QTextCursor,
QTextDocument, QTextDocumentFragment,
QTextFormat, QTextFragment,
QTextFrame, QTextFrameFormat, QTextImageFormat,
QTextInlineObject, QTextItem, QTextLayout,
QTextLength, QTextLine, QTextList, QTextListFormat,
QTextObject, QTextObjectInterface, QTextOption,
QTextTable, QTextTableCell, QTextTableCellFormat,
QTextTableFormat, QTouchEvent, QTransform,
QValidator, QVector2D, QVector3D, QVector4D,
QWhatsThisClickedEvent, QWheelEvent,
QWindowStateChangeEvent, qAlpha, qBlue,
qGray, qGreen, qIsGray, qRed, qRgb, qRgba,
QIntValidator)
# QDesktopServices has has been split into (QDesktopServices and
# QStandardPaths) in Qt5
# It only exposes QDesktopServices that are still in pyqt5
from PySide.QtGui import QDesktopServices as _QDesktopServices
class QDesktopServices():
openUrl = _QDesktopServices.openUrl
setUrlHandler = _QDesktopServices.setUrlHandler
unsetUrlHandler = _QDesktopServices.unsetUrlHandler
def __getattr__(self, name):
attr = getattr(_QDesktopServices, name)
new_name = name
if name == 'storageLocation':
new_name = 'writableLocation'
warnings.warn(("Warning QDesktopServices.{} is deprecated in Qt5"
"we recommend you use QDesktopServices.{} instead").format(name, new_name),
DeprecationWarning)
return attr
QDesktopServices = QDesktopServices()
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""QtHelp Wrapper."""
import warnings
from . import PYQT5
from . import PYQT4
from . import PYSIDE
from . import PYSIDE2
if PYQT5:
from PyQt5.QtHelp import *
elif PYSIDE2:
from PySide2.QtHelp import *
elif PYQT4:
from PyQt4.QtHelp import *
elif PYSIDE:
from PySide.QtHelp import *

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtLocation classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
if PYQT5:
from PyQt5.QtLocation import *
elif PYSIDE2:
from PySide2.QtLocation import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,17 @@
import warnings
from . import PYQT5
from . import PYQT4
from . import PYSIDE
from . import PYSIDE2
if PYQT5:
from PyQt5.QtMultimedia import *
elif PYSIDE2:
from PySide2.QtMultimedia import *
elif PYQT4:
from PyQt4.QtMultimedia import *
from PyQt4.QtGui import QSound
elif PYSIDE:
from PySide.QtMultimedia import *
from PySide.QtGui import QSound

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtMultimediaWidgets classes and functions."""
# Local imports
from . import PYSIDE2, PYQT5, PythonQtError
if PYQT5:
from PyQt5.QtMultimediaWidgets import *
elif PYSIDE2:
from PySide2.QtMultimediaWidgets import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2014-2015 Colin Duquesnoy
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
Provides QtNetwork classes and functions.
"""
from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
if PYQT5:
from PyQt5.QtNetwork import *
elif PYSIDE2:
from PySide2.QtNetwork import *
elif PYQT4:
from PyQt4.QtNetwork import *
elif PYSIDE:
from PySide.QtNetwork import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtOpenGL classes and functions."""
# Local imports
from . import PYQT4, PYQT5, PYSIDE, PYSIDE2, PythonQtError
if PYQT5:
from PyQt5.QtOpenGL import *
elif PYSIDE2:
from PySide2.QtOpenGL import *
elif PYQT4:
from PyQt4.QtOpenGL import *
elif PYSIDE:
from PySide.QtOpenGL import *
else:
raise PythonQtError('No Qt bindings could be found')
del PYQT4, PYQT5, PYSIDE, PYSIDE2

View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
Provides QtPrintSupport classes and functions.
"""
from . import PYQT5, PYQT4,PYSIDE2, PYSIDE, PythonQtError
if PYQT5:
from PyQt5.QtPrintSupport import *
elif PYSIDE2:
from PySide2.QtPrintSupport import *
elif PYQT4:
from PyQt4.QtGui import (QAbstractPrintDialog, QPageSetupDialog,
QPrintDialog, QPrintEngine, QPrintPreviewDialog,
QPrintPreviewWidget, QPrinter, QPrinterInfo)
elif PYSIDE:
from PySide.QtGui import (QAbstractPrintDialog, QPageSetupDialog,
QPrintDialog, QPrintEngine, QPrintPreviewDialog,
QPrintPreviewWidget, QPrinter, QPrinterInfo)
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtQml classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
if PYQT5:
from PyQt5.QtQml import *
elif PYSIDE2:
from PySide2.QtQml import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtQuick classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
if PYQT5:
from PyQt5.QtQuick import *
elif PYSIDE2:
from PySide2.QtQuick import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtQuickWidgets classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PythonQtError
if PYQT5:
from PyQt5.QtQuickWidgets import *
elif PYSIDE2:
from PySide2.QtQuickWidgets import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtSql classes and functions."""
# Local imports
from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
if PYQT5:
from PyQt5.QtSql import *
elif PYSIDE2:
from PySide2.QtSql import *
elif PYQT4:
from PyQt4.QtSql import *
elif PYSIDE:
from PySide.QtSql import *
else:
raise PythonQtError('No Qt bindings could be found')
del PYQT4, PYQT5, PYSIDE, PYSIDE2

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtSvg classes and functions."""
# Local imports
from . import PYQT4, PYSIDE2, PYQT5, PYSIDE, PythonQtError
if PYQT5:
from PyQt5.QtSvg import *
elif PYSIDE2:
from PySide2.QtSvg import *
elif PYQT4:
from PyQt4.QtSvg import *
elif PYSIDE:
from PySide.QtSvg import *
else:
raise PythonQtError('No Qt bindings could be found')
del PYQT4, PYQT5, PYSIDE, PYSIDE2

View file

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2014-2015 Colin Duquesnoy
# Copyright © 2009- The Spyder Developmet Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
Provides QtTest and functions
"""
from . import PYQT5,PYSIDE2, PYQT4, PYSIDE, PythonQtError
if PYQT5:
from PyQt5.QtTest import QTest
elif PYSIDE2:
from PySide2.QtTest import QTest
elif PYQT4:
from PyQt4.QtTest import QTest as OldQTest
class QTest(OldQTest):
@staticmethod
def qWaitForWindowActive(QWidget):
OldQTest.qWaitForWindowShown(QWidget)
elif PYSIDE:
from PySide.QtTest import QTest
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtWebChannel classes and functions."""
# Local imports
from . import PYSIDE2, PYQT5, PythonQtError
if PYQT5:
from PyQt5.QtWebChannel import *
elif PYSIDE2:
from PySide2.QtWebChannel import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2014-2015 Colin Duquesnoy
# Copyright © 2009- The Spyder development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
Provides QtWebEngineWidgets classes and functions.
"""
from . import PYQT5,PYSIDE2, PYQT4, PYSIDE, PythonQtError
# To test if we are using WebEngine or WebKit
WEBENGINE = True
if PYQT5:
try:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
except ImportError:
from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView
from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings
WEBENGINE = False
elif PYSIDE2:
from PySide2.QtWebEngineWidgets import QWebEnginePage
from PySide2.QtWebEngineWidgets import QWebEngineView
from PySide2.QtWebEngineWidgets import QWebEngineSettings
elif PYQT4:
from PyQt4.QtWebKit import QWebPage as QWebEnginePage
from PyQt4.QtWebKit import QWebView as QWebEngineView
from PyQt4.QtWebKit import QWebSettings as QWebEngineSettings
WEBENGINE = False
elif PYSIDE:
from PySide.QtWebKit import QWebPage as QWebEnginePage
from PySide.QtWebKit import QWebView as QWebEngineView
from PySide.QtWebKit import QWebSettings as QWebEngineSettings
WEBENGINE = False
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtWebSockets classes and functions."""
# Local imports
from . import PYSIDE2, PYQT5, PythonQtError
if PYQT5:
from PyQt5.QtWebSockets import *
elif PYSIDE2:
from PySide2.QtWebSockets import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,133 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2014-2015 Colin Duquesnoy
# Copyright © 2009- The Spyder Developmet Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
Provides widget classes and functions.
.. warning:: Only PyQt4/PySide QtGui classes compatible with PyQt5.QtWidgets
are exposed here. Therefore, you need to treat/use this package as if it
were the ``PyQt5.QtWidgets`` module.
"""
from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
from ._patch.qcombobox import patch_qcombobox
from ._patch.qheaderview import introduce_renamed_methods_qheaderview
if PYQT5:
from PyQt5.QtWidgets import *
elif PYSIDE2:
from PySide2.QtWidgets import *
elif PYQT4:
from PyQt4.QtGui import *
QStyleOptionViewItem = QStyleOptionViewItemV4
del QStyleOptionViewItemV4
# These objects belong to QtGui
try:
# Older versions of PyQt4 do not provide these
del (QGlyphRun,
QMatrix2x2, QMatrix2x3, QMatrix2x4, QMatrix3x2, QMatrix3x3,
QMatrix3x4, QMatrix4x2, QMatrix4x3, QMatrix4x4,
QQuaternion, QRadialGradient, QRawFont, QRegExpValidator,
QStaticText, QTouchEvent, QVector2D, QVector3D, QVector4D,
qFuzzyCompare)
except NameError:
pass
del (QAbstractTextDocumentLayout, QActionEvent, QBitmap, QBrush, QClipboard,
QCloseEvent, QColor, QConicalGradient, QContextMenuEvent, QCursor,
QDesktopServices, QDoubleValidator, QDrag, QDragEnterEvent,
QDragLeaveEvent, QDragMoveEvent, QDropEvent, QFileOpenEvent,
QFocusEvent, QFont, QFontDatabase, QFontInfo, QFontMetrics,
QFontMetricsF, QGradient, QHelpEvent, QHideEvent,
QHoverEvent, QIcon, QIconDragEvent, QIconEngine, QImage,
QImageIOHandler, QImageReader, QImageWriter, QInputEvent,
QInputMethodEvent, QKeyEvent, QKeySequence, QLinearGradient,
QMouseEvent, QMoveEvent, QMovie, QPaintDevice, QPaintEngine,
QPaintEngineState, QPaintEvent, QPainter, QPainterPath,
QPainterPathStroker, QPalette, QPen, QPicture, QPictureIO, QPixmap,
QPixmapCache, QPolygon, QPolygonF,
QRegion, QResizeEvent, QSessionManager, QShortcutEvent, QShowEvent,
QStandardItem, QStandardItemModel, QStatusTipEvent,
QSyntaxHighlighter, QTabletEvent, QTextBlock, QTextBlockFormat,
QTextBlockGroup, QTextBlockUserData, QTextCharFormat, QTextCursor,
QTextDocument, QTextDocumentFragment, QTextDocumentWriter,
QTextFormat, QTextFragment, QTextFrame, QTextFrameFormat,
QTextImageFormat, QTextInlineObject, QTextItem, QTextLayout,
QTextLength, QTextLine, QTextList, QTextListFormat, QTextObject,
QTextObjectInterface, QTextOption, QTextTable, QTextTableCell,
QTextTableCellFormat, QTextTableFormat, QTransform,
QValidator, QWhatsThisClickedEvent,
QWheelEvent, QWindowStateChangeEvent, qAlpha, qBlue,
qGray, qGreen, qIsGray, qRed, qRgb, qRgba, QIntValidator,
QStringListModel)
# These objects belong to QtPrintSupport
del (QAbstractPrintDialog, QPageSetupDialog, QPrintDialog, QPrintEngine,
QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo)
# These objects belong to QtCore
del (QItemSelection, QItemSelectionModel, QItemSelectionRange,
QSortFilterProxyModel)
# Patch QComboBox to allow Python objects to be passed to userData
patch_qcombobox(QComboBox)
# QHeaderView: renamed methods
introduce_renamed_methods_qheaderview(QHeaderView)
elif PYSIDE:
from PySide.QtGui import *
QStyleOptionViewItem = QStyleOptionViewItemV4
del QStyleOptionViewItemV4
# These objects belong to QtGui
del (QAbstractTextDocumentLayout, QActionEvent, QBitmap, QBrush, QClipboard,
QCloseEvent, QColor, QConicalGradient, QContextMenuEvent, QCursor,
QDesktopServices, QDoubleValidator, QDrag, QDragEnterEvent,
QDragLeaveEvent, QDragMoveEvent, QDropEvent, QFileOpenEvent,
QFocusEvent, QFont, QFontDatabase, QFontInfo, QFontMetrics,
QFontMetricsF, QGradient, QHelpEvent, QHideEvent,
QHoverEvent, QIcon, QIconDragEvent, QIconEngine, QImage,
QImageIOHandler, QImageReader, QImageWriter, QInputEvent,
QInputMethodEvent, QKeyEvent, QKeySequence, QLinearGradient,
QMatrix2x2, QMatrix2x3, QMatrix2x4, QMatrix3x2, QMatrix3x3,
QMatrix3x4, QMatrix4x2, QMatrix4x3, QMatrix4x4, QMouseEvent,
QMoveEvent, QMovie, QPaintDevice, QPaintEngine, QPaintEngineState,
QPaintEvent, QPainter, QPainterPath, QPainterPathStroker, QPalette,
QPen, QPicture, QPictureIO, QPixmap, QPixmapCache, QPolygon,
QPolygonF, QQuaternion, QRadialGradient, QRegExpValidator,
QRegion, QResizeEvent, QSessionManager, QShortcutEvent, QShowEvent,
QStandardItem, QStandardItemModel, QStatusTipEvent,
QSyntaxHighlighter, QTabletEvent, QTextBlock, QTextBlockFormat,
QTextBlockGroup, QTextBlockUserData, QTextCharFormat, QTextCursor,
QTextDocument, QTextDocumentFragment,
QTextFormat, QTextFragment, QTextFrame, QTextFrameFormat,
QTextImageFormat, QTextInlineObject, QTextItem, QTextLayout,
QTextLength, QTextLine, QTextList, QTextListFormat, QTextObject,
QTextObjectInterface, QTextOption, QTextTable, QTextTableCell,
QTextTableCellFormat, QTextTableFormat, QTouchEvent, QTransform,
QValidator, QVector2D, QVector3D, QVector4D, QWhatsThisClickedEvent,
QWheelEvent, QWindowStateChangeEvent, qAlpha, qBlue, qGray, qGreen,
qIsGray, qRed, qRgb, qRgba, QIntValidator, QStringListModel)
# These objects belong to QtPrintSupport
del (QAbstractPrintDialog, QPageSetupDialog, QPrintDialog, QPrintEngine,
QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo)
# These objects belong to QtCore
del (QItemSelection, QItemSelectionModel, QItemSelectionRange,
QSortFilterProxyModel)
# Patch QComboBox to allow Python objects to be passed to userData
patch_qcombobox(QComboBox)
# QHeaderView: renamed methods
introduce_renamed_methods_qheaderview(QHeaderView)
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © 2009- The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
# -----------------------------------------------------------------------------
"""Provides QtXmlPatterns classes and functions."""
# Local imports
from . import PYQT4, PYSIDE2, PYQT5, PYSIDE, PythonQtError
if PYQT5:
from PyQt5.QtXmlPatterns import *
elif PYSIDE2:
from PySide2.QtXmlPatterns import *
elif PYQT4:
from PyQt4.QtXmlPatterns import *
elif PYSIDE:
from PySide.QtXmlPatterns import *
else:
raise PythonQtError('No Qt bindings could be found')

View file

@ -0,0 +1,226 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2009- The Spyder Development Team
# Copyright © 2014-2015 Colin Duquesnoy
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
"""
**QtPy** is a shim over the various Python Qt bindings. It is used to write
Qt binding indenpendent libraries or applications.
If one of the APIs has already been imported, then it will be used.
Otherwise, the shim will automatically select the first available API (PyQt5,
PySide2, PyQt4 and finally PySide); in that case, you can force the use of one
specific bindings (e.g. if your application is using one specific bindings and
you need to use library that use QtPy) by setting up the ``QT_API`` environment
variable.
PyQt5
=====
For PyQt5, you don't have to set anything as it will be used automatically::
>>> from qtpy import QtGui, QtWidgets, QtCore
>>> print(QtWidgets.QWidget)
PySide2
======
Set the QT_API environment variable to 'pyside2' before importing other
packages::
>>> import os
>>> os.environ['QT_API'] = 'pyside2'
>>> from qtpy import QtGui, QtWidgets, QtCore
>>> print(QtWidgets.QWidget)
PyQt4
=====
Set the ``QT_API`` environment variable to 'pyqt' before importing any python
package::
>>> import os
>>> os.environ['QT_API'] = 'pyqt'
>>> from qtpy import QtGui, QtWidgets, QtCore
>>> print(QtWidgets.QWidget)
PySide
======
Set the QT_API environment variable to 'pyside' before importing other
packages::
>>> import os
>>> os.environ['QT_API'] = 'pyside'
>>> from qtpy import QtGui, QtWidgets, QtCore
>>> print(QtWidgets.QWidget)
"""
from distutils.version import LooseVersion
import os
import platform
import sys
import warnings
# Version of QtPy
from ._version import __version__
class PythonQtError(RuntimeError):
"""Error raise if no bindings could be selected."""
pass
class PythonQtWarning(Warning):
"""Warning if some features are not implemented in a binding."""
pass
# Qt API environment variable name
QT_API = 'QT_API'
# Names of the expected PyQt5 api
PYQT5_API = ['pyqt5']
# Names of the expected PyQt4 api
PYQT4_API = [
'pyqt', # name used in IPython.qt
'pyqt4' # pyqode.qt original name
]
# Names of the expected PySide api
PYSIDE_API = ['pyside']
# Names of the expected PySide2 api
PYSIDE2_API = ['pyside2']
# Detecting if a binding was specified by the user
binding_specified = QT_API in os.environ
# Setting a default value for QT_API
os.environ.setdefault(QT_API, 'pyqt5')
API = os.environ[QT_API].lower()
initial_api = API
assert API in (PYQT5_API + PYQT4_API + PYSIDE_API + PYSIDE2_API)
is_old_pyqt = is_pyqt46 = False
PYQT5 = True
PYQT4 = PYSIDE = PYSIDE2 = False
# When `FORCE_QT_API` is set, we disregard
# any previously imported python bindings.
if os.environ.get('FORCE_QT_API') is not None:
if 'PyQt5' in sys.modules:
API = initial_api if initial_api in PYQT5_API else 'pyqt5'
elif 'PySide2' in sys.modules:
API = initial_api if initial_api in PYSIDE2_API else 'pyside2'
elif 'PyQt4' in sys.modules:
API = initial_api if initial_api in PYQT4_API else 'pyqt4'
elif 'PySide' in sys.modules:
API = initial_api if initial_api in PYSIDE_API else 'pyside'
if API in PYQT5_API:
try:
from PyQt5.QtCore import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore
from PyQt5.QtCore import QT_VERSION_STR as QT_VERSION # analysis:ignore
PYSIDE_VERSION = None
if sys.platform == 'darwin':
macos_version = LooseVersion(platform.mac_ver()[0])
if macos_version < LooseVersion('10.10'):
if LooseVersion(QT_VERSION) >= LooseVersion('5.9'):
raise PythonQtError("Qt 5.9 or higher only works in "
"macOS 10.10 or higher. Your "
"program will fail in this "
"system.")
elif macos_version < LooseVersion('10.11'):
if LooseVersion(QT_VERSION) >= LooseVersion('5.11'):
raise PythonQtError("Qt 5.11 or higher only works in "
"macOS 10.11 or higher. Your "
"program will fail in this "
"system.")
del macos_version
except ImportError:
API = os.environ['QT_API'] = 'pyside2'
if API in PYSIDE2_API:
try:
from PySide2 import __version__ as PYSIDE_VERSION # analysis:ignore
from PySide2.QtCore import __version__ as QT_VERSION # analysis:ignore
PYQT_VERSION = None
PYQT5 = False
PYSIDE2 = True
if sys.platform == 'darwin':
macos_version = LooseVersion(platform.mac_ver()[0])
if macos_version < LooseVersion('10.11'):
if LooseVersion(QT_VERSION) >= LooseVersion('5.11'):
raise PythonQtError("Qt 5.11 or higher only works in "
"macOS 10.11 or higher. Your "
"program will fail in this "
"system.")
del macos_version
except ImportError:
API = os.environ['QT_API'] = 'pyqt'
if API in PYQT4_API:
try:
import sip
try:
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
sip.setapi('QDate', 2)
sip.setapi('QDateTime', 2)
sip.setapi('QTextStream', 2)
sip.setapi('QTime', 2)
sip.setapi('QUrl', 2)
except (AttributeError, ValueError):
# PyQt < v4.6
pass
from PyQt4.Qt import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore
from PyQt4.Qt import QT_VERSION_STR as QT_VERSION # analysis:ignore
PYSIDE_VERSION = None
PYQT5 = False
PYQT4 = True
except ImportError:
API = os.environ['QT_API'] = 'pyside'
else:
is_old_pyqt = PYQT_VERSION.startswith(('4.4', '4.5', '4.6', '4.7'))
is_pyqt46 = PYQT_VERSION.startswith('4.6')
if API in PYSIDE_API:
try:
from PySide import __version__ as PYSIDE_VERSION # analysis:ignore
from PySide.QtCore import __version__ as QT_VERSION # analysis:ignore
PYQT_VERSION = None
PYQT5 = PYSIDE2 = False
PYSIDE = True
except ImportError:
raise PythonQtError('No Qt bindings could be found')
# If a correct API name is passed to QT_API and it could not be found,
# switches to another and informs through the warning
if API != initial_api and binding_specified:
warnings.warn('Selected binding "{}" could not be found, '
'using "{}"'.format(initial_api, API), RuntimeWarning)
API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyqt4': 'PyQt4',
'pyside': 'PySide', 'pyside2':'PySide2'}[API]
if PYQT4:
import sip
try:
API_NAME += (" (API v{0})".format(sip.getapi('QString')))
except AttributeError:
pass

View file

@ -0,0 +1,101 @@
# The code below, as well as the associated test were adapted from
# qt-helpers, which was released under a 3-Clause BSD license:
#
# Copyright (c) 2015, Chris Beaumont and Thomas Robitaille
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the
# distribution.
# * Neither the name of the Glue project nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
def patch_qcombobox(QComboBox):
"""
In PySide, using Python objects as userData in QComboBox causes
Segmentation faults under certain conditions. Even in cases where it
doesn't, findData does not work correctly. Likewise, findData also does not
work correctly with Python objects when using PyQt4. On the other hand,
PyQt5 deals with this case correctly. We therefore patch QComboBox when
using PyQt4 and PySide to avoid issues.
"""
from ..QtGui import QIcon
from ..QtCore import Qt, QObject
class userDataWrapper():
"""
This class is used to wrap any userData object. If we don't do this,
then certain types of objects can cause segmentation faults or issues
depending on whether/how __getitem__ is defined.
"""
def __init__(self, data):
self.data = data
_addItem = QComboBox.addItem
def addItem(self, *args, **kwargs):
if len(args) == 3 or (not isinstance(args[0], QIcon)
and len(args) == 2):
args, kwargs['userData'] = args[:-1], args[-1]
if 'userData' in kwargs:
kwargs['userData'] = userDataWrapper(kwargs['userData'])
_addItem(self, *args, **kwargs)
_insertItem = QComboBox.insertItem
def insertItem(self, *args, **kwargs):
if len(args) == 4 or (not isinstance(args[1], QIcon)
and len(args) == 3):
args, kwargs['userData'] = args[:-1], args[-1]
if 'userData' in kwargs:
kwargs['userData'] = userDataWrapper(kwargs['userData'])
_insertItem(self, *args, **kwargs)
_setItemData = QComboBox.setItemData
def setItemData(self, index, value, role=Qt.UserRole):
value = userDataWrapper(value)
_setItemData(self, index, value, role=role)
_itemData = QComboBox.itemData
def itemData(self, index, role=Qt.UserRole):
userData = _itemData(self, index, role=role)
if isinstance(userData, userDataWrapper):
userData = userData.data
return userData
def findData(self, value):
for i in range(self.count()):
if self.itemData(i) == value:
return i
return -1
QComboBox.addItem = addItem
QComboBox.insertItem = insertItem
QComboBox.setItemData = setItemData
QComboBox.itemData = itemData
QComboBox.findData = findData

View file

@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
#
# Copyright © The Spyder Development Team
#
# Licensed under the terms of the MIT License
# (see LICENSE.txt for details)
import warnings
def introduce_renamed_methods_qheaderview(QHeaderView):
_isClickable = QHeaderView.isClickable
def sectionsClickable(self):
"""
QHeaderView.sectionsClickable() -> bool
"""
return _isClickable(self)
QHeaderView.sectionsClickable = sectionsClickable
def isClickable(self):
warnings.warn('isClickable is only available in Qt4. Use '
'sectionsClickable instead.', stacklevel=2)
return _isClickable(self)
QHeaderView.isClickable = isClickable
_isMovable = QHeaderView.isMovable
def sectionsMovable(self):
"""
QHeaderView.sectionsMovable() -> bool
"""
return _isMovable(self)
QHeaderView.sectionsMovable = sectionsMovable
def isMovable(self):
warnings.warn('isMovable is only available in Qt4. Use '
'sectionsMovable instead.', stacklevel=2)
return _isMovable(self)
QHeaderView.isMovable = isMovable
_resizeMode = QHeaderView.resizeMode
def sectionResizeMode(self, logicalIndex):
"""
QHeaderView.sectionResizeMode(int) -> QHeaderView.ResizeMode
"""
return _resizeMode(self, logicalIndex)
QHeaderView.sectionResizeMode = sectionResizeMode
def resizeMode(self, logicalIndex):
warnings.warn('resizeMode is only available in Qt4. Use '
'sectionResizeMode instead.', stacklevel=2)
return _resizeMode(self, logicalIndex)
QHeaderView.resizeMode = resizeMode
_setClickable = QHeaderView.setClickable
def setSectionsClickable(self, clickable):
"""
QHeaderView.setSectionsClickable(bool)
"""
return _setClickable(self, clickable)
QHeaderView.setSectionsClickable = setSectionsClickable
def setClickable(self, clickable):
warnings.warn('setClickable is only available in Qt4. Use '
'setSectionsClickable instead.', stacklevel=2)
return _setClickable(self, clickable)
QHeaderView.setClickable = setClickable
_setMovable = QHeaderView.setMovable
def setSectionsMovable(self, movable):
"""
QHeaderView.setSectionsMovable(bool)
"""
return _setMovable(self, movable)
QHeaderView.setSectionsMovable = setSectionsMovable
def setMovable(self, movable):
warnings.warn('setMovable is only available in Qt4. Use '
'setSectionsMovable instead.', stacklevel=2)
return _setMovable(self, movable)
QHeaderView.setMovable = setMovable
_setResizeMode = QHeaderView.setResizeMode
def setSectionResizeMode(self, *args):
"""
QHeaderView.setSectionResizeMode(QHeaderView.ResizeMode)
QHeaderView.setSectionResizeMode(int, QHeaderView.ResizeMode)
"""
_setResizeMode(self, *args)
QHeaderView.setSectionResizeMode = setSectionResizeMode
def setResizeMode(self, *args):
warnings.warn('setResizeMode is only available in Qt4. Use '
'setSectionResizeMode instead.', stacklevel=2)
_setResizeMode(self, *args)
QHeaderView.setResizeMode = setResizeMode

View file

@ -0,0 +1,2 @@
version_info = (1, 9, 0)
__version__ = '.'.join(map(str, version_info))

View file

@ -0,0 +1,196 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2009- The Spyder Development Team
# Licensed under the terms of the MIT License
"""
Compatibility functions
"""
from __future__ import print_function
import sys
import collections
from . import PYQT4
from .QtWidgets import QFileDialog
from .py3compat import is_text_string, to_text_string, TEXT_TYPES
# =============================================================================
# QVariant conversion utilities
# =============================================================================
PYQT_API_1 = False
if PYQT4:
import sip
try:
PYQT_API_1 = sip.getapi('QVariant') == 1 # PyQt API #1
except AttributeError:
# PyQt <v4.6
PYQT_API_1 = True
def to_qvariant(pyobj=None):
"""Convert Python object to QVariant
This is a transitional function from PyQt API #1 (QVariant exist)
to PyQt API #2 and Pyside (QVariant does not exist)"""
if PYQT_API_1:
# PyQt API #1
from PyQt4.QtCore import QVariant
return QVariant(pyobj)
else:
# PyQt API #2
return pyobj
def from_qvariant(qobj=None, convfunc=None):
"""Convert QVariant object to Python object
This is a transitional function from PyQt API #1 (QVariant exist)
to PyQt API #2 and Pyside (QVariant does not exist)"""
if PYQT_API_1:
# PyQt API #1
assert isinstance(convfunc, collections.Callable)
if convfunc in TEXT_TYPES or convfunc is to_text_string:
return convfunc(qobj.toString())
elif convfunc is bool:
return qobj.toBool()
elif convfunc is int:
return qobj.toInt()[0]
elif convfunc is float:
return qobj.toDouble()[0]
else:
return convfunc(qobj)
else:
# PyQt API #2
return qobj
else:
def to_qvariant(obj=None): # analysis:ignore
"""Convert Python object to QVariant
This is a transitional function from PyQt API#1 (QVariant exist)
to PyQt API#2 and Pyside (QVariant does not exist)"""
return obj
def from_qvariant(qobj=None, pytype=None): # analysis:ignore
"""Convert QVariant object to Python object
This is a transitional function from PyQt API #1 (QVariant exist)
to PyQt API #2 and Pyside (QVariant does not exist)"""
return qobj
# =============================================================================
# Wrappers around QFileDialog static methods
# =============================================================================
def getexistingdirectory(parent=None, caption='', basedir='',
options=QFileDialog.ShowDirsOnly):
"""Wrapper around QtGui.QFileDialog.getExistingDirectory static method
Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0"""
# Calling QFileDialog static method
if sys.platform == "win32":
# On Windows platforms: redirect standard outputs
_temp1, _temp2 = sys.stdout, sys.stderr
sys.stdout, sys.stderr = None, None
try:
result = QFileDialog.getExistingDirectory(parent, caption, basedir,
options)
finally:
if sys.platform == "win32":
# On Windows platforms: restore standard outputs
sys.stdout, sys.stderr = _temp1, _temp2
if not is_text_string(result):
# PyQt API #1
result = to_text_string(result)
return result
def _qfiledialog_wrapper(attr, parent=None, caption='', basedir='',
filters='', selectedfilter='', options=None):
if options is None:
options = QFileDialog.Options(0)
try:
# PyQt <v4.6 (API #1)
from .QtCore import QString
except ImportError:
# PySide or PyQt >=v4.6
QString = None # analysis:ignore
tuple_returned = True
try:
# PyQt >=v4.6
func = getattr(QFileDialog, attr+'AndFilter')
except AttributeError:
# PySide or PyQt <v4.6
func = getattr(QFileDialog, attr)
if QString is not None:
selectedfilter = QString()
tuple_returned = False
# Calling QFileDialog static method
if sys.platform == "win32":
# On Windows platforms: redirect standard outputs
_temp1, _temp2 = sys.stdout, sys.stderr
sys.stdout, sys.stderr = None, None
try:
result = func(parent, caption, basedir,
filters, selectedfilter, options)
except TypeError:
# The selectedfilter option (`initialFilter` in Qt) has only been
# introduced in Jan. 2010 for PyQt v4.7, that's why we handle here
# the TypeError exception which will be raised with PyQt v4.6
# (see Issue 960 for more details)
result = func(parent, caption, basedir, filters, options)
finally:
if sys.platform == "win32":
# On Windows platforms: restore standard outputs
sys.stdout, sys.stderr = _temp1, _temp2
# Processing output
if tuple_returned:
# PySide or PyQt >=v4.6
output, selectedfilter = result
else:
# PyQt <v4.6 (API #1)
output = result
if QString is not None:
# PyQt API #1: conversions needed from QString/QStringList
selectedfilter = to_text_string(selectedfilter)
if isinstance(output, QString):
# Single filename
output = to_text_string(output)
else:
# List of filenames
output = [to_text_string(fname) for fname in output]
# Always returns the tuple (output, selectedfilter)
return output, selectedfilter
def getopenfilename(parent=None, caption='', basedir='', filters='',
selectedfilter='', options=None):
"""Wrapper around QtGui.QFileDialog.getOpenFileName static method
Returns a tuple (filename, selectedfilter) -- when dialog box is canceled,
returns a tuple of empty strings
Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0"""
return _qfiledialog_wrapper('getOpenFileName', parent=parent,
caption=caption, basedir=basedir,
filters=filters, selectedfilter=selectedfilter,
options=options)
def getopenfilenames(parent=None, caption='', basedir='', filters='',
selectedfilter='', options=None):
"""Wrapper around QtGui.QFileDialog.getOpenFileNames static method
Returns a tuple (filenames, selectedfilter) -- when dialog box is canceled,
returns a tuple (empty list, empty string)
Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0"""
return _qfiledialog_wrapper('getOpenFileNames', parent=parent,
caption=caption, basedir=basedir,
filters=filters, selectedfilter=selectedfilter,
options=options)
def getsavefilename(parent=None, caption='', basedir='', filters='',
selectedfilter='', options=None):
"""Wrapper around QtGui.QFileDialog.getSaveFileName static method
Returns a tuple (filename, selectedfilter) -- when dialog box is canceled,
returns a tuple of empty strings
Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0"""
return _qfiledialog_wrapper('getSaveFileName', parent=parent,
caption=caption, basedir=basedir,
filters=filters, selectedfilter=selectedfilter,
options=options)

View file

@ -0,0 +1,261 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2012-2013 Pierre Raybaut
# Licensed under the terms of the MIT License
# (see spyderlib/__init__.py for details)
"""
spyderlib.py3compat
-------------------
Transitional module providing compatibility functions intended to help
migrating from Python 2 to Python 3.
This module should be fully compatible with:
* Python >=v2.6
* Python 3
"""
from __future__ import print_function
import sys
import os
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
PY33 = PY3 and sys.version_info[1] >= 3
# =============================================================================
# Data types
# =============================================================================
if PY2:
# Python 2
TEXT_TYPES = (str, unicode)
INT_TYPES = (int, long)
else:
# Python 3
TEXT_TYPES = (str,)
INT_TYPES = (int,)
NUMERIC_TYPES = tuple(list(INT_TYPES) + [float, complex])
# =============================================================================
# Renamed/Reorganized modules
# =============================================================================
if PY2:
# Python 2
import __builtin__ as builtins
import ConfigParser as configparser
try:
import _winreg as winreg
except ImportError:
pass
from sys import maxint as maxsize
try:
import CStringIO as io
except ImportError:
import StringIO as io
try:
import cPickle as pickle
except ImportError:
import pickle
from UserDict import DictMixin as MutableMapping
import thread as _thread
import repr as reprlib
else:
# Python 3
import builtins
import configparser
try:
import winreg
except ImportError:
pass
from sys import maxsize
import io
import pickle
if PY33:
from collections.abc import MutableMapping
else:
from collections import MutableMapping
import _thread
import reprlib
# =============================================================================
# Strings
# =============================================================================
if PY2:
# Python 2
import codecs
def u(obj):
"""Make unicode object"""
return codecs.unicode_escape_decode(obj)[0]
else:
# Python 3
def u(obj):
"""Return string as it is"""
return obj
def is_text_string(obj):
"""Return True if `obj` is a text string, False if it is anything else,
like binary data (Python 3) or QString (Python 2, PyQt API #1)"""
if PY2:
# Python 2
return isinstance(obj, basestring)
else:
# Python 3
return isinstance(obj, str)
def is_binary_string(obj):
"""Return True if `obj` is a binary string, False if it is anything else"""
if PY2:
# Python 2
return isinstance(obj, str)
else:
# Python 3
return isinstance(obj, bytes)
def is_string(obj):
"""Return True if `obj` is a text or binary Python string object,
False if it is anything else, like a QString (Python 2, PyQt API #1)"""
return is_text_string(obj) or is_binary_string(obj)
def is_unicode(obj):
"""Return True if `obj` is unicode"""
if PY2:
# Python 2
return isinstance(obj, unicode)
else:
# Python 3
return isinstance(obj, str)
def to_text_string(obj, encoding=None):
"""Convert `obj` to (unicode) text string"""
if PY2:
# Python 2
if encoding is None:
return unicode(obj)
else:
return unicode(obj, encoding)
else:
# Python 3
if encoding is None:
return str(obj)
elif isinstance(obj, str):
# In case this function is not used properly, this could happen
return obj
else:
return str(obj, encoding)
def to_binary_string(obj, encoding=None):
"""Convert `obj` to binary string (bytes in Python 3, str in Python 2)"""
if PY2:
# Python 2
if encoding is None:
return str(obj)
else:
return obj.encode(encoding)
else:
# Python 3
return bytes(obj, 'utf-8' if encoding is None else encoding)
# =============================================================================
# Function attributes
# =============================================================================
def get_func_code(func):
"""Return function code object"""
if PY2:
# Python 2
return func.func_code
else:
# Python 3
return func.__code__
def get_func_name(func):
"""Return function name"""
if PY2:
# Python 2
return func.func_name
else:
# Python 3
return func.__name__
def get_func_defaults(func):
"""Return function default argument values"""
if PY2:
# Python 2
return func.func_defaults
else:
# Python 3
return func.__defaults__
# =============================================================================
# Special method attributes
# =============================================================================
def get_meth_func(obj):
"""Return method function object"""
if PY2:
# Python 2
return obj.im_func
else:
# Python 3
return obj.__func__
def get_meth_class_inst(obj):
"""Return method class instance"""
if PY2:
# Python 2
return obj.im_self
else:
# Python 3
return obj.__self__
def get_meth_class(obj):
"""Return method class"""
if PY2:
# Python 2
return obj.im_class
else:
# Python 3
return obj.__self__.__class__
# =============================================================================
# Misc.
# =============================================================================
if PY2:
# Python 2
input = raw_input
getcwd = os.getcwdu
cmp = cmp
import string
str_lower = string.lower
from itertools import izip_longest as zip_longest
else:
# Python 3
input = input
getcwd = os.getcwd
def cmp(a, b):
return (a > b) - (a < b)
str_lower = str.lower
from itertools import zip_longest
def qbytearray_to_str(qba):
"""Convert QByteArray object to str in a way compatible with Python 2/3"""
return str(bytes(qba.toHex().data()).decode())

Some files were not shown because too many files have changed in this diff Show more