本文整理汇总了Python中sip.setapi函数的典型用法代码示例。如果您正苦于以下问题:Python setapi函数的具体用法?Python setapi怎么用?Python setapi使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setapi函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setup_apiv2
def setup_apiv2():
"""
Setup apiv2 when using PyQt4 and Python2.
"""
# setup PyQt api to version 2
if sys.version_info[0] == 2:
import sip
if _api_version:
default = _api_version
apis = [
("QDate", default),
("QDateTime", default),
("QString", default),
("QTextStream", default),
("QTime", default),
("QUrl", default),
("QVariant", default),
("QFileDialog", default),
]
for name, version in apis:
try:
sip.setapi(name, version)
except ValueError:
logging.getLogger(__name__).critical("failed to set up sip api to version 2 for PyQt4")
raise ImportError('PyQt4')
from PyQt4.QtCore import PYQT_VERSION_STR as __version__
开发者ID:gbaty,项目名称:openalea,代码行数:26,代码来源:__init__.py
示例2: test_sip_api_already_set
def test_sip_api_already_set():
"""Raise ImportError if sip API v1 was already set"""
__import__("PyQt4.QtCore") # Bypass linter warning
import sip
sip.setapi("QString", 1)
assert_raises(ImportError, __import__, "Qt")
开发者ID:abstractfactory,项目名称:Qt.py,代码行数:7,代码来源:tests.py
示例3: import_pyqt4
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
开发者ID:hrocha,项目名称:ipython,代码行数:35,代码来源:qt_loaders.py
示例4: _setup_pyqt4_internal
def _setup_pyqt4_internal(api):
global QtCore, QtGui, QtWidgets, \
__version__, is_pyqt5, _getSaveFileName
# List of incompatible APIs:
# http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
_sip_apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime",
"QUrl", "QVariant"]
try:
import sip
except ImportError:
pass
else:
for _sip_api in _sip_apis:
try:
sip.setapi(_sip_api, api)
except ValueError:
pass
from PyQt4 import QtCore, QtGui
__version__ = QtCore.PYQT_VERSION_STR
# PyQt 4.6 introduced getSaveFileNameAndFilter:
# https://riverbankcomputing.com/news/pyqt-46
if __version__ < LooseVersion("4.6"):
raise ImportError("PyQt<4.6 is not supported")
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
QtCore.Property = QtCore.pyqtProperty
_getSaveFileName = QtGui.QFileDialog.getSaveFileNameAndFilter
开发者ID:NelleV,项目名称:matplotlib,代码行数:27,代码来源:qt_compat.py
示例5: importPyQt
def importPyQt():
try:
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from PyQt4 import QtCore, QtGui, QtNetwork, QtWebKit, uic
from PyQt4.QtCore import pyqtSignal as Signal, pyqtSlot as Slot, \
pyqtProperty as Property
QtUiTools = object()
def loadUI(uiFilename, parent=None):
newWidget = uic.loadUi(uiFilename)
newWidget.setParent(parent)
return newWidget
logger.info("Successfully initialized PyQt4.")
globals().update(
QtCore=QtCore,
QtGui=QtGui,
QtNetwork=QtNetwork,
QtWebKit=QtWebKit,
QtUiTools=QtUiTools,
Signal=Signal,
Slot=Slot,
Property=Property,
loadUI=loadUI,
binding="PyQt4",
)
return True
except ImportError:
return False
开发者ID:aktos-io,项目名称:aktos-dcs-lib,代码行数:35,代码来源:__init__.py
示例6: prepare_pyqt4
def prepare_pyqt4():
# For PySide compatibility, use the new-style string API that automatically
# converts QStrings to Unicode Python strings. Also, automatically unpack
# QVariants to their underlying objects.
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
开发者ID:Tremere,项目名称:ipython,代码行数:7,代码来源:qt.py
示例7: set_sip_api
def set_sip_api():
import sip
api2_classes = [
'QData', 'QDateTime', 'QString', 'QTextStream',
'QTime', 'QUrl', 'QVariant',
]
for cl in api2_classes:
sip.setapi(cl, 2)
开发者ID:portfors-lab,项目名称:SparkleAnalysis,代码行数:8,代码来源:QtWrapper.py
示例8: load_module
def load_module(fullname):
if fullname in _sys.modules:
return _sys.modules[fullname]
_, name = fullname.split('.')
global qt
if qt:
# If a Qt implementation was already selected previously
# and the selected module is the same as the one being imported,
# then return it, otherwise False.
if qt.__name__ == name:
_sys.modules[fullname] = qt; return qt
else:
_sys.modules[fullname] = False; return False
if name == 'PyQt4' and _sys.version_info[0] == 2:
# Select API version 2, this is needed only for PyQt4 on Python 2.x
try:
import sip
for api in ['QDate', 'QDateTime', 'QString', 'QTextStream',
'QTime', 'QUrl', 'QVariant']:
try:
sip.setapi(api, 2)
except Exception:
pass
except Exception:
pass
# The selection of Qt implementation is successful only if its QtCore
# module can be imported.
try:
qt = __import__(name + '.QtCore')
except ImportError:
_sys.modules[fullname] = False; return False
core = qt.QtCore
# Turn `QtCore.Qt` object into a package,
# because `import qt` will actually give this object.
core.Qt.__path__ = []
core.Qt.__package__ = 'qt'
# Put some additional attributes into `qt`.
core.Qt.module = name
core.Qt.version_str = core.qVersion()
core.Qt.major = int(core.Qt.version_str.split('.', 1)[0])
if name.startswith('PyQt'):
core.Qt.module_version_str = core.PYQT_VERSION_STR
core.Signal = core.pyqtSignal
core.Slot = core.pyqtSlot
else:
core.Qt.module_version_str = qt.__version__
core.Qt.Signal = core.Signal
core.Qt.Slot = core.Slot
_sys.modules[fullname] = qt; return qt
开发者ID:BlaXpirit,项目名称:sixcells,代码行数:58,代码来源:__init__.py
示例9: update_apis
def update_apis(apis='QDate QDateTime QString QTextStream QTime QUrl QVariant'.split()):
import sys
if sys.version_info.major==2:
import sip
for api in apis:
try:
sip.setapi(api, 2)
except:
pass
开发者ID:BlaXpirit,项目名称:steam-notifier,代码行数:9,代码来源:core.py
示例10: _checkDependencies
def _checkDependencies(profiler):
"""Check if 3rdparty software is installed in the system.
Notify user, how to install it
"""
_SEE_SITE_PLAIN = 'See http://enki-editor.org/install-sources.html'
_SEE_SITE_HTML = \
'See <a href="http://enki-editor.org/install-sources.html">' \
'installation instructions</a>'
try:
import PyQt5
except ImportError as ex:
plain = 'Failed to import Qt4 python bindings:\n{}\n{}'.format(str(ex), _SEE_SITE_PLAIN)
_showErrorMessage(False, 'PyQt5 not found', plain, plain)
raise ex
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
profiler.stepDone('Import PyQt5')
try:
import qutepart
except ImportError as ex:
html = "<html>" + \
"Failed to import qutepart.<br/>" \
"See <a href=\"https://github.com/hlamer/qutepart\">qutepart site</a><br/>" \
"Exception:<br/>" + \
str(ex) + '<br/>' + \
_SEE_SITE_HTML + \
"</html>"
plain = "Failed to import qutepart.\n" \
"See https://github.com/hlamer/qutepart\n" + \
str(ex) + '\n' + \
_SEE_SITE_PLAIN
_showErrorMessage(True, "Qutepart not found", html, plain)
raise ex
profiler.stepDone('Import Qutepart')
if qutepart.VERSION[0] != enki.core.defines.QUTEPART_SUPPORTED_MAJOR or \
qutepart.VERSION[1] < enki.core.defines.QUTEPART_SUPPORTED_MINOR:
text = "Qutepart version not supported\n" + \
"This Enki version requires Qutepart {}.>={}.*\n". \
format(enki.core.defines.QUTEPART_SUPPORTED_MAJOR,
enki.core.defines.QUTEPART_SUPPORTED_MINOR) + \
"But {}.{}.{} is detected\n\n".format(*qutepart.VERSION)
html = "<html>" + text.replace('\n', '<br/>') + \
_SEE_SITE_HTML + \
"</html>"
plain = text + _SEE_SITE_PLAIN
_showErrorMessage(True, "Not supported Qutepart version", html, plain)
raise ImportError('Not supported Qutepart')
开发者ID:gpa14,项目名称:enki,代码行数:57,代码来源:main.py
示例11: _initPyQt4
def _initPyQt4():
"""initialize PyQt4 to be compatible with PySide"""
if 'PyQt4.QtCore' in sys.modules:
# too late to configure API
pass
else:
import sip
sip.setapi("QString", 2)
sip.setapi("QVariant", 2)
开发者ID:christwell,项目名称:qimage2ndarray,代码行数:9,代码来源:qt_driver.py
示例12: test_sip_api_1_2
def test_sip_api_1_2():
"""sip=1, hint=2 == WARNING"""
import sip
sip.setapi("QString", 1)
os.environ["QT_SIP_API_HINT"] = "2"
with captured_output() as out:
__import__("Qt") # Bypass linter warning
stdout, stderr = out
assert stderr.getvalue().startswith("Warning:")
开发者ID:sonictk,项目名称:Qt.py,代码行数:10,代码来源:tests.py
示例13: _initPyQt4
def _initPyQt4():
"""initialize PyQt4 to be compatible with PySide"""
import sip
if 'PyQt4.QtCore' in sys.modules:
# too late to configure API, let's check that it was properly parameterized...
for api in ('QVariant', 'QString'):
if sip.getapi(api) != 2:
raise RuntimeError('%s API already set to V%d, but should be 2' % (api, sip.getapi(api)))
else:
sip.setapi("QString", 2)
sip.setapi("QVariant", 2)
开发者ID:hmeine,项目名称:pdfdecanter,代码行数:11,代码来源:dynqt.py
示例14: setup_apiv2
def setup_apiv2():
"""
Setup apiv2 when using PyQt4 and Python2.
"""
# setup PyQt api to version 2
if sys.version_info[0] == 2:
logging.getLogger(__name__).debug('setting up SIP API to version 2')
import sip
try:
sip.setapi("QString", 2)
sip.setapi("QVariant", 2)
except ValueError:
logging.getLogger(__name__).critical(
"failed to set up sip api to version 2 for PyQt4")
raise ImportError('PyQt4')
开发者ID:binwen925,项目名称:QMusic,代码行数:15,代码来源:__init__.py
示例15: get_qt
def get_qt():
qtapi = os.environ.get('QT_API', 'pyqt')
# Try PyQt4
if qtapi == 'pyqt' or qtapi == 'pyqt4':
try:
PyQt4 = __import__('PyQt4')
imp.find_module('QtCore', PyQt4.__path__)
imp.find_module('QtGui', PyQt4.__path__)
import sip
except ImportError:
pass
else:
api2_classes = [
'QData', 'QDateTime', 'QString', 'QTextStream',
'QTime', 'QUrl', 'QVariant'
]
for cl in api2_classes:
try:
sip.setapi(cl, 2)
except ValueError:
pass
import PyQt4.QtCore
import PyQt4.QtGui
os.environ['QT_API'] = 'pyqt'
return PyQt4, qtapi
# Try PyQt5
if qtapi == 'pyqt5':
try:
PyQt5 = __import__('PyQt5')
imp.find_module('QtCore', PyQt5.__path__)
imp.find_module('QtGui', PyQt5.__path__)
except ImportError:
pass
else:
import PyQt5.QtCore
import PyQt5.QtGui
import PyQt5.QtWidgets
os.environ['QT_API'] = 'pyqt5'
return PyQt5, qtapi
# Oh no
sys.stderr.write("'file_archive view' requires either PyQt4 or PyQt5\n")
if 'QT_API' in os.environ:
sys.stderr.write("QT_API is currently set to '%s', which is not "
"supported\n" % qtapi)
sys.exit(3)
开发者ID:remram44,项目名称:file_archive,代码行数:46,代码来源:viewer.py
示例16: load_pyqt4
def load_pyqt4():
"""Sets up PyQt4 nicely to be PySide-compatible as much as possible."""
# Kill off QString and QVariant to make it act properly like PySide
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from PyQt4 import QtCore
QtCore._QT_ENGINE = 'PyQt4'
# Also rename the pyqt things for compatibility.
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
QtCore.Property = QtCore.pyqtProperty
global IS_PYQT4
IS_PYQT4 = True
开发者ID:3D1T0R,项目名称:PortableApps.com-DevelopmentToolkit,代码行数:17,代码来源:pyqt4pysideimporter.py
示例17: run
def run(self):
import unittest
import sip
sip.setapi("QString", 2)
sip.setapi("QVariant", 2)
names = []
for filename in glob.glob("test/test_*.py"):
name = os.path.splitext(os.path.basename(filename))[0]
if not self.tests or name in self.tests:
names.append("test." + name)
tests = unittest.defaultTestLoader.loadTestsFromNames(names)
t = unittest.TextTestRunner(verbosity=self.verbosity)
testresult = t.run(tests)
if not testresult.wasSuccessful():
sys.exit("At least one test failed.")
开发者ID:queer1,项目名称:picard,代码行数:18,代码来源:setup.py
示例18: ets
def ets(self, parameter_s=''):
"""Choose backend for ETS GUI
%ets wx|qt
"""
opts, arg = self.parse_options(parameter_s, '')
if arg == "qt":
import sip, os
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
os.environ['ETS_TOOLKIT'] = 'qt4'
elif arg == "wx":
import os
os.environ['ETS_TOOLKIT'] = 'wx'
else:
from IPython.utils.warn import error
error("argument of ets must be wx or qt")
self.shell.enable_gui(arg)
开发者ID:YaoC,项目名称:scpy2,代码行数:18,代码来源:nbmagics.py
示例19: __setPyQt4API
def __setPyQt4API(element, api_version=2):
try:
ver = sip.getapi(element)
except ValueError:
ver = -1
if ver < 0:
try:
sip.setapi(element, api_version)
log.debug("%s API set to version %d",
element, sip.getapi("QString"))
except ValueError:
log.warning("Error setting %s API to version %s", element,
api_version, exc_info=1)
return False
elif ver < api_version:
log.info("%s API set to version %s (advised: version >= %s)",
element, ver, api_version)
return True
开发者ID:ESRF-BCU,项目名称:qarbon,代码行数:19,代码来源:__init__.py
示例20: importPyQt
def importPyQt():
try:
if "PyQt4" in sys.modules:
return True
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
required_modules = ["QtCore", "QtGui", "QtNetwork", "QtWebKit", "uic"]
for module_name in required_modules:
_named_import('PyQt4.%s' % module_name)
from PyQt4.QtCore import pyqtSignal as Signal
from PyQt4.QtCore import pyqtSlot as Slot
from PyQt4.QtCore import pyqtProperty as Property
QtUiTools = object()
def loadUi(uifile, parent=None):
newWidget = uic.loadUi(uifile, parent)
return newWidget
si.LogMessage("[PyQtForSoftimage] Successfully initialized PyQt4.", C.siInfo)
globals().update(
QtCore=QtCore,
QtGui=QtGui,
QtNetwork=QtNetwork,
QtWebKit=QtWebKit,
QtUiTools=QtUiTools,
Signal=Signal,
Slot=Slot,
Property=Property,
loadUi=loadUi,
binding="PyQt4",
)
return True
except ImportError:
return False
开发者ID:caron,项目名称:PyQtForSoftimage,代码行数:42,代码来源:__init__.py
注:本文中的sip.setapi函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论