Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support secondary arguments support to load_ui #81

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d286429
Add tests for improvements in load_ui
fredrikaverpil Jul 28, 2016
b9a5d96
Add distinguishable test descriptions
fredrikaverpil Jul 28, 2016
1b068a1
Add support for additional load_ui arguments
fredrikaverpil Jul 28, 2016
dfa8587
Specify a non-binary mode
fredrikaverpil Jul 28, 2016
174833e
Update with load_ui additional arguments info
fredrikaverpil Jul 28, 2016
c61b33d
Remove QMenuBar and QStatusBar from UI
fredrikaverpil Jul 28, 2016
73920a9
Revert "Remove QMenuBar and QStatusBar from UI"
fredrikaverpil Jul 28, 2016
c6dc043
Simplify tests
mottosso Jul 29, 2016
ce6fb63
Merge pull request #2 from abstractfactory/feature/load_ui
fredrikaverpil Jul 29, 2016
cae6aff
Remove whitespace
fredrikaverpil Jul 29, 2016
6dad71f
Add Xvfb
fredrikaverpil Jul 31, 2016
a01dee1
Add xvfbwrapper
fredrikaverpil Jul 31, 2016
9636bf2
Add xvfbwrapper to .travis.yml
fredrikaverpil Jul 31, 2016
cf6b7d7
Add tests title consistency
fredrikaverpil Jul 31, 2016
0efaa10
Revert "Add xvfbwrapper to .travis.yml"
fredrikaverpil Jul 31, 2016
1075d02
Remove xvfbwrapper
fredrikaverpil Jul 31, 2016
211db11
Add tests for improvements in load_ui
fredrikaverpil Jul 28, 2016
e07eaab
Add distinguishable test descriptions
fredrikaverpil Jul 28, 2016
1ef25b4
Add support for additional load_ui arguments
fredrikaverpil Jul 28, 2016
57b7956
Specify a non-binary mode
fredrikaverpil Jul 28, 2016
a440883
Update with load_ui additional arguments info
fredrikaverpil Jul 28, 2016
231819d
Remove QMenuBar and QStatusBar from UI
fredrikaverpil Jul 28, 2016
b443923
Revert "Remove QMenuBar and QStatusBar from UI"
fredrikaverpil Jul 28, 2016
41dbb76
Simplify tests
mottosso Jul 29, 2016
9f25323
Remove whitespace
fredrikaverpil Jul 29, 2016
9c4f7d7
Add Xvfb
fredrikaverpil Jul 31, 2016
189c0ed
Add xvfbwrapper
fredrikaverpil Jul 31, 2016
9fb8646
Add xvfbwrapper to .travis.yml
fredrikaverpil Jul 31, 2016
bfd9cae
Add tests title consistency
fredrikaverpil Jul 31, 2016
adf4c2b
Revert "Add xvfbwrapper to .travis.yml"
fredrikaverpil Jul 31, 2016
0f4ee5a
Remove xvfbwrapper
fredrikaverpil Jul 31, 2016
f24fc29
Merged branch feature/load_ui into feature/load_ui
fredrikaverpil Aug 1, 2016
69bb70f
Change UI template into QWidget
fredrikaverpil Aug 1, 2016
fe4889c
Squelch xvfb messages
mottosso Aug 1, 2016
cd656b7
- Remove duplicate definition from prior merge
mottosso Aug 1, 2016
84bfc84
Merge pull request #3 from abstractfactory/feature/load_ui
fredrikaverpil Aug 1, 2016
b17413e
Add docstring fixes
fredrikaverpil Aug 1, 2016
1d363a6
Avoid defining UiLoader class twice
fredrikaverpil Aug 1, 2016
cb6d835
Avoid doctest of pyside_load_ui
fredrikaverpil Aug 1, 2016
ee30a6d
Fix docstrings for load_ui: PyQt4/PyQt5
fredrikaverpil Aug 1, 2016
c231100
Add consistency on load_ui wrap functions
fredrikaverpil Aug 1, 2016
b4ed328
- Alternative UiLoader implementation
mottosso Aug 1, 2016
7703fda
Merge pull request #4 from abstractfactory/feature/load_ui
fredrikaverpil Aug 1, 2016
2de9542
Revert change UI template into QWidget
fredrikaverpil Aug 2, 2016
58b7e4e
Add comments
fredrikaverpil Aug 2, 2016
02bc2ea
Merge tag '0.3.3'
fredrikaverpil Aug 4, 2016
049213a
Add tests for widget parent and class
fredrikaverpil Aug 4, 2016
8929b63
Add test for missing/invalid widget class
fredrikaverpil Aug 4, 2016
ecf2780
Merge remote-tracking branch 'refs/remotes/mottosso/master'
fredrikaverpil Aug 8, 2016
4cf7294
Remove class
fredrikaverpil Aug 8, 2016
7dd4d6c
Comment out test with invalid class
fredrikaverpil Aug 8, 2016
99b1e99
Add custom widgets support and tests
fredrikaverpil Aug 8, 2016
0ea392a
Add consistency
fredrikaverpil Aug 8, 2016
87c7dae
Add more tests for custom widgets
fredrikaverpil Aug 8, 2016
7bfb97e
Remove whitespace and fix linting issues
fredrikaverpil Aug 8, 2016
3daabe9
Retry appveyor PyQt4 download
fredrikaverpil Aug 8, 2016
55f464f
Remove custom widgets support
fredrikaverpil Aug 9, 2016
f9abc92
Remove extension of UiLoader
fredrikaverpil Aug 11, 2016
a545edd
Add tests for QWidget, QDialog
fredrikaverpil Aug 11, 2016
61bcb86
Add tests for signals
fredrikaverpil Aug 12, 2016
5e5825b
Remove untestable test
fredrikaverpil Aug 12, 2016
a44a466
Add better test descriptions
fredrikaverpil Aug 12, 2016
cfe625c
Add complete usage examples
fredrikaverpil Aug 12, 2016
7c18457
Skip attributes with double leading underscore
fredrikaverpil Aug 12, 2016
b3a3cf4
Amend README, add example with second argument
fredrikaverpil Aug 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ FROM ubuntu:14.04
RUN apt-get update && apt-get install -y \
python-qt4 \
python-pyside \
python-pip
python-pip \
xvfb

