Merge branch 'wip'

This commit is contained in:
Matthias Koefferlein
2023-10-19 21:23:07 +02:00
839 changed files with 84456 additions and 46678 deletions
+48 -3
View File
@@ -1400,10 +1400,55 @@ class BasicTest(unittest.TestCase):
def f4():
n[0] = n[0] + 2
n[0] = 0
e.e0(f4)
e.s1()
self.assertEqual( 4, n[0] )
self.assertEqual( 2, n[0] )
# remove event handler -> no events triggered anymore
n[0] = 0
e.e0 -= f4
e.s1()
self.assertEqual( 0, n[0] )
# adding again will re-activate it
e.e0 += f4
n[0] = 0
e.s1()
self.assertEqual( 2, n[0] )
# two events at once
def f5():
n[0] = n[0] + 10
n[0] = 0
e.e0 += f5
e.s1()
self.assertEqual( 12, n[0] )
# clearing events
e.e0.clear()
e.s1()
n[0] = 0
self.assertEqual( 0, n[0] )
# synonyms: add, connect
e.e0.add(f4)
e.e0.connect(f5)
n[0] = 0
e.s1()
self.assertEqual( 12, n[0] )
# synonyms: remove, disconnect
e.e0.disconnect(f4)
n[0] = 0
e.s1()
self.assertEqual( 10, n[0] )
n[0] = 0
e.e0.remove(f5)
e.s1()
self.assertEqual( 0, n[0] )
# another signal
e.s2()
self.assertEqual( 100, n[1] )
e.m = 1
@@ -1975,11 +2020,11 @@ class BasicTest(unittest.TestCase):
# Hint: QApplication creates some leaks (FT, GTK). Hence it must not be used in the leak_check case ..
if not leak_check:
a = pya.QCoreApplication.instance()
self.assertEqual("<class 'pya.Application'>", str(type(a)))
self.assertEqual("<class 'klayout.pyacore.Application'>", str(type(a)))
qd = pya.QDialog()
pya.QApplication.setActiveWindow(qd)
self.assertEqual(repr(pya.QApplication.activeWindow), repr(qd))
self.assertEqual("<class 'pya.QDialog'>", str(type(pya.QApplication.activeWindow)))
self.assertEqual("<class 'klayout.pyacore.QDialog'>", str(type(pya.QApplication.activeWindow)))
qd._destroy()
self.assertEqual(repr(pya.QApplication.activeWindow), "None")
+54
View File
@@ -0,0 +1,54 @@
# KLayout Layout Viewer
# Copyright (C) 2006-2023 Matthias Koefferlein
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import pya
import unittest
class LAYObjectsTests(unittest.TestCase):
def test_1(self):
class MyBrowserSource(pya.BrowserSource):
def get(self, url):
next_url = "int:" + str(int(url.split(":")[1]) + 1)
return f"This is {url}. <a href='{next_url}'>Goto next ({next_url})</a>"
dialog = pya.BrowserDialog()
dialog.home = "int:0"
dialog.source = MyBrowserSource()
dialog = pya.BrowserDialog()
dialog.home = "int:0"
dialog.source = MyBrowserSource()
self.assertEqual(True, True)
# run unit tests
if __name__ == '__main__':
suite = unittest.TestSuite()
# NOTE: Use this instead of loadTestsfromTestCase to select a specific test:
# suite.addTest(BasicTest("test_26"))
suite = unittest.TestLoader().loadTestsFromTestCase(LAYObjectsTests)
# Only runs with Application available
if "Application" in pya.__all__ and not unittest.TextTestRunner(verbosity = 1).run(suite).wasSuccessful():
sys.exit(1)
+75
View File
@@ -649,6 +649,81 @@ 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")
def test_57(self):
# QColor with string parameter (suppressing QLatin1String)
color = pya.QColor("blue")
self.assertEqual(color.name(), "#0000ff")
def test_58(self):
# The various ways to refer to enums
self.assertEqual(pya.Qt.MouseButton(4).to_i(), 4)
self.assertEqual(pya.Qt_MouseButton(4).to_i(), 4)
self.assertEqual(pya.Qt_MouseButton(4).__int__(), 4)
self.assertEqual(pya.Qt_MouseButton(4).__hash__(), 4)
self.assertEqual(int(pya.Qt_MouseButton(4)), 4)
self.assertEqual(str(pya.Qt_MouseButton(1)), "LeftButton")
self.assertEqual(pya.Qt.MouseButton.LeftButton.to_i(), 1)
self.assertEqual(pya.Qt_MouseButton.LeftButton.to_i(), 1)
self.assertEqual(pya.Qt.LeftButton.to_i(), 1)
self.assertEqual((pya.Qt_MouseButton.LeftButton | pya.Qt_MouseButton.RightButton).to_i(), 3)
self.assertEqual(type(pya.Qt_MouseButton.LeftButton | pya.Qt_MouseButton.RightButton).__name__, "Qt_QFlags_MouseButton")
self.assertEqual((pya.Qt.MouseButton.LeftButton | pya.Qt.MouseButton.RightButton).to_i(), 3)
self.assertEqual(type(pya.Qt.MouseButton.LeftButton | pya.Qt.MouseButton.RightButton).__name__, "Qt_QFlags_MouseButton")
self.assertEqual((pya.Qt.LeftButton | pya.Qt.RightButton).to_i(), 3)
self.assertEqual(type(pya.Qt.LeftButton | pya.Qt.RightButton).__name__, "Qt_QFlags_MouseButton")
def test_59(self):
# Enums can act as hash keys
h = {}
h[pya.Qt.MouseButton.LeftButton] = "left"
h[pya.Qt.MouseButton.RightButton] = "right"
self.assertEqual(pya.Qt.MouseButton.LeftButton in h, True)
self.assertEqual(h[pya.Qt.MouseButton.LeftButton], "left")
self.assertEqual(h[pya.Qt.MouseButton.RightButton], "right")
self.assertEqual(pya.Qt.MouseButton.NoButton in h, False)
# run unit tests
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(QtBindingTest)