我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用PyQt5.QtCore.PYQT_VERSION_STR。
def _list_3rd_party(): from ..thirdparty import pyqtgraph import qtawesome try: from qtconsole import __version__ as qtconsole_version from IPython import __version__ as ipython_version except ImportError: qtconsole_version = 'N/A' ipython_version = 'N/A' return [ ('PyUAVCAN', uavcan.__version__, 'MIT', 'http://uavcan.org/Implementations/Pyuavcan'), ('PyQt5', PYQT_VERSION_STR, 'GPLv3', 'https://www.riverbankcomputing.com/software/pyqt/intro'), ('PyQtGraph', pyqtgraph.__version__, 'MIT', 'http://www.pyqtgraph.org/'), ('QtAwesome', qtawesome.__version__, 'MIT', 'https://github.com/spyder-ide/qtawesome'), ('QtConsole', qtconsole_version, 'BSD', 'http://jupyter.org'), ('IPython', ipython_version, 'BSD', 'https://ipython.org'), ]
def pyqt5(): import PyQt5.Qt from PyQt5 import QtCore, uic remap(QtCore, "Signal", QtCore.pyqtSignal) remap(QtCore, "Slot", QtCore.pyqtSlot) remap(QtCore, "Property", QtCore.pyqtProperty) add(PyQt5, "__wrapper_version__", __version__) add(PyQt5, "__binding__", "PyQt5") add(PyQt5, "__binding_version__", QtCore.PYQT_VERSION_STR) add(PyQt5, "__qt_version__", QtCore.QT_VERSION_STR, safe=False) add(PyQt5, "__added__", __added__) add(PyQt5, "__remapped__", __remapped__) add(PyQt5, "__modified__", __modified__) add(PyQt5, "load_ui", lambda fname: uic.loadUi(fname)) return PyQt5
def import_pyqt4(version=2): """ 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 """ # The new-style string API (version=2) automatically # converts QStrings to Unicode Python strings. Also, automatically unpacks # QVariants to their underlying objects. import sip if version is not None: sip.setapi('QString', version) sip.setapi('QVariant', version) from PyQt4 import QtGui, QtCore, QtSvg if not check_version(QtCore.PYQT_VERSION_STR, '4.7'): raise ImportError("IPython requires PyQt4 >= 4.7, found %s" % QtCore.PYQT_VERSION_STR) # Alias PyQt-specific functions for PySide compatibility. QtCore.Signal = QtCore.pyqtSignal QtCore.Slot = QtCore.pyqtSlot # query for the API version (in case version == None) version = sip.getapi('QString') api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT return QtCore, QtGui, QtSvg, api
def CanvasObject(): if g.config.mode3d: QtVersion = QtCore.QT_VERSION_STR.split(".") if not (int(QtVersion[0]) >= 5 and int(QtVersion[1]) >= 4): raise Exception("For the 3d mode you need a PyQt version that includes a Qt version of at least 5.4.\n" "Set mode3d to False in the config file, or update your PyQt version.\n" "Current version found: PyQt%s (which includes Qt%s)" % (QtCore.PYQT_VERSION_STR, QtCore.QT_VERSION_STR)) from PyQt5.QtWidgets import QOpenGLWidget return QOpenGLWidget else: return QGraphicsView
def import_pyqt4(version=2): """ Import PyQt4 Parameters ---------- version : 1, 2, or None Which QString/QVariant API to use. Set to None to use the system default ImportErrors raised within this function are non-recoverable """ # The new-style string API (version=2) automatically # converts QStrings to Unicode Python strings. Also, automatically unpacks # QVariants to their underlying objects. import sip if version is not None: sip.setapi('QString', version) sip.setapi('QVariant', version) from PyQt4 import QtGui, QtCore, QtSvg if not check_version(QtCore.PYQT_VERSION_STR, '4.7'): raise ImportError("IPython requires PyQt4 >= 4.7, found %s" % QtCore.PYQT_VERSION_STR) # Alias PyQt-specific functions for PySide compatibility. QtCore.Signal = QtCore.pyqtSignal QtCore.Slot = QtCore.pyqtSlot # query for the API version (in case version == None) version = sip.getapi('QString') api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT return QtCore, QtGui, QtSvg, api
def compileUi(uifile, pyfile, execute=False, indent=4, from_imports=False, resource_suffix='_rc'): """compileUi(uifile, pyfile, execute=False, indent=4, from_imports=False, resource_suffix='_rc') Creates a Python module from a Qt Designer .ui file. uifile is a file name or file-like object containing the .ui file. pyfile is the file-like object to which the Python code will be written to. execute is optionally set to generate extra Python code that allows the code to be run as a standalone application. The default is False. indent is the optional indentation width using spaces. If it is 0 then a tab is used. The default is 4. from_imports is optionally set to generate import statements that are relative to '.'. resource_suffix is the suffix appended to the basename of any resource file specified in the .ui file to create the name of the Python module generated from the resource file by pyrcc4. The default is '_rc', i.e. if the .ui file specified a resource file called foo.qrc then the corresponding Python module is foo_rc. """ from PyQt5.QtCore import PYQT_VERSION_STR try: uifname = uifile.name except AttributeError: uifname = uifile indenter.indentwidth = indent pyfile.write(_header % (uifname, PYQT_VERSION_STR)) winfo = compiler.UICompiler().compileUi(uifile, pyfile, from_imports, resource_suffix) if execute: indenter.write_code(_display_code % winfo)
def compileUi(uifile, pyfile, execute=False, indent=4, from_imports=False, resource_suffix='_rc', import_from='.'): """compileUi(uifile, pyfile, execute=False, indent=4, from_imports=False, resource_suffix='_rc', import_from='.') Creates a Python module from a Qt Designer .ui file. uifile is a file name or file-like object containing the .ui file. pyfile is the file-like object to which the Python code will be written to. execute is optionally set to generate extra Python code that allows the code to be run as a standalone application. The default is False. indent is the optional indentation width using spaces. If it is 0 then a tab is used. The default is 4. from_imports is optionally set to generate relative import statements. At the moment this only applies to the import of resource modules. resource_suffix is the suffix appended to the basename of any resource file specified in the .ui file to create the name of the Python module generated from the resource file by pyrcc4. The default is '_rc', i.e. if the .ui file specified a resource file called foo.qrc then the corresponding Python module is foo_rc. import_from is optionally set to the package used for relative import statements. The default is ``'.'``. """ from PyQt5.QtCore import PYQT_VERSION_STR try: uifname = uifile.name except AttributeError: uifname = uifile indenter.indentwidth = indent pyfile.write(_header % (uifname, PYQT_VERSION_STR)) winfo = compiler.UICompiler().compileUi(uifile, pyfile, from_imports, resource_suffix, import_from) if execute: indenter.write_code(_display_code % winfo)
def about(self): import platform if use_pyside: Qt_version = QtCore.__version__ PyQt_version = PySide.__version__ else: Qt_version = QtCore.QT_VERSION_STR PyQt_version = QtCore.PYQT_VERSION_STR QMessageBox.about( self, "About XAFSmassQt", """<b>XAFSmass(Qt)</b> v {0} <ul> <li>{1[0]} <li>{1[1]} </ul> <p>Open source, {2}. Available at PyPI and GitHub<p> <p>Your system: <ul> <li>{3} <li>Python {4} <li>Qt {5} <li>{6} {7} </ul>""".format( __version__, __author__.split(','), __license__, platform.platform(terse=True), platform.python_version(), Qt_version, QtName, PyQt_version))
def pyqt4(): # Attempt to set sip API v2 (must be done prior to importing PyQt4) 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: raise ImportError # PyQt4 < v4.6 except ValueError: # API version already set to v1 raise ImportError import PyQt4.Qt from PyQt4 import QtCore, QtGui, uic remap(PyQt4, "QtWidgets", QtGui) remap(QtCore, "Signal", QtCore.pyqtSignal) remap(QtCore, "Slot", QtCore.pyqtSlot) remap(QtCore, "Property", QtCore.pyqtProperty) remap(QtCore, "QItemSelection", QtGui.QItemSelection) remap(QtCore, "QStringListModel", QtGui.QStringListModel) remap(QtCore, "QItemSelectionModel", QtGui.QItemSelectionModel) remap(QtCore, "QSortFilterProxyModel", QtGui.QSortFilterProxyModel) remap(QtCore, "QAbstractProxyModel", QtGui.QAbstractProxyModel) try: from PyQt4 import QtWebKit remap(PyQt4, "QtWebKitWidgets", QtWebKit) except ImportError: # QtWebkit is optional in Qt , therefore might not be available pass add(PyQt4, "__wrapper_version__", __version__) add(PyQt4, "__binding__", "PyQt4") add(PyQt4, "__binding_version__", QtCore.PYQT_VERSION_STR) add(PyQt4, "__qt_version__", QtCore.QT_VERSION_STR) add(PyQt4, "__added__", __added__) add(PyQt4, "__remapped__", __remapped__) add(PyQt4, "__modified__", __modified__) add(PyQt4, "load_ui", lambda fname: uic.loadUi(fname)) return PyQt4