def testIncubateWhileCall(self): app = QGuiApplication(sys.argv) view = QQuickView() controller = CustomIncubationController(self) view.engine().setIncubationController(controller) view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource( QUrl.fromLocalFile( adjust_filename('qqmlincubator_incubateWhile.qml', __file__))) view.show() root = view.rootObject() # The QML code will issue an interrupt signal after half of its items are loaded. root.shouldInterrupt.connect(controller.interrupter) res = app.exec_() itemsToCreate = root.property("itemsToCreate") loadedItems = root.property("loadedItems") self.assertEqual(loadedItems, itemsToCreate / 2) # Finish incubating the remaining items. controller.incubateFor(1000) loadedItems = root.property("loadedItems") self.assertEqual(loadedItems, itemsToCreate) # Deleting the view before it goes out of scope is required to make sure all child QML # instances are destroyed in the correct order. del view del app
def testMetaData(self): self.view = QWebView() QObject.connect(self.view, SIGNAL('loadFinished(bool)'), self.load_finished) url = QUrl.fromLocalFile(adjust_filename('fox.html', __file__)) self.view.setUrl(url) self.app.exec_()
def testQMLFunctionCall(self): app = QtGui.QGuiApplication(sys.argv) view = QtQuick.QQuickView() obj = PythonObject() context = view.rootContext() context.setContextProperty("python", obj) view.setSource( QtCore.QUrl.fromLocalFile(adjust_filename('bug_451.qml', __file__))) root = view.rootObject() root.simpleFunction() self.assertEqual(obj.called, "simpleFunction") root.oneArgFunction(42) self.assertEqual(obj.called, "oneArgFunction") self.assertEqual(obj.arg1, 42) root.twoArgFunction(10, app) self.assertEqual(obj.called, "twoArgFunction") self.assertEqual(obj.arg1, 10) self.assertEqual(obj.arg2, app) rvalue = root.returnFunction() self.assertEqual(obj.called, "returnFunction") self.assertEqual(rvalue, 42)
def testAbstractItemModelTransferToQML(self): view = QQuickView() model = ListModel() view.rootContext().setContextProperty("pythonModel", model) view.setSource( QUrl.fromLocalFile(adjust_filename('bug_814.qml', __file__))) root = view.rootObject() view.show()
def testIt(self): app = QApplication([]) loader = QUiLoader() widget = loader.load(adjust_filename('bug_913.ui', __file__)) widget.tabWidget.currentIndex() # direct child is available as member widget.le_first.setText( 'foo') # child of QTabWidget must also be available!
def __init__(self): QtWidgets.QWidget.__init__(self) loader = QUiLoader() widget = loader.load(adjust_filename('bug_552.ui', __file__), self) self.children = [] for child in widget.findChildren(QtCore.QObject, None): self.children.append(child) self.t = widget.tabWidget self.t.removeTab(0)
def testSignalEmission(self): qmlRegisterType(MyItem, "my.item", 1, 0, "MyItem") view = QQuickView() view.setSource( QUrl.fromLocalFile(adjust_filename('bug_951.qml', __file__))) self.app.exec_() self.assertTrue(MyItem.COMPONENT_COMPLETE_CALLED)
def __init__(self, parent=None): super(Gui_Qt, self).__init__(parent) lLoader = QtUiTools.QUiLoader() # this used to cause a segfault because the old inject code used to destroy the parent layout self._cw = lLoader.load(adjust_filename('bug_958.ui', __file__), self) self.setCentralWidget(self._cw)
def testIt(self): app = QGuiApplication([]) qmlRegisterType(MyClass, 'Example', 1, 0, 'MyClass') view = QQuickView() view.setSource( QUrl.fromLocalFile(adjust_filename('bug_926.qml', __file__))) self.assertEqual(len(view.errors()), 0) view.show() QTimer.singleShot(0, app.quit) app.exec_()
def testImage(self): #Test loading of sample.png resource f = open(adjust_filename('sample.png', __file__), "rb") orig = f.read() f.close() f = QFile(':/sample.png') f.open(QIODevice.ReadOnly) copy = f.readAll() f.close() self.assertEqual(len(orig), len(copy)) self.assertEqual(orig, copy)
def testPhrase(self): #Test loading of quote.txt resource f = open(adjust_filename('quoteEnUS.txt', __file__), "r") orig = f.read() f.close() f = QFile(':/quote.txt') f.open(QIODevice.ReadOnly) #|QIODevice.Text) print("Error:", f.errorString()) copy = f.readAll() f.close() self.assertEqual(orig, copy)
def testIt(self): global paintCalled app = QGuiApplication([]) qmlRegisterType(Bug825, 'bugs', 1, 0, 'Bug825') self.assertRaises(TypeError, qmlRegisterType, A, 'bugs', 1, 0, 'A') view = QQuickView() view.setSource(QUrl.fromLocalFile(adjust_filename('bug_825.qml', __file__))) view.show() QTimer.singleShot(250, view.close) app.exec_() self.assertTrue(paintCalled)
def test_qml_type(self): qmlRegisterType(TestClass, 'JavaScriptExceptions', 1, 0, 'JavaScriptExceptions') view = QQuickView() qml_url = QUrl.fromLocalFile( adjust_filename('javascript_exceptions.qml', __file__)) view.setSource(qml_url) self.assertTrue(test_1) self.assertTrue(test_2)
def testSlotRetur(self): view = QtQuick.QQuickView() proxy = ProxyObject() context = view.rootContext() context.setContextProperty("proxy", proxy) view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_726.qml', __file__))) root = view.rootObject() button = root.findChild(QtCore.QObject, "buttonMouseArea") view.show() button.entered.emit() self.assertEqual(proxy._receivedName, "PySideObject")
def testQQuickNetworkFactory(self): view = QQuickView() self.factory = CustomFactory() view.engine().setNetworkAccessManagerFactory(self.factory) url = QUrl.fromLocalFile(adjust_filename('hw.qml', __file__)) view.setSource(url) view.show() self.assertEqual(view.status(), QQuickView.Ready) self.app.exec_()
def testIt(self): app = QGuiApplication([]) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice") view = QQuickView() view.setSource( QUrl.fromLocalFile(adjust_filename('registertype.qml', __file__))) view.show() QTimer.singleShot(250, view.close) app.exec_() self.assertTrue(appendCalled) self.assertTrue(paintCalled)
def testSignalArguments(self): view = QQuickView() obj = Obj() context = view.rootContext() context.setContextProperty("o", obj) view.setSource(QUrl.fromLocalFile(adjust_filename('signal_arguments.qml', __file__))) root = view.rootObject() self.assertTrue(root) button = root.findChild(QObject, "button") self.assertTrue(button) view.show() button.clicked.emit() self.assertEqual(obj.value, 42)
def testConversions(self): file_path = adjust_filename('qsettings_test.ini', __file__) settings = QSettings(file_path, QSettings.IniFormat) r = settings.value('var1') self.assertEqual(type(r), list) r = settings.value('var2') if py3k.IS_PY3K: self.assertEqual(type(r), str) else: self.assertEqual(type(r), unicode) r = settings.value('var2', type=list) self.assertEqual(type(r), list)
def testQMLFunctionCall(self): ownerData = QtQml.QQmlPropertyMap() ownerData.insert('name', 'John Smith') ownerData.insert('phone', '555-5555') ownerData.insert('newValue', '') view = QtQuick.QQuickView() ctxt = view.rootContext() ctxt.setContextProperty('owner', ownerData) view.setSource( QtCore.QUrl.fromLocalFile(adjust_filename('bug_997.qml', __file__))) view.show() QtCore.QTimer.singleShot(1000, self.app.quit) self.app.exec_() self.assertEqual(ownerData.value('newName'), ownerData.value('name'))
def testSlotRetur(self): view = QtQuick.QQuickView() rotatevalue = RotateValue() timer = QtCore.QTimer() timer.start(2000) context = view.rootContext() context.setContextProperty("rotatevalue", rotatevalue) view.setSource( QtCore.QUrl.fromLocalFile(adjust_filename('bug_456.qml', __file__))) root = view.rootObject() button = root.findChild(QtCore.QObject, "buttonMouseArea") view.show() button.entered.emit() self.assertEqual(rotatevalue.rotation, 100)
def testQQuickViewList(self): view = QQuickView() dataList = ["Item 1", "Item 2", "Item 3", "Item 4"] ctxt = view.rootContext() ctxt.setContextProperty("myModel", dataList) url = QUrl.fromLocalFile(adjust_filename('view.qml', __file__)) view.setSource(url) view.show() self.assertEqual(view.status(), QQuickView.Ready) rootObject = view.rootObject() self.assertTrue(rootObject) self.assertTrue(QtQml.qmlEngine(rootObject)) self.assertTrue(QtQml.qmlContext(rootObject))
def testModelExport(self): view = QQuickView() dataList = [ MyObject("Item 1"), MyObject("Item 2"), MyObject("Item 3"), MyObject("Item 4") ] ctxt = view.rootContext() ctxt.setContextProperty("myModel", dataList) url = QUrl.fromLocalFile(adjust_filename('viewmodel.qml', __file__)) view.setSource(url) view.show() self.assertEqual(view.status(), QQuickView.Ready)
def testFailConnection(self): self.buttonClicked = False self.buttonFailClicked = False view = QtQuick.QQuickView() view.setSource( QtCore.QUrl.fromLocalFile( adjust_filename('connect_python_qml.qml', __file__))) root = view.rootObject() button = root.findChild(QtCore.QObject, "buttonMouseArea") self.assertRaises( TypeError, QtCore.QObject.connect, [button, QtCore.SIGNAL('entered()'), self.onButtonFailClicked]) button.entered.connect(self.onButtonClicked) button.entered.emit() view.show() self.app.exec_() self.assertTrue(self.buttonClicked)
def testQQuickItemGrabToImageSharedPointer(self): view = QtQuick.QQuickView() view.setSource( QtCore.QUrl.fromLocalFile( adjust_filename('qquickitem_grabToImage.qml', __file__))) view.show() # Get the QQuickItem objects for the blue Rectangle and the Image item. root = view.rootObject() blueRectangle = root.findChild(QtQuick.QQuickItem, "blueRectangle") imageContainer = root.findChild(QtQuick.QQuickItem, "imageContainer") # Start the image grabbing. grabResultSharedPtr = blueRectangle.grabToImage() # Implicit call of operator bool() of the smart pointer, to check that it holds # a valid pointer. self.assertTrue(grabResultSharedPtr) self.grabbedColor = None def onGrabReady(): # Signal early exit. QtCore.QTimer.singleShot(0, self.app.quit) # Show the grabbed image in the QML Image item. imageContainer.setProperty("source", grabResultSharedPtr.url()) # Wait for signal when grabbing is complete. grabResultSharedPtr.ready.connect(onGrabReady) self.app.exec_() # Get the first pixel color of the grabbed image. self.image = grabResultSharedPtr.image() self.assertTrue(self.image) self.grabbedColor = self.image.pixelColor(0, 0) self.assertTrue(self.grabbedColor.isValid()) # Compare the grabbed color with the one we set in the rectangle. blueColor = QtGui.QColor("blue") self.assertEqual(self.grabbedColor, blueColor)
def testPythonSlot(self): self._sucess = False view = View() # Connect first, then set the property. view.called.connect(self.done) view.setSource(QUrl.fromLocalFile(adjust_filename('bug_847.qml', __file__))) while view.status() == QQuickView.Loading: self.app.processEvents() self.assertEqual(view.status(), QQuickView.Ready) self.assertTrue(view.rootObject()) view.rootObject().setProperty('pythonObject', view) view.show() while not view.isExposed(): self.app.processEvents() # Essentially a timeout in case method invocation fails. QTimer.singleShot(30000, QCoreApplication.instance().quit) self.app.exec_() self.assertTrue(self._sucess)
def testQImageStringBuffer(self): '''Test if the QImage signatures receiving string buffers exist.''' img0 = QImage(adjust_filename('sample.png', __file__)) # btw let's test the bits() method img1 = QImage(img0.bits(), img0.width(), img0.height(), img0.format()) self.assertEqual(img0, img1) img2 = QImage(img0.bits(), img0.width(), img0.height(), img0.bytesPerLine(), img0.format()) self.assertEqual(img0, img2) ## test scanLine method data1 = img0.scanLine(0) data2 = img1.scanLine(0) self.assertEqual(data1, data2) # PySide python 3.x does not support slice yet if not py3k.IS_PY3K: buff = py3k.buffer(img0.bits()[:img0.bytesPerLine()]) self.assertEqual(data1, buff) self.assertEqual(data2, buff)
## $QT_END_LICENSE$ ## ############################################################################# ''' unit test for BUG #1060 ''' import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from init_paths import init_test_paths init_test_paths(False) from helper.helper import adjust_filename from PySide2.QtWidgets import QApplication from PySide2.QtUiTools import QUiLoader class MyQUiLoader(QUiLoader): def __init__(self): super(MyQUiLoader, self).__init__() def createWidget(self, *args): return super(MyQUiLoader, self).createWidget(*args) if __name__ == "__main__": app = QApplication([]) ui = MyQUiLoader().load(adjust_filename("bug_1060.ui", __file__)) ui.show()
def testFindSelectText(self): url = QUrl.fromLocalFile(adjust_filename('fox.html', __file__)) self.page.mainFrame().load(url) self.app.exec_() self.assertTrue(self.called)
## included in the packaging of this file. Please review the following ## information to ensure the GNU General Public License requirements will ## be met: https://www.gnu.org/licenses/gpl-3.0.html. ## ## $QT_END_LICENSE$ ## ############################################################################# import os import sys import unittest sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from init_paths import init_test_paths init_test_paths(False) from helper.helper import adjust_filename from PySide2.QtCore import QUrl from PySide2.QtGui import QGuiApplication from PySide2.QtQml import QQmlEngine, QQmlComponent app = QGuiApplication(sys.argv) engine = QQmlEngine() component = QQmlComponent(engine) # This should segfault if the QDeclarativeComponent has not QQmlEngine component.loadUrl(QUrl.fromLocalFile(adjust_filename('foo.qml', __file__)))
def testLoadFinishedFromFile(self): url = QUrl.fromLocalFile(adjust_filename('fox.html', __file__)) self.view.setUrl(url) self.app.exec_() self.assertTrue(self.called)