# Nose is the Python test-runner
RUN pip install nose nosepipe

# Enable additional output from Qt.py
ENV QT_VERBOSE true

# Xvfb
ENV DISPLAY :99

WORKDIR /workspace/Qt.py
ENTRYPOINT cp -r /Qt.py /workspace && \
python build_caveats_tests.py && \
Xvfb :99 -screen 0 1024x768x16 2>/dev/null & \
sleep 3 && \
nosetests \
--verbose \
--with-process-isolation \
Expand Down
107 changes: 64 additions & 43 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

def _pyqt5():
import PyQt5.Qt
from PyQt5 import uic

# Remap
PyQt5.QtCore.Signal = PyQt5.QtCore.pyqtSignal
Expand All @@ -37,7 +38,7 @@ def _pyqt5():
PyQt5.__binding__ = "PyQt5"
PyQt5.__binding_version__ = PyQt5.QtCore.PYQT_VERSION_STR
PyQt5.__qt_version__ = PyQt5.QtCore.QT_VERSION_STR
PyQt5.load_ui = pyqt5_load_ui
PyQt5.load_ui = _pyqt_load_ui_factory(uic)

return PyQt5

Expand All @@ -61,6 +62,7 @@ def _pyqt4():
raise ImportError

import PyQt4.Qt
from PyQt4 import uic

# Remap
PyQt4.QtWidgets = PyQt4.QtGui
Expand All @@ -75,14 +77,14 @@ def _pyqt4():
PyQt4.__binding__ = "PyQt4"
PyQt4.__binding_version__ = PyQt4.QtCore.PYQT_VERSION_STR
PyQt4.__qt_version__ = PyQt4.QtCore.QT_VERSION_STR
PyQt4.load_ui = pyqt4_load_ui
PyQt4.load_ui = _pyqt_load_ui_factory(uic)

return PyQt4


def _pyside2():
import PySide2
from PySide2 import QtGui, QtCore
from PySide2 import QtGui, QtCore, QtUiTools

# Remap
QtCore.QStringListModel = QtGui.QStringListModel
Expand All @@ -92,14 +94,14 @@ def _pyside2():
PySide2.__binding__ = "PySide2"
PySide2.__binding_version__ = PySide2.__version__
PySide2.__qt_version__ = PySide2.QtCore.qVersion()
PySide2.load_ui = pyside2_load_ui
PySide2.load_ui = _pyside_load_ui_factory(QtUiTools.QUiLoader)

return PySide2


def _pyside():
import PySide
from PySide import QtGui, QtCore
from PySide import QtGui, QtCore, QtUiTools
QtCore, QtGui # bypass linter warnings

