Skip to content

Commit 6ede980

Browse files
committed
Better documentation
1 parent 27f09ca commit 6ede980

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

qtpy/__init__.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,53 @@
77
# (see LICENSE.txt for details)
88

99
"""
10-
**QtPy** is a shim over the various Python Qt bindings. It is used to write
11-
Qt binding independent libraries or applications.
10+
**QtPy** is a shim over the various Python Qt bindings. It is used to
11+
write Qt binding independent libraries or applications.
1212
1313
If one of the APIs has already been imported, then it will be used.
1414
1515
Otherwise, the shim will automatically select the first available API
16-
following the list; in that case, you can force the use of one
17-
specific bindings (e.g. if your application is using one specific bindings and
18-
you need to use library that use QtPy) by setting up the ``QT_API`` environment
19-
variable.
20-
21-
For each binding selected, there are more three attempts if it not found,
22-
following the most recent (Qt5) and most stable (PyQt) API. See bellow:
23-
24-
* PyQt5: PySide2, PyQt4, PySide
25-
* PySide2: PyQt5, PyQt4, PySide
26-
* PyQt4: PySide, PyQt5, PySide2
27-
* PySide: PyQt4, PyQt5, PySide2
28-
29-
The default value for QT_API is PyQt5 (not case sensitive).
30-
31-
The clearest way to set which API is to be used by QtPy is setting``QT_API``
32-
environment variable.
33-
If any of binding is imported directly anywhere, but before you import QtPy,
34-
this binding will be used, overwriting your definition.
35-
36-
Priority when setting the Qt binding API:
37-
38-
1 Have been already imported any Qt binding (not recommended):
39-
1.1 QT_API is not set, pass, no output;
40-
1.2 QT_API is set to the same binding, pass, no output;
41-
1.3 QT_API is set to differ binding, ignore QT_API, pass but warns;
42-
43-
2 Have NOT been already imported any Qt binding:
44-
2.1 QT_API is set correctly, pass;
45-
2.1.1 If binding is found, pass, no output;
46-
2.1.2 If binding is not found, try another one (more three):
47-
2.1.2.a If any is found (different from set), pass but warns;
48-
2.1.2.b If no one is found, stop, error;
49-
2.2 QT_API is not set correctly, stop, error;
16+
following the list below; in that case, you can force the use of one
17+
specific binding (e.g. if your application is using one specific binding
18+
and you need to use a library that uses QtPy) by setting up the
19+
``QT_API`` environment variable.
20+
21+
For each selected binding, there will be more three attempts if it is
22+
not found, following the most recent (Qt5) and most stable (PyQt) API.
23+
See below:
24+
25+
* pyqt5: PyQt5, PySide2, PyQt4, PySide
26+
* pyside2: PySide2, PyQt5, PyQt4, PySide
27+
* pyqt4: PyQt4, PySide, PyQt5, PySide2
28+
* pyside: PySide, PyQt4, PyQt5, PySide2
29+
30+
The clearest way to set which API is to be used by QtPy is setting
31+
``QT_API`` environment variable. The default value for ``QT_API = 'pyqt5'``
32+
(not case sensitive).
33+
34+
The priority when setting the Qt binding API is detailed below:
35+
36+
1 Have been already imported any Qt binding (not recommended, implicit):
37+
1.1 QT_API is not set, pass, no output;
38+
1.2 QT_API is set to the same binding, pass, no output;
39+
1.3 QT_API is set to a different binding, ignore QT_API, pass but warns;
40+
41+
2 Have NOT been already imported any Qt binding (explicitly setting):
42+
2.1 QT_API is set correctly, pass;
43+
2.1.1 If binding is found, pass, no output;
44+
2.1.2 If binding is not found, try another one (more three);
45+
2.1.2.a If any is found (different from set), pass but warns;
46+
2.1.2.b If no one is found, stop, error;
47+
2.2 QT_API is not set correctly, stop, error;
48+
49+
Note 1: if any Qt binding is imported (a different one) after QtPy
50+
import, issues and errors may occur and QtPy won't be able to help you
51+
with any warning.
52+
53+
Note 2: we always preffer to not break the code when something is not
54+
found, so we use ``warnings`` module to alert changes and show information
55+
that may be useful when developing using QtPy. Remember to set warnings
56+
to show messages.
5057
5158
PyQt5
5259
=====
@@ -56,7 +63,6 @@
5663
>>> from qtpy import QtGui, QtWidgets, QtCore
5764
>>> print(QtWidgets.QWidget)
5865
59-
6066
PySide2
6167
=======
6268

0 commit comments

Comments
 (0)