qt.py
32 lines
| 948 B
| text/x-python
|
PythonLexer
Evan Patterson
|
r3304 | """ A Qt API selector that can be used to switch between PyQt and PySide. | ||
""" | ||||
import os | ||||
epatters
|
r3306 | # Available APIs. | ||
QT_API_PYQT = 'pyqt' | ||||
QT_API_PYSIDE = 'pyside' | ||||
Evan Patterson
|
r3304 | # Use PyQt by default until PySide is stable. | ||
epatters
|
r3306 | QT_API = os.environ.get('QT_API', QT_API_PYQT) | ||
Evan Patterson
|
r3304 | |||
epatters
|
r3306 | if QT_API == QT_API_PYQT: | ||
epatters
|
r3364 | # 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. | ||||
Evan Patterson
|
r3304 | import sip | ||
sip.setapi('QString', 2) | ||||
epatters
|
r3364 | sip.setapi('QVariant', 2) | ||
Evan Patterson
|
r3304 | |||
from PyQt4 import QtCore, QtGui, QtSvg | ||||
# Alias PyQt-specific functions for PySide compatibility. | ||||
QtCore.Signal = QtCore.pyqtSignal | ||||
QtCore.Slot = QtCore.pyqtSlot | ||||
epatters
|
r3306 | elif QT_API == QT_API_PYSIDE: | ||
Evan Patterson
|
r3304 | from PySide import QtCore, QtGui, QtSvg | ||
epatters
|
r3306 | |||
else: | ||||
epatters
|
r3334 | raise RuntimeError('Invalid Qt API %r, valid values are: %r or %r' % | ||
(QT_API, QT_API_PYQT, QT_API_PYSIDE)) | ||||