# Remap
Expand All @@ -114,65 +116,84 @@ def _pyside():
PySide.__binding__ = "PySide"
PySide.__binding_version__ = PySide.__version__
PySide.__qt_version__ = PySide.QtCore.qVersion()
PySide.load_ui = pyside_load_ui
PySide.load_ui = _pyside_load_ui_factory(QtUiTools.QUiLoader)

return PySide


def pyside_load_ui(fname):
"""Read Qt Designer .ui `fname`

Args:
fname (str): Absolute path to .ui file
def _pyside_load_ui_factory(superclass):
"""load_ui factory function for PySide and PySide2

Usage:
>> from Qt import load_ui
>> class MyWindow(QtWidgets.QWidget):
.. fname = 'my_ui.ui'
.. self.ui = load_ui(fname)
..
>> window = MyWindow()
Produce a load_ui function using the provided superclass

"""

from PySide import QtUiTools
return QtUiTools.QUiLoader().load(fname)
def load_ui(fname, base_instance=None):
"""Read Qt Designer .ui `fname`

Args:
fname (str): Absolute path to .ui file
base_instance (widget, optional): Instance of the Qt base class.

def pyside2_load_ui(fname):
"""Read Qt Designer .ui `fname`
Usage:
import sys
from Qt import QtWidgets, load_ui
class MyWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
fname = 'my_ui.ui'
load_ui(fname, self)
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
app.exec_()

Args:
fname (str): Absolute path to .ui file
"""

"""
if base_instance:
ui = superclass().load(fname)
for member in dir(ui):
if not member.startswith('__'):
setattr(base_instance, member, getattr(ui, member))
return ui
else:
return superclass().load(fname)

from PySide2 import QtUiTools
return QtUiTools.QUiLoader().load(fname)
return load_ui


def pyqt4_load_ui(fname):
"""Read Qt Designer .ui `fname`
def _pyqt_load_ui_factory(uic):
"""load_ui factory function for PyQt4 and PyQt5

Args:
fname (str): Absolute path to .ui file
Produce a load_ui function using the provided module

"""

from PyQt4 import uic
return uic.loadUi(fname)
def load_ui(fname, base_instance=None):
"""Read Qt Designer .ui `fname`

Args:
fname (str): Absolute path to .ui file
base_instance (widget, optional): Instance of the Qt base class.

def pyqt5_load_ui(fname):
"""Read Qt Designer .ui `fname`
Usage:
import sys
from Qt import QtWidgets, load_ui
class MyWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
fname = 'my_ui.ui'
load_ui(fname, self)
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
app.exec_()

Args:
fname (str): Absolute path to .ui file
"""

"""
return uic.loadUi(fname, base_instance)

from PyQt5 import uic
return uic.loadUi(fname)
return load_ui


def _log(text, verbose):
Expand All @@ -190,18 +211,18 @@ def _init():
this has executed.

"""

preferred = os.getenv("QT_PREFERRED_BINDING")
verbose = os.getenv("QT_VERBOSE") is not None
bindings = (_pyside2, _pyqt5, _pyside, _pyqt4)

if preferred:

# Internal flag (used in installer)
if preferred == "None":
sys.modules[__name__].__wrapper_version__ = __version__
return

preferred = preferred.split(os.pathsep)
available = {
"PySide2": _pyside2,
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,22 @@ ui.show()
app.exec_()
```

Please note, for maximum compatibility, only pass the argument of the filename to the `load_ui` function.
This `load_ui` function accepts a second argument; the base instance into which the UI is loaded:

```python
import sys
from Qt import QtWidgets, load_ui

class MyWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
load_ui("my.ui", self)

app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
app.exec_()
```

##### sip API v2

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ install:
# the registry key.

- REG ADD HKCU\Software\Python\PythonCore\2.7\InstallPath /f /ve /t REG_SZ /d %PYTHON%
- ps: (new-object net.webclient).DownloadFile($env:PYQT, "C:\install-PyQt4.exe")
- ps: do{sleep 5;(New-Object Net.WebClient).DownloadFile($env:PYQT, "C:\install-PyQt4.exe")}while(!$?)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully no more b0rked tests because this wasn't downloaded 😎

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, hopelessly unreliable the sourceforge downloads.. :(

- ps: Start-Process -FilePath C:\install-PyQt4.exe -ArgumentList "/S" -Wait -Passthru

# Test install
Expand Down
Loading