Skip to content

Unicode utf8 is deprecated #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
25 changes: 22 additions & 3 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

def _pyqt5():
import PyQt5.Qt
from PyQt5 import QtWidgets

# Remap
PyQt5.QtCore.Signal = PyQt5.QtCore.pyqtSignal
Expand All @@ -39,6 +40,16 @@ def _pyqt5():
PyQt5.__qt_version__ = PyQt5.QtCore.QT_VERSION_STR
PyQt5.load_ui = pyqt5_load_ui

# provide mocked UnicodeUTF8 For backward compatibility
QtWidgets.QApplication.UnicodeUTF8 = -1

old_translate_fn = QtWidgets.QApplication.translate

def translate(context, key, disambiguation=None, encoding=None, n=0):
return old_translate_fn(context, key, disambiguation, n)

QtWidgets.QApplication.translate = staticmethod(translate)

return PyQt5


Expand Down Expand Up @@ -89,7 +100,7 @@ def _pyqt4():

def _pyside2():
import PySide2
from PySide2 import QtGui, QtCore
from PySide2 import QtGui, QtCore, QtWidgets

# Remap
QtCore.QStringListModel = QtGui.QStringListModel
Expand All @@ -101,6 +112,16 @@ def _pyside2():
PySide2.__qt_version__ = PySide2.QtCore.qVersion()
PySide2.load_ui = pyside2_load_ui

# provide mocked UnicodeUTF8 For backward compatibility
QtWidgets.QApplication.UnicodeUTF8 = -1

old_translate_fn = QtWidgets.QApplication.translate

def translate(context, key, disambiguation=None, encoding=None, n=0):
return old_translate_fn(context, key, disambiguation, n)

QtWidgets.QApplication.translate = staticmethod(translate)

return PySide2


Expand Down Expand Up @@ -204,13 +225,11 @@ def _init():
this has executed.

"""

preferred = os.getenv("QT_PREFERRED_BINDING")
verbose = os.getenv("QT_VERBOSE") is not None
bindings = (_pyside2, _pyqt5, _pyside, _pyqt4)

if preferred:

# Internal flag (used in installer)
if preferred == "None":
sys.modules[__name__].__wrapper_version__ = __version__
Expand Down
101 changes: 101 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,104 @@ def test_sip_api_already_set():
import sip
sip.setapi("QString", 1)
assert_raises(ImportError, __import__, "Qt")


def test_translate_and_UnicodeUTF8_in_pyside():
_str_ = str
if PYTHON == 2:
_str_ = basestring

with pyside():
from Qt import QtWidgets

# this does exist in PySide
assert QtWidgets.QApplication.UnicodeUTF8 is not None

# use patched method with old arguments
result = QtWidgets.QApplication.translate(
u'Href_Gui',
u'Text',
u'None',
QtWidgets.QApplication.UnicodeUTF8
)
assert isinstance(result, _str_)


def test_translate_and_UnicodeUTF8_in_pyqt4():
_str_ = str
if PYTHON == 2:
_str_ = basestring

with pyqt4():
from Qt import QtWidgets

# this does exist in PyQt4
assert QtWidgets.QApplication.UnicodeUTF8 is not None

# use patched method with old arguments
result = QtWidgets.QApplication.translate(
u'Href_Gui',
u'Text',
u'None',
QtWidgets.QApplication.UnicodeUTF8
)

assert isinstance(result, _str_)


def test_translate_and_UnicodeUTF8_in_pyside2():
_str_ = str
if PYTHON == 2:
_str_ = basestring

with pyside2():
from Qt import QtWidgets

# this does not exist in PySide2 by default
assert QtWidgets.QApplication.UnicodeUTF8 is -1

# use patched method with old arguments
result = QtWidgets.QApplication.translate(
u'Href_Gui',
u'Text',
u'None',
QtWidgets.QApplication.UnicodeUTF8
)
assert isinstance(result, _str_)

# use patched method with new arguments
result = QtWidgets.QApplication.translate(
u'SomeText',
u'Form',
u'None'
)
assert isinstance(result, _str_)


def test_translate_and_UnicodeUTF8_in_PyQt5():
_str_ = str
if PYTHON == 2:
_str_ = basestring

with pyqt5():
from Qt import QtWidgets

# this does not exist in PyQt5 by default
assert QtWidgets.QApplication.UnicodeUTF8 is -1

# use patched method with old arguments
result = QtWidgets.QApplication.translate(
u'SomeText',
u'Form',
u'None',
QtWidgets.QApplication.UnicodeUTF8
)
assert isinstance(result, _str_)

# use patched method with new arguments
result = QtWidgets.QApplication.translate(
u'SomeText',
u'Form',
u'None'
)
assert isinstance(result, _str_)