Skip to content

Commit

Permalink
Merge pull request #121 from abstractfactory/documentation
Browse files Browse the repository at this point in the history
Update documentation for load_ui
  • Loading branch information
mottosso authored Aug 30, 2016
2 parents ed0af1f + 4691451 commit 6f39c2c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ app.exec_()

All members of `Qt` stem directly from those available via PySide2, along with these additional members.

| Attribute | Type | Value
|:------------------------|:-------|:------------
| `__binding__` | `str` | A string reference to binding currently in use
| `__qt_version__` | `str` | Reference to version of Qt, such as Qt 5.6.1
| `__binding_version__` | `str` | Reference to version of binding, such as PySide 1.2.6
| `__wrapper_version__` | `str` | Version of this project
| `load_ui()` | `func` | Minimal wrapper of PyQt4.loadUi and PySide equivalent
| Attribute | Returns | Description
|:------------------------|:----------|:------------
| `__binding__` | `str` | A string reference to binding currently in use
| `__qt_version__` | `str` | Reference to version of Qt, such as Qt 5.6.1
| `__binding_version__` | `str` | Reference to version of binding, such as PySide 1.2.6
| `__wrapper_version__` | `str` | Version of this project
| `load_ui(fname=str)` | `QObject` | Minimal wrapper of PyQt4.loadUi and PySide equivalent

<br>

Expand Down Expand Up @@ -136,12 +136,12 @@ import sys
import Qt

app = QtWidgets.QApplication(sys.argv)
ui = Qt.load_ui("my.ui")
ui = Qt.load_ui(fname="my.ui")
ui.show()
app.exec_()
```

Please note, for maximum compatibility, only pass the argument of the filename to the `load_ui` function.
Please note, `load_ui` has only one argument, whereas the PyQt and PySide equivalent has more. See [here](https://github.com/mottosso/Qt.py/pull/81) for details - in a nutshell, those arguments differ between PyQt and PySide in incompatible ways.

<br>

Expand Down
75 changes: 75 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import os
import io
import sys
import imp
import shutil
Expand All @@ -24,6 +25,36 @@

def setup():
self.tempdir = tempfile.mkdtemp()
self.ui_qwidget = os.path.join(self.tempdir, "qwidget.ui")

with io.open(self.ui_qwidget, "w", encoding="utf-8") as f:
f.write(u"""\
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>235</width>
<height>149</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLineEdit" name="lineEdit"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
"""
)


def teardown():
Expand Down Expand Up @@ -143,6 +174,50 @@ def test_sip_api_qtpy():
% sip.getapi("QString"))


def test_pyside_load_ui_returntype():
"""load_ui returns an instance of QObject with PySide"""

with pyside():
import sys
from Qt import QtWidgets, QtCore, load_ui
app = QtWidgets.QApplication(sys.argv)
obj = load_ui(self.ui_qwidget)
assert isinstance(obj, QtCore.QObject)


def test_pyqt4_load_ui_returntype():
"""load_ui returns an instance of QObject with PyQt4"""

with pyqt4():
import sys
from Qt import QtWidgets, QtCore, load_ui
app = QtWidgets.QApplication(sys.argv)
obj = load_ui(self.ui_qwidget)
assert isinstance(obj, QtCore.QObject)


def test_pyside2_load_ui_returntype():
"""load_ui returns an instance of QObject with PySide2"""

with pyside2():
import sys
from Qt import QtWidgets, QtCore, load_ui
app = QtWidgets.QApplication(sys.argv)
obj = load_ui(self.ui_qwidget)
assert isinstance(obj, QtCore.QObject)


def test_pyqt5_load_ui_returntype():
"""load_ui returns an instance of QObject with PyQt5"""

with pyqt5():
import sys
from Qt import QtWidgets, QtCore, load_ui
app = QtWidgets.QApplication(sys.argv)
obj = load_ui(self.ui_qwidget)
assert isinstance(obj, QtCore.QObject)


def test_vendoring():
"""Qt.py may be bundled along with another library/project
Expand Down

0 comments on commit 6f39c2c

Please sign in to comment.