Updated QtCore modue to works with python 2.x and 3.x
This commit is contained in:
parent
75843bf45a
commit
edaefbce48
8 changed files with 25 additions and 23 deletions
|
|
@ -5,6 +5,7 @@ from PySide.QtCore import QObject, QCoreApplication, QEvent, QThread
|
||||||
|
|
||||||
class MyEvent(QEvent):
|
class MyEvent(QEvent):
|
||||||
def __init__(self,i):
|
def __init__(self,i):
|
||||||
|
print("TYPE:", type(QEvent.User))
|
||||||
super(MyEvent,self).__init__(QEvent.Type(QEvent.User + 100 ))
|
super(MyEvent,self).__init__(QEvent.Type(QEvent.User + 100 ))
|
||||||
self.i = i
|
self.i = i
|
||||||
|
|
||||||
|
|
@ -42,4 +43,6 @@ class CheckForEventsTypes(unittest.TestCase):
|
||||||
o.app = None
|
o.app = None
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
print int(QEvent.User)
|
||||||
|
val = QEvent.User + 100
|
||||||
|
#unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
[General]
|
[General]
|
||||||
x=@Variant(\0\0\0\x7f\0\0\0\x18PySide::PyObjectWrapper\0\0\0\0\x11\x80\x3}q\0K\x1X\x1\0\0\0\x61q\x1s.)
|
x=@Variant(\0\0\0\x7f\0\0\0\x18PySide::PyObjectWrapper\0\0\0\0\x12(dp0\nI1\nS'a'\np1\ns.)
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class QDataStreamShift(unittest.TestCase):
|
||||||
self.stream.writeQChar(None)
|
self.stream.writeQChar(None)
|
||||||
|
|
||||||
res = self.read_stream.readQChar()
|
res = self.read_stream.readQChar()
|
||||||
self.assertEqual(res, py3k.unicode('\x00'))
|
self.assertEqual(res, py3k.unicode_('\x00'))
|
||||||
|
|
||||||
def testQByteArrayValid(self):
|
def testQByteArrayValid(self):
|
||||||
'''QDataStream <<>> QByteArray - valid'''
|
'''QDataStream <<>> QByteArray - valid'''
|
||||||
|
|
@ -124,21 +124,21 @@ class QDataStreamShift(unittest.TestCase):
|
||||||
self.stream.writeQString('Ka-boom')
|
self.stream.writeQString('Ka-boom')
|
||||||
|
|
||||||
res = self.read_stream.readQString()
|
res = self.read_stream.readQString()
|
||||||
self.assertEqual(res, py3k.unicode('Ka-boom'))
|
self.assertEqual(res, py3k.unicode_('Ka-boom'))
|
||||||
|
|
||||||
def testQStringEmpty(self):
|
def testQStringEmpty(self):
|
||||||
'''QDataStream <<>> QString - empty'''
|
'''QDataStream <<>> QString - empty'''
|
||||||
self.stream.writeQString('')
|
self.stream.writeQString('')
|
||||||
|
|
||||||
res = self.read_stream.readQString()
|
res = self.read_stream.readQString()
|
||||||
self.assertEqual(res, py3k.unicode(''))
|
self.assertEqual(res, py3k.unicode_(''))
|
||||||
|
|
||||||
def testQStringNull(self):
|
def testQStringNull(self):
|
||||||
'''QDataStream <<>> QString - null'''
|
'''QDataStream <<>> QString - null'''
|
||||||
self.stream.writeQString(None)
|
self.stream.writeQString(None)
|
||||||
|
|
||||||
res = self.read_stream.readQString()
|
res = self.read_stream.readQString()
|
||||||
self.assertEqual(res, py3k.unicode(''))
|
self.assertEqual(res, py3k.unicode_(''))
|
||||||
|
|
||||||
def testQBitArrayNull(self):
|
def testQBitArrayNull(self):
|
||||||
'''QDataStream <<>> QBitArray - null'''
|
'''QDataStream <<>> QBitArray - null'''
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class ParentCase(unittest.TestCase):
|
||||||
child.setObjectName(name % i)
|
child.setObjectName(name % i)
|
||||||
|
|
||||||
child = parent.findChild(QObject)
|
child = parent.findChild(QObject)
|
||||||
self.assert_(isinstance(child, QObject))
|
self.assertTrue(isinstance(child, QObject))
|
||||||
|
|
||||||
def testFindChildren(self):
|
def testFindChildren(self):
|
||||||
#QObject.findChildren() with all QObject
|
#QObject.findChildren() with all QObject
|
||||||
|
|
@ -105,8 +105,7 @@ class ParentCase(unittest.TestCase):
|
||||||
# Emulates findChildren with the intended outcome
|
# Emulates findChildren with the intended outcome
|
||||||
target_children = [x for x in children if x.objectName() == target_name]
|
target_children = [x for x in children if x.objectName() == target_name]
|
||||||
test_children = parent.findChildren(QObject, target_name)
|
test_children = parent.findChildren(QObject, target_name)
|
||||||
|
self.assertEqual(target_children, test_children)
|
||||||
self.assertEqual(sorted(target_children), sorted(test_children))
|
|
||||||
|
|
||||||
# test findChildren default value
|
# test findChildren default value
|
||||||
res = parent.findChildren(QTimer)
|
res = parent.findChildren(QTimer)
|
||||||
|
|
@ -114,7 +113,7 @@ class ParentCase(unittest.TestCase):
|
||||||
|
|
||||||
# test findChildre with a regex
|
# test findChildre with a regex
|
||||||
res = parent.findChildren(QObject, QRegExp("^fo+"))
|
res = parent.findChildren(QObject, QRegExp("^fo+"))
|
||||||
self.assertEqual(sorted(res), sorted(test_children))
|
self.assertEqual(res, test_children)
|
||||||
|
|
||||||
|
|
||||||
def testParentEquality(self):
|
def testParentEquality(self):
|
||||||
|
|
@ -218,7 +217,7 @@ class ReparentingTest(unittest.TestCase):
|
||||||
object_list.append(obj)
|
object_list.append(obj)
|
||||||
obj.setParent(parent)
|
obj.setParent(parent)
|
||||||
for child in parent.children():
|
for child in parent.children():
|
||||||
self.assert_(child in object_list)
|
self.assertTrue(child in object_list)
|
||||||
|
|
||||||
def testParentedExtQObjectType(self):
|
def testParentedExtQObjectType(self):
|
||||||
object_list = []
|
object_list = []
|
||||||
|
|
@ -241,7 +240,7 @@ class ReparentingTest(unittest.TestCase):
|
||||||
for obj in object_list:
|
for obj in object_list:
|
||||||
obj.setParent(new_parent)
|
obj.setParent(new_parent)
|
||||||
for child in new_parent.children():
|
for child in new_parent.children():
|
||||||
self.assert_(child in object_list)
|
self.assertTrue(child in object_list)
|
||||||
|
|
||||||
def testReparentedExtQObjectType(self):
|
def testReparentedExtQObjectType(self):
|
||||||
object_list = []
|
object_list = []
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class ObjectNameCase(unittest.TestCase):
|
||||||
self.assertEqual('', obj.objectName())
|
self.assertEqual('', obj.objectName())
|
||||||
|
|
||||||
def testUnicode(self):
|
def testUnicode(self):
|
||||||
name = py3k.unicode('diseño')
|
name = py3k.unicode_('não')
|
||||||
#FIXME Strange error on upstream when using equal(name, obj)
|
#FIXME Strange error on upstream when using equal(name, obj)
|
||||||
obj = QObject()
|
obj = QObject()
|
||||||
obj.setObjectName(name)
|
obj.setObjectName(name)
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ class QStringConstructor(unittest.TestCase):
|
||||||
def testQStringDefault(self):
|
def testQStringDefault(self):
|
||||||
obj = QObject()
|
obj = QObject()
|
||||||
obj.setObjectName('foo')
|
obj.setObjectName('foo')
|
||||||
self.assertEqual(obj.objectName(), py3k.unicode('foo'))
|
self.assertEqual(obj.objectName(), py3k.unicode_('foo'))
|
||||||
obj.setObjectName(py3k.unicode('áâãà'))
|
obj.setObjectName(py3k.unicode_('áâãà'))
|
||||||
self.assertEqual(obj.objectName(), py3k.unicode('áâãà'))
|
self.assertEqual(obj.objectName(), py3k.unicode_('áâãà'))
|
||||||
obj.setObjectName(None)
|
obj.setObjectName(None)
|
||||||
self.assertEqual(obj.objectName(), py3k.unicode(''))
|
self.assertEqual(obj.objectName(), py3k.unicode_(''))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class TranslationTest(UsesQCoreApplication):
|
||||||
|
|
||||||
obj = QObject()
|
obj = QObject()
|
||||||
obj.setObjectName(obj.tr('Hello World!'))
|
obj.setObjectName(obj.tr('Hello World!'))
|
||||||
self.assertEqual(obj.objectName(), py3k.unicode('Orbis, te saluto!'))
|
self.assertEqual(obj.objectName(), py3k.unicode_('Orbis, te saluto!'))
|
||||||
|
|
||||||
def testRussian(self):
|
def testRussian(self):
|
||||||
#Set string value to Russian
|
#Set string value to Russian
|
||||||
|
|
@ -35,7 +35,7 @@ class TranslationTest(UsesQCoreApplication):
|
||||||
|
|
||||||
obj = QObject()
|
obj = QObject()
|
||||||
obj.setObjectName(obj.tr('Hello World!'))
|
obj.setObjectName(obj.tr('Hello World!'))
|
||||||
self.assertEqual(obj.objectName(), py3k.unicode('привет мир!'))
|
self.assertEqual(obj.objectName(), py3k.unicode_('привет мир!'))
|
||||||
|
|
||||||
def testUtf8(self):
|
def testUtf8(self):
|
||||||
translator = QTranslator()
|
translator = QTranslator()
|
||||||
|
|
@ -44,7 +44,7 @@ class TranslationTest(UsesQCoreApplication):
|
||||||
|
|
||||||
obj = QObject()
|
obj = QObject()
|
||||||
obj.setObjectName(obj.trUtf8('Hello World!'))
|
obj.setObjectName(obj.trUtf8('Hello World!'))
|
||||||
self.assertEqual(obj.objectName(), py3k.unicode('привет мир!'))
|
self.assertEqual(obj.objectName(), py3k.unicode_('привет мир!'))
|
||||||
|
|
||||||
def testTranslateWithNoneDisambiguation(self):
|
def testTranslateWithNoneDisambiguation(self):
|
||||||
value = 'String here'
|
value = 'String here'
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,13 @@ class UnicodeConversion(unittest.TestCase):
|
||||||
#Set regular Python string retrieve unicode
|
#Set regular Python string retrieve unicode
|
||||||
obj = QObject()
|
obj = QObject()
|
||||||
obj.setObjectName('test')
|
obj.setObjectName('test')
|
||||||
self.assertEqual(obj.objectName(), py3k.unicode('test'))
|
self.assertEqual(obj.objectName(), py3k.unicode_('test'))
|
||||||
|
|
||||||
def testSetUnicodeRetrieveUnicode(self):
|
def testSetUnicodeRetrieveUnicode(self):
|
||||||
#Set Python unicode string and retrieve unicode
|
#Set Python unicode string and retrieve unicode
|
||||||
obj = QObject()
|
obj = QObject()
|
||||||
obj.setObjectName(py3k.unicode('ümlaut'))
|
obj.setObjectName(py3k.unicode_('ümlaut'))
|
||||||
self.assertEqual(obj.objectName(), py3k.unicode('ümlaut'))
|
self.assertEqual(obj.objectName(), py3k.unicode_('ümlaut'))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue