Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jun 4, 2016
2 parents c40912c + 48c9198 commit 5ae81fc
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 5 deletions.
19 changes: 18 additions & 1 deletion Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os
import sys

__version__ = "0.2.6"
__version__ = "0.3.0"


def _pyqt5():
Expand All @@ -43,6 +43,23 @@ def _pyqt5():


def _pyqt4():
# Attempt to set sip API v2 (must be done prior to importing PyQt4)
import sip
try:
sip.setapi("QString", 2)
sip.setapi("QVariant", 2)
sip.setapi("QDate", 2)
sip.setapi("QDateTime", 2)
sip.setapi("QTextStream", 2)
sip.setapi("QTime", 2)
sip.setapi("QUrl", 2)
except AttributeError:
raise ImportError
# PyQt4 < v4.6
except ValueError:
# API version already set to v1
raise ImportError

import PyQt4.Qt

# Remap
Expand Down
69 changes: 67 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ pip install Qt.py

### Usage

Use Qt.py as you would use PyQt5 or PySide2.
Use Qt.py as you would use PySide2.

![image](https://cloud.githubusercontent.com/assets/2152766/15653248/b5ce298e-2683-11e6-8c0c-f041ecae203d.png)

Expand Down Expand Up @@ -98,6 +98,14 @@ from Qt import QtCore
signal = QtCore.pyqtSignal()
```

But it enables use of Qt.py as a helper library, in conjunction with an existing binding, simplifying the transition of an existing project from a particular binding.

```python
# This is ok
from Qt import QtCore
from PyQt4 import QtGui
```

<br>
<br>
<br>
Expand Down Expand Up @@ -170,6 +178,16 @@ sys.exit(app.exec_())

Please note, for maximum compatibility, only pass the argument of the filename to the `load_ui` function.

**sip API v2**

If you're using PyQt4, `sip` attempts to set its API to version 2 for the following:
- `QString`
- `QVariant`
- `QDate`
- `QDateTime`
- `QTextStream`
- `QTime`
- `QUrl`

<br>
<br>
Expand Down Expand Up @@ -235,4 +253,51 @@ docker run --rm -v $(pwd):/Qt.py mottosso/qtpy
# OK
```

The dependencies, and OS, can and should be identical to those found in [`.travis.yml`](https://github.com/mottosso/Qt.py/blob/master/.travis.yml). That way, both you and Travis are operating on the same assumptions which means that when the tests pass on your machine, they pass on Travis. And everybody wins!
The dependencies, and OS, can and should be identical to those found in [`.travis.yml`](https://github.com/mottosso/Qt.py/blob/master/.travis.yml). That way, both you and Travis are operating on the same assumptions which means that when the tests pass on your machine, they pass on Travis. And everybody wins!

**Commits**

Commits should be well contained, as small as possible (but no smaller) and its messages should be in present-tense, imperative-style.

E.g.

```bash
# No
Changed this and did that

# No
Changes this and does that

# Yes
Change this and do that
```

The reason is that, each commit is like an action. An event. And it is perfectly possible to "cherry-pick" a commit onto any given branch. In this style, it makes more sense what exactly the commit will do to your code.

- Cherry pick "Add this and remove that"
- Cherry pick "Remove X and replace with Y"

**Version bumping**

This project uses [semantic versioning](http://semver.org/) and is updated *after* a new release has been made.

For example, if the project had 100 commits at the time of the latest release and has 103 commits now, then it's time to increment. If however you modify the project and it has not yet been released, then your changes are included in the overall next release.

The goal is to make a new release per increment.

**Making a Release**

Once the project has gained features, had bugs sorted out and is in a relatively stable state, it's time to make a new release.

- https://github.com/mottosso/Qt.py/releases

Each release should come with:

- An short summary of what has changed.
- A full changelog, including links to resolved issues.

The release is then automatically uploaded to PyPI.

```bash
$ pip install Qt.py
```
18 changes: 16 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
assert_raises,
)


@contextlib.contextmanager
def pyqt4():
os.environ["QT_PREFERRED_BINDING"] = "PyQt4"
Expand All @@ -33,6 +34,7 @@ def clean():
"""Provide clean working environment"""
sys.modules.pop("Qt", None)
os.environ.pop("QT_PREFERRED_BINDING", None)
sys.modules.pop("sip", None)


def test_environment():
Expand All @@ -57,7 +59,7 @@ def test_preferred():

# Try again
sys.modules.pop("Qt")

with pyside():
import Qt
assert Qt.__name__ == "PySide", ("PySide should have been picked, "
Expand All @@ -76,7 +78,7 @@ def test_preferred_none():
@with_setup(clean)
def test_coexistence():
"""Qt.py may be use alongside the actual binding"""

with pyside():
from Qt import QtCore
import PySide.QtGui
Expand All @@ -86,3 +88,15 @@ def test_coexistence():

# But does not delete the original
assert PySide.QtGui.QStringListModel


@with_setup(clean)
def test_sip_api_qtpy():
"""Qt.py with preferred binding PyQt4 should have sip version 2"""

with pyqt4():
import Qt
import sip
assert sip.getapi("QString") == 2, ("PyQt4 API version should be 2, "
"instead is %s"
% sip.getapi("QString"))

0 comments on commit 5ae81fc

Please sign in to comment.