Qt5 binding enhancements

- Based on Qt 5.12.12 now (tested to build on 5.15)
- QImage constructor with binary data
- More classes, specifically QLibraryInfo for Qt version
- QLayout and derivatives take ownership over widgets added
This commit is contained in:
Matthias Koefferlein
2023-03-25 22:54:54 +01:00
parent 9a1c776475
commit 31aa45dce4
486 changed files with 42165 additions and 25655 deletions
+37
View File
@@ -649,6 +649,43 @@ class QtBindingTest(unittest.TestCase):
self.assertEqual(item.background(0).color.green, 255)
self.assertEqual(item.background(0).color.blue, 0)
def test_55(self):
# addWidget to QHBoxLayout keeps object managed
window = pya.QDialog()
layout = pya.QHBoxLayout(window)
w = pya.QPushButton()
oid = str(w)
layout.addWidget(w)
self.assertEqual(str(layout.itemAt(0).widget()), oid)
# try to kill the object
w = None
# still there
w = layout.itemAt(0).widget()
self.assertEqual(w._destroyed(), False)
self.assertEqual(str(w), oid)
# killing the window kills the layout kills the widget
window._destroy()
self.assertEqual(window._destroyed(), True)
self.assertEqual(layout._destroyed(), True)
self.assertEqual(w._destroyed(), True)
def test_56(self):
# Creating QImage from binary data
bstr = b'\x01\x02\x03\x04\x11\x12\x13\x14\x21\x22\x33\x34' + b'\x31\x32\x33\x34\x41\x42\x43\x44\x51\x52\x53\x54' + b'\x61\x62\x63\x64\x71\x72\x73\x74\x81\x82\x83\x84' + b'\x91\x92\x93\x94\xa1\xa2\xa3\xa4\xb1\xb2\xb3\xb4'
image = pya.QImage(bstr, 3, 4, pya.QImage.Format_ARGB32)
self.assertEqual("%08x" % image.pixel(0, 0), "04030201")
self.assertEqual("%08x" % image.pixel(1, 0), "14131211")
self.assertEqual("%08x" % image.pixel(0, 2), "64636261")
# run unit tests
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(QtBindingTest)
+49 -4
View File
@@ -272,21 +272,21 @@ class QtBinding_TestClass < TestBase
label = RBA::QLabel::new(dialog)
layout = RBA::QHBoxLayout::new(dialog)
layout.addWidget(label)
label.destroy
label._destroy
GC.start
dialog = RBA::QDialog::new(mw)
label = RBA::QLabel::new(dialog)
layout = RBA::QHBoxLayout::new(dialog)
layout.addWidget(label)
layout.destroy
layout._destroy
GC.start
dialog = RBA::QDialog::new(mw)
label = RBA::QLabel::new(dialog)
layout = RBA::QHBoxLayout::new(dialog)
layout.addWidget(label)
dialog.destroy
dialog._destroy
GC.start
dialog = RBA::QDialog::new(mw)
@@ -740,7 +740,7 @@ class QtBinding_TestClass < TestBase
img.save(buf, "PNG")
assert_equal(buf.data.size > 100, true)
assert_equal(buf.data[0..7].inspect, "\"\\x89PNG\\r\\n\\x1A\\n\"")
assert_equal(buf.data[0..7].unpack("C*"), [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
end
@@ -767,6 +767,51 @@ class QtBinding_TestClass < TestBase
end
def test_55
# addWidget to QHBoxLayout keeps object managed
window = RBA::QDialog::new
layout = RBA::QHBoxLayout::new(window)
w = RBA::QPushButton::new
oid = w.object_id
layout.addWidget(w)
assert_equal(layout.itemAt(0).widget.object_id, oid)
# try to kill the object
w = nil
GC.start
# still there
w = layout.itemAt(0).widget
assert_equal(w._destroyed?, false)
assert_equal(w.object_id, oid)
# killing the window kills the layout kills the widget
window._destroy
assert_equal(window._destroyed?, true)
assert_equal(layout._destroyed?, true)
assert_equal(w._destroyed?, true)
end
def test_56
# Creating QImage from binary data
bytes = [ 0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14, 0x21, 0x22, 0x33, 0x34,
0x31, 0x32, 0x33, 0x34, 0x41, 0x42, 0x43, 0x44, 0x51, 0x52, 0x53, 0x54,
0x61, 0x62, 0x63, 0x64, 0x71, 0x72, 0x73, 0x74, 0x81, 0x82, 0x83, 0x84,
0x91, 0x92, 0x93, 0x94, 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xb3, 0xb4 ].pack("C*")
image = RBA::QImage::new(bytes, 3, 4, RBA::QImage::Format_ARGB32)
assert_equal("%08x" % image.pixel(0, 0), "04030201")
assert_equal("%08x" % image.pixel(1, 0), "14131211")
assert_equal("%08x" % image.pixel(0, 2), "64636261")
end
end
load("test_epilogue.rb")