本文整理汇总了Python中sip.getapi函数的典型用法代码示例。如果您正苦于以下问题:Python getapi函数的具体用法?Python getapi怎么用?Python getapi使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getapi函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sip_api_qtpy
def test_sip_api_qtpy():
"""Preferred binding PyQt4 should have sip version 2"""
__import__("Qt") # Bypass linter warning
import sip
assert sip.getapi("QString") == 2, ("PyQt4 API version should be 2, "
"instead is %s"
% sip.getapi("QString"))
示例2: _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)
示例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
示例4: sip_getapi
def sip_getapi(name):
"""
Get the api version for a name.
"""
if sip.SIP_VERSION > 0x40900:
return sip.getapi(name)
elif name in _API_NAMES:
return 1
else:
raise ValueError("unknown API {0!r}".format(name))
示例5: __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
示例6: load_Qt4
def load_Qt4():
from PyQt4 import QtGui, QtCore
# Alias PyQt-specific functions for PySide compatibility.
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
version = sip.getapi('QString')
api = 'pyqt4' if version == 1 else 'pyqt4v2'
return QtCore, QtGui, api
示例7: uni
def uni(s, encoding="gbk"):
if sip.getapi("QString") != 2: # api=2时QString会自动变为str类型
if isinstance(s, QtCore.QString):
s = unicode(s)
if isinstance(s, unicode):
return s
elif isinstance(s, str):
return unicode(s, encoding)
else:
return unicode(s)
示例8: requireCompatibleAPI
def requireCompatibleAPI():
"""If PyQt4's API should be configured to be compatible with PySide's
(i.e. QString and QVariant should not be explicitly exported,
cf. documentation of sip.setapi()), call this function to check that
the PyQt4 was properly imported. (It will always be configured this
way by this module, but it could have been imported before we got a
hand on doing so.)
"""
if 'PyQt4.QtCore' in sys.modules:
import sip
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)))
示例9: utf8
def utf8(u, encoding="gbk"):
'''
string convert (gbk -> utf-8)
'''
if sip.getapi("QString") != 2: # api=2时QString会自动变为str类型
if isinstance(u, QtCore.QString):
u = unicode(u)
if isinstance(u, unicode):
return u.encode("utf-8")
elif encoding == "utf-8":
return u
else:
return unicode(u, encoding).encode("utf-8")
示例10: qtapi_version
def qtapi_version():
"""Return which QString API has been set, if any
Returns
-------
The QString API version (1 or 2), or None if not set
"""
try:
import sip
except ImportError:
return
try:
return sip.getapi('QString')
except ValueError:
return
示例11: run
def run(self):
# show the dialog
self.dlg.show()
text = self.dlg.ui.text
text.append("QGIS " + QGis.QGIS_VERSION)
text.append("SIP " + sip.SIP_VERSION_STR + " API V" + str(sip.getapi("QVariant")))
text.append("\n")
tests = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(TestQvariant),
unittest.TestLoader().loadTestsFromTestCase(TestQstring),
unittest.TestLoader().loadTestsFromTestCase(TestVectorapi)])
unittest.TextTestRunner(verbosity=2, stream=self.dlg).run(tests)
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result == 1:
pass
示例12: __init__
def __init__(self):
"""Constructor"""
# Determine the sip api that is used, because this depends on whether
# or not IPython is loaded
object.__setattr__(self, u'api', sip.getapi(u'QString'))
if self.api not in (1,2):
raise Exception(u'config: unknown api %s' % self.api)
# Apply OS specific override settings
if platform.system() == u"Windows":
for key, value in self.config_windows.iteritems():
self.config[key] = value
elif platform.system() == u"Darwin":
for key, value in self.config_mac.iteritems():
self.config[key] = value
elif platform.system() == u"Linux":
for key, value in self.config_linux.iteritems():
self.config[key] = value
示例13: __init__
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/geometry_copier"
# initialize locale
locale_path = ""
if sip.getapi("QVariant") > 1:
# new API style
locale = QSettings().value("locale/userLocale")[0:2]
else:
# the old API style
locale = QSettings().value("locale/userLocale").toString()[0:2]
if QFileInfo(self.plugin_dir).exists():
locale_path = self.plugin_dir + "/i18n/geometry_copier_" + locale + ".qm"
if QFileInfo(locale_path).exists():
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
self._geom_buffer = None
示例14: isSIPv2
def isSIPv2():
return sip.getapi("QVariant") > 1
示例15: Exception
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSesame. If not, see <http://www.gnu.org/licenses/>.
"""
from PyQt4 import QtCore
import libopensesame.misc
from libopensesame import debug
# Determine the sip api that is used, because this depends on whether or not
# IPython is loaded
import sip
api = sip.getapi('QString')
if api not in (1,2):
raise Exception('config: unknown api %s' % api)
config = {
"cfg_ver" : 0,
"_initial_window_state" : QtCore.QByteArray(),
"auto_update_check" : True,
"auto_response" : False,
"autosave_interval" : 10 * 60 * 1000,
"autosave_max_age" : 7,
"default_logfile_folder" : libopensesame.misc.home_folder(),
"disabled_plugins" : "",
"immediate_rename" : False,
"onetabmode" : False,
"overview_info" : False,