summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PySide/CMakeLists.txt1
-rw-r--r--PySide/QtUiTools/CMakeLists.txt40
-rw-r--r--PySide/QtUiTools/typesystem_uitools.xml52
-rw-r--r--tests/qtuitools/uiloader_test.py26
4 files changed, 104 insertions, 15 deletions
diff --git a/PySide/CMakeLists.txt b/PySide/CMakeLists.txt
index 6b8b3b2a..c74e0b93 100644
--- a/PySide/CMakeLists.txt
+++ b/PySide/CMakeLists.txt
@@ -39,3 +39,4 @@ HAS_QT_MODULE(QT_QTXML_FOUND QtXml)
HAS_QT_MODULE(QT_QTTEST_FOUND QtTest)
HAS_QT_MODULE(QT_QTOPENGL_FOUND QtOpenGL)
HAS_QT_MODULE(QT_QTSQL_FOUND QtSql)
+HAS_QT_MODULE(QT_QTUITOOLS_FOUND QtUiTools)
diff --git a/PySide/QtUiTools/CMakeLists.txt b/PySide/QtUiTools/CMakeLists.txt
new file mode 100644
index 00000000..1145f976
--- /dev/null
+++ b/PySide/QtUiTools/CMakeLists.txt
@@ -0,0 +1,40 @@
+project(QtUiTools)
+
+set(QtUiTools_SRC
+ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtUiTools/qtuitools_module_wrapper.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtUiTools/quiloader_wrapper.cpp
+)
+
+execute_generator(uitools QtUiTools_SRC "${CMAKE_CURRENT_BINARY_DIR}:${QtCore_SOURCE_DIR}:${QtGui_BINARY_DIR}:${QtGui_SOURCE_DIR}:${QtXml_SOURCE_DIR}:${QtUiTools_SOURCE_DIR}")
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+ ${QT_QTCORE_INCLUDE_DIR}
+ ${QT_QTGUI_INCLUDE_DIR}
+ ${QT_QTXML_INCLUDE_DIR}
+ ${QT_QTUITOOLS_INCLUDE_DIR}
+ ${PYTHON_INCLUDE_PATH}
+ ${SHIBOKEN_INCLUDE_DIR}
+ ${libpyside_SOURCE_DIR}
+ ${QtCore_BINARY_DIR}/PySide/QtCore/
+ ${QtXml_BINARY_DIR}/PySide/QtXml/
+ ${QtGui_BINARY_DIR}/PySide/QtGui/
+ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtUiTools)
+
+add_library(QtUiTools MODULE ${QtUiTools_SRC})
+set_target_properties(QtUiTools PROPERTIES PREFIX "")
+target_link_libraries(QtUiTools
+ pyside
+ ${PYTHON_LIBRARIES}
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTGUI_LIBRARY}
+ ${QT_QTXML_LIBRARY}
+ ${QT_QTUITOOLS_LIBRARY})
+
+add_dependencies(QtUiTools QtGui QtXml)
+
+# install
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/QtUiTools.so
+ DESTINATION ${SITE_PACKAGE}/PySide)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtUiTools/pyside_qtuitools_python.h
+ DESTINATION include/PySide/QtUiTools/)
+
diff --git a/PySide/QtUiTools/typesystem_uitools.xml b/PySide/QtUiTools/typesystem_uitools.xml
new file mode 100644
index 00000000..c155bff9
--- /dev/null
+++ b/PySide/QtUiTools/typesystem_uitools.xml
@@ -0,0 +1,52 @@
+<typesystem package="PySide.QtUiTools">
+
+ <load-typesystem name="typesystem_gui.xml" generate="no" />
+ <load-typesystem name="typesystem_xml.xml" generate="no" />
+
+ <object-type name="QUiLoader">
+ <modify-function signature="createAction(QObject *, const QString&amp;)">
+ <modify-argument index="return">
+ <parent index="1" action="add"/>
+ </modify-argument>
+ </modify-function>
+
+ <modify-function signature="createActionGroup(QObject *, const QString&amp;)">
+ <modify-argument index="return">
+ <parent index="1" action="add"/>
+ </modify-argument>
+ </modify-function>
+
+ <modify-function signature="createLayout(const QString&amp;,QObject *, const QString&amp;)">
+ <modify-argument index="return">
+ <parent index="2" action="add"/>
+ </modify-argument>
+ </modify-function>
+
+ <modify-function signature="createWidget(const QString&amp;,QWidget*, const QString&amp;)">
+ <modify-argument index="return">
+ <parent index="2" action="add"/>
+ </modify-argument>
+ </modify-function>
+
+ <modify-function signature="load(QIODevice*, QWidget*)">
+ <modify-argument index="return">
+ <parent index="2" action="add"/>
+ </modify-argument>
+ </modify-function>
+
+ <!-- Syntax sugar -->
+ <add-function signature="load(const char*, QWidget*)" return-type="QWidget*">
+ <modify-argument index="return">
+ <parent index="2" action="add"/>
+ </modify-argument>
+ <inject-code>
+ QFile f(%1);
+ if (f.open(QIODevice::ReadOnly | QIODevice::Text))
+ %PYARG_0 = %CONVERTTOPYTHON[QWidget*](%CPPSELF.load(&amp;f, %2));
+ else
+ PyErr_SetString(PyExc_RuntimeError, "Unable to open ui file");
+ </inject-code>
+ </add-function>
+ </object-type>
+
+</typesystem>
diff --git a/tests/qtuitools/uiloader_test.py b/tests/qtuitools/uiloader_test.py
index 83dd9c46..fe3725ba 100644
--- a/tests/qtuitools/uiloader_test.py
+++ b/tests/qtuitools/uiloader_test.py
@@ -2,11 +2,8 @@ import unittest
import os
from helper import UsesQApplication
-from PySide.QtGui import QWidget, QFrame, QPushButton
-from PySide.QtUiTools import QUiLoader
-
-#ugly workaround for work with ctest
-file_path = [ "./test.ui", "./qtuitools/test.ui", "../tests/qtuitools/test.ui", "../../tests/qtuitools/test.ui" ]
+from PySide.QtGui import *
+from PySide.QtUiTools import *
def get_file_path():
for path in file_path:
@@ -16,18 +13,17 @@ def get_file_path():
class QUioaderTeste(UsesQApplication):
def testLoadFile(self):
- widget = QWidget()
-
- file_path = get_file_path()
- self.assertTrue(file_path != "")
-
- QUiLoader.loadUi(file_path, widget)
+ filePath = os.path.join(os.path.dirname(__file__), 'test.ui')
+ loader = QUiLoader()
+ parent = QWidget()
+ w = loader.load(filePath, parent)
+ self.assertNotEqual(w, None)
- self.assertTrue("child_object" in dir(widget))
- self.assertTrue("grandson_object" in dir(widget.child_object))
+ self.assertEqual(len(parent.children()), 1)
- self.assertEqual(type(widget.child_object), QFrame)
- self.assertEqual(type(widget.child_object.grandson_object), QPushButton)
+ child = w.findChild(QWidget, "child_object")
+ self.assertNotEqual(child, None)
+ self.assertEqual(w.findChild(QWidget, "grandson_object"), child.findChild(QWidget, "grandson_object"))
if __name__ == '__main__':
unittest.main()