pyqtcompat 0.1.0a0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyqtcompat-0.1.0a0/LICENSE +21 -0
- pyqtcompat-0.1.0a0/PKG-INFO +145 -0
- pyqtcompat-0.1.0a0/README.md +128 -0
- pyqtcompat-0.1.0a0/pyproject.toml +26 -0
- pyqtcompat-0.1.0a0/pyqtcompat.egg-info/PKG-INFO +145 -0
- pyqtcompat-0.1.0a0/pyqtcompat.egg-info/SOURCES.txt +10 -0
- pyqtcompat-0.1.0a0/pyqtcompat.egg-info/dependency_links.txt +1 -0
- pyqtcompat-0.1.0a0/pyqtcompat.egg-info/requires.txt +1 -0
- pyqtcompat-0.1.0a0/pyqtcompat.egg-info/top_level.txt +1 -0
- pyqtcompat-0.1.0a0/pyqtcompat.py +545 -0
- pyqtcompat-0.1.0a0/setup.cfg +7 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jifeng Wu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyqtcompat
|
|
3
|
+
Version: 0.1.0a0
|
|
4
|
+
Summary: A single-module Qt binding compatibility layer for PyQt6, PySide6, PyQt5, PySide2, PyQt4, and PySide.
|
|
5
|
+
Author-email: Jifeng Wu <jifengwu2k@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jifengwu2k/pyqtcompat
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/jifengwu2k/pyqtcompat/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 2
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=2
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: detect-qt-binding
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
A single-module Qt binding compatibility layer for PyQt6, PySide6, PyQt5, PySide2, PyQt4, and PySide.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Install the package with:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install pyqtcompat
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
You must also have at least one supported Qt binding installed in your Python environment:
|
|
29
|
+
|
|
30
|
+
- PyQt6
|
|
31
|
+
- PySide6
|
|
32
|
+
- PyQt5
|
|
33
|
+
- PySide2
|
|
34
|
+
- PyQt4
|
|
35
|
+
- PySide
|
|
36
|
+
|
|
37
|
+
The module uses [`detect-qt-binding`](https://pypi.org/project/detect-qt-binding/) to choose the active binding.
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Import the normalized Qt names from `pyqtcompat` instead of importing directly from a specific binding:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from pyqtcompat import QApplication, QLabel, QT_ALIGN_CENTER, execute
|
|
45
|
+
|
|
46
|
+
application = QApplication([])
|
|
47
|
+
label = QLabel('Hello from pyqtcompat')
|
|
48
|
+
label.setAlignment(QT_ALIGN_CENTER)
|
|
49
|
+
label.show()
|
|
50
|
+
raise SystemExit(execute(application))
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You can also inspect which binding was selected:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from pyqtcompat import QT_BINDING
|
|
57
|
+
|
|
58
|
+
print(QT_BINDING)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Public API
|
|
62
|
+
|
|
63
|
+
`pyqtcompat` defines `__all__` at the top of the module. These names are the intended application-facing imports.
|
|
64
|
+
|
|
65
|
+
Binding and module-level names:
|
|
66
|
+
|
|
67
|
+
- `QtBindings`
|
|
68
|
+
- `QT_BINDING`
|
|
69
|
+
- `IS_PYQT`, `IS_PYSIDE`, `IS_QT6`
|
|
70
|
+
- `QtSignal`
|
|
71
|
+
|
|
72
|
+
Common Qt classes exported directly:
|
|
73
|
+
|
|
74
|
+
- `QTimer`
|
|
75
|
+
- `QImage`, `QPixmap`, `QColor`, `QPainter`, `QPen`, `QScreen`
|
|
76
|
+
- `QAbstractSlider`
|
|
77
|
+
- `QApplication`
|
|
78
|
+
- `QCheckBox`, `QComboBox`, `QDesktopServices`, `QDesktopWidget`, `QFileDialog`
|
|
79
|
+
- `QFrame`, `QGroupBox`, `QHBoxLayout`, `QLabel`, `QLineEdit`
|
|
80
|
+
- `QMainWindow`, `QMessageBox`, `QPushButton`, `QScrollArea`
|
|
81
|
+
- `QSizePolicy`, `QSlider`, `QVBoxLayout`, `QWidget`
|
|
82
|
+
|
|
83
|
+
Compatibility constants exported directly:
|
|
84
|
+
|
|
85
|
+
- `Format_RGB32`, `Format_ARGB32`, `Format_RGB888`
|
|
86
|
+
- `QT_KEEP_ASPECT_RATIO`, `QT_SMOOTH_TRANSFORMATION`, `QT_ALIGN_CENTER`, `QT_HORIZONTAL`
|
|
87
|
+
- `QT_SCROLLBAR_ALWAYS_OFF`, `QT_SCROLLBAR_AS_NEEDED`
|
|
88
|
+
- `QSIZEPOLICY_EXPANDING`
|
|
89
|
+
- `SLIDER_SINGLE_STEP_ADD`, `SLIDER_SINGLE_STEP_SUB`, `SLIDER_PAGE_STEP_ADD`, `SLIDER_PAGE_STEP_SUB`, `SLIDER_MOVE`
|
|
90
|
+
|
|
91
|
+
Helper functions exported directly:
|
|
92
|
+
|
|
93
|
+
- `exec_qapplication(app)`
|
|
94
|
+
- Purpose: Run the Qt application event loop with the correct cross-binding call style.
|
|
95
|
+
- Returns: the integer exit code returned by the event loop.
|
|
96
|
+
- `execute(q_application)`
|
|
97
|
+
- Purpose: Alias for `exec_qapplication()` for codebases already using that name.
|
|
98
|
+
- Returns: the integer exit code returned by the event loop.
|
|
99
|
+
- `get_or_create_q_application(argv=None)`
|
|
100
|
+
- Purpose: Return the existing `QApplication` instance, or create one if none exists yet.
|
|
101
|
+
- Returns: a `QApplication` instance.
|
|
102
|
+
- `get_buffer(qimage)`
|
|
103
|
+
- Purpose: Return a Python buffer-compatible view of the pixel memory of a `QImage`, handling PyQt/PySide differences.
|
|
104
|
+
- Returns: a binding-specific buffer object suitable for zero-copy access.
|
|
105
|
+
- `qimage_get_buffer(qimage)`
|
|
106
|
+
- Purpose: Same as `get_buffer()`; provided as the explicit `QImage`-named form.
|
|
107
|
+
- Returns: a binding-specific buffer object suitable for zero-copy access.
|
|
108
|
+
- `get_primary_screen_geometry()`
|
|
109
|
+
- Purpose: Read the geometry of the primary screen using the correct API for old and new Qt bindings.
|
|
110
|
+
- Returns: a Qt rectangle object describing the primary screen bounds.
|
|
111
|
+
- `get_primary_screen_size()`
|
|
112
|
+
- Purpose: Get the primary screen width and height as plain Python values.
|
|
113
|
+
- Returns: a `(width, height)` tuple of integers.
|
|
114
|
+
- `grab_primary_screen_pixmap()`
|
|
115
|
+
- Purpose: Capture the full primary screen into a pixmap using the correct API for the active binding.
|
|
116
|
+
- Returns: a `QPixmap` containing the screen capture.
|
|
117
|
+
|
|
118
|
+
Example using `QImage` buffer access:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from pyqtcompat import QImage, Format_RGB32, get_buffer
|
|
122
|
+
|
|
123
|
+
image = QImage(64, 64, Format_RGB32)
|
|
124
|
+
buffer_object = get_buffer(image)
|
|
125
|
+
print(type(buffer_object))
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Example using screen-grab helpers:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from pyqtcompat import get_or_create_q_application, get_primary_screen_size, grab_primary_screen_pixmap
|
|
132
|
+
|
|
133
|
+
application = get_or_create_q_application()
|
|
134
|
+
width, height = get_primary_screen_size()
|
|
135
|
+
pixmap = grab_primary_screen_pixmap()
|
|
136
|
+
print(width, height, pixmap.width(), pixmap.height())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
A single-module Qt binding compatibility layer for PyQt6, PySide6, PyQt5, PySide2, PyQt4, and PySide.
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Install the package with:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install pyqtcompat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
You must also have at least one supported Qt binding installed in your Python environment:
|
|
12
|
+
|
|
13
|
+
- PyQt6
|
|
14
|
+
- PySide6
|
|
15
|
+
- PyQt5
|
|
16
|
+
- PySide2
|
|
17
|
+
- PyQt4
|
|
18
|
+
- PySide
|
|
19
|
+
|
|
20
|
+
The module uses [`detect-qt-binding`](https://pypi.org/project/detect-qt-binding/) to choose the active binding.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Import the normalized Qt names from `pyqtcompat` instead of importing directly from a specific binding:
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from pyqtcompat import QApplication, QLabel, QT_ALIGN_CENTER, execute
|
|
28
|
+
|
|
29
|
+
application = QApplication([])
|
|
30
|
+
label = QLabel('Hello from pyqtcompat')
|
|
31
|
+
label.setAlignment(QT_ALIGN_CENTER)
|
|
32
|
+
label.show()
|
|
33
|
+
raise SystemExit(execute(application))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can also inspect which binding was selected:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from pyqtcompat import QT_BINDING
|
|
40
|
+
|
|
41
|
+
print(QT_BINDING)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Public API
|
|
45
|
+
|
|
46
|
+
`pyqtcompat` defines `__all__` at the top of the module. These names are the intended application-facing imports.
|
|
47
|
+
|
|
48
|
+
Binding and module-level names:
|
|
49
|
+
|
|
50
|
+
- `QtBindings`
|
|
51
|
+
- `QT_BINDING`
|
|
52
|
+
- `IS_PYQT`, `IS_PYSIDE`, `IS_QT6`
|
|
53
|
+
- `QtSignal`
|
|
54
|
+
|
|
55
|
+
Common Qt classes exported directly:
|
|
56
|
+
|
|
57
|
+
- `QTimer`
|
|
58
|
+
- `QImage`, `QPixmap`, `QColor`, `QPainter`, `QPen`, `QScreen`
|
|
59
|
+
- `QAbstractSlider`
|
|
60
|
+
- `QApplication`
|
|
61
|
+
- `QCheckBox`, `QComboBox`, `QDesktopServices`, `QDesktopWidget`, `QFileDialog`
|
|
62
|
+
- `QFrame`, `QGroupBox`, `QHBoxLayout`, `QLabel`, `QLineEdit`
|
|
63
|
+
- `QMainWindow`, `QMessageBox`, `QPushButton`, `QScrollArea`
|
|
64
|
+
- `QSizePolicy`, `QSlider`, `QVBoxLayout`, `QWidget`
|
|
65
|
+
|
|
66
|
+
Compatibility constants exported directly:
|
|
67
|
+
|
|
68
|
+
- `Format_RGB32`, `Format_ARGB32`, `Format_RGB888`
|
|
69
|
+
- `QT_KEEP_ASPECT_RATIO`, `QT_SMOOTH_TRANSFORMATION`, `QT_ALIGN_CENTER`, `QT_HORIZONTAL`
|
|
70
|
+
- `QT_SCROLLBAR_ALWAYS_OFF`, `QT_SCROLLBAR_AS_NEEDED`
|
|
71
|
+
- `QSIZEPOLICY_EXPANDING`
|
|
72
|
+
- `SLIDER_SINGLE_STEP_ADD`, `SLIDER_SINGLE_STEP_SUB`, `SLIDER_PAGE_STEP_ADD`, `SLIDER_PAGE_STEP_SUB`, `SLIDER_MOVE`
|
|
73
|
+
|
|
74
|
+
Helper functions exported directly:
|
|
75
|
+
|
|
76
|
+
- `exec_qapplication(app)`
|
|
77
|
+
- Purpose: Run the Qt application event loop with the correct cross-binding call style.
|
|
78
|
+
- Returns: the integer exit code returned by the event loop.
|
|
79
|
+
- `execute(q_application)`
|
|
80
|
+
- Purpose: Alias for `exec_qapplication()` for codebases already using that name.
|
|
81
|
+
- Returns: the integer exit code returned by the event loop.
|
|
82
|
+
- `get_or_create_q_application(argv=None)`
|
|
83
|
+
- Purpose: Return the existing `QApplication` instance, or create one if none exists yet.
|
|
84
|
+
- Returns: a `QApplication` instance.
|
|
85
|
+
- `get_buffer(qimage)`
|
|
86
|
+
- Purpose: Return a Python buffer-compatible view of the pixel memory of a `QImage`, handling PyQt/PySide differences.
|
|
87
|
+
- Returns: a binding-specific buffer object suitable for zero-copy access.
|
|
88
|
+
- `qimage_get_buffer(qimage)`
|
|
89
|
+
- Purpose: Same as `get_buffer()`; provided as the explicit `QImage`-named form.
|
|
90
|
+
- Returns: a binding-specific buffer object suitable for zero-copy access.
|
|
91
|
+
- `get_primary_screen_geometry()`
|
|
92
|
+
- Purpose: Read the geometry of the primary screen using the correct API for old and new Qt bindings.
|
|
93
|
+
- Returns: a Qt rectangle object describing the primary screen bounds.
|
|
94
|
+
- `get_primary_screen_size()`
|
|
95
|
+
- Purpose: Get the primary screen width and height as plain Python values.
|
|
96
|
+
- Returns: a `(width, height)` tuple of integers.
|
|
97
|
+
- `grab_primary_screen_pixmap()`
|
|
98
|
+
- Purpose: Capture the full primary screen into a pixmap using the correct API for the active binding.
|
|
99
|
+
- Returns: a `QPixmap` containing the screen capture.
|
|
100
|
+
|
|
101
|
+
Example using `QImage` buffer access:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from pyqtcompat import QImage, Format_RGB32, get_buffer
|
|
105
|
+
|
|
106
|
+
image = QImage(64, 64, Format_RGB32)
|
|
107
|
+
buffer_object = get_buffer(image)
|
|
108
|
+
print(type(buffer_object))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Example using screen-grab helpers:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from pyqtcompat import get_or_create_q_application, get_primary_screen_size, grab_primary_screen_pixmap
|
|
115
|
+
|
|
116
|
+
application = get_or_create_q_application()
|
|
117
|
+
width, height = get_primary_screen_size()
|
|
118
|
+
pixmap = grab_primary_screen_pixmap()
|
|
119
|
+
print(width, height, pixmap.width(), pixmap.height())
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Contributing
|
|
123
|
+
|
|
124
|
+
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyqtcompat"
|
|
7
|
+
version = "0.1.0a0"
|
|
8
|
+
description = "A single-module Qt binding compatibility layer for PyQt6, PySide6, PyQt5, PySide2, PyQt4, and PySide."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=2"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Jifeng Wu", email = "jifengwu2k@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 2",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"detect-qt-binding"
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
"Homepage" = "https://github.com/jifengwu2k/pyqtcompat"
|
|
26
|
+
"Bug Tracker" = "https://github.com/jifengwu2k/pyqtcompat/issues"
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyqtcompat
|
|
3
|
+
Version: 0.1.0a0
|
|
4
|
+
Summary: A single-module Qt binding compatibility layer for PyQt6, PySide6, PyQt5, PySide2, PyQt4, and PySide.
|
|
5
|
+
Author-email: Jifeng Wu <jifengwu2k@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jifengwu2k/pyqtcompat
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/jifengwu2k/pyqtcompat/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 2
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=2
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: detect-qt-binding
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
A single-module Qt binding compatibility layer for PyQt6, PySide6, PyQt5, PySide2, PyQt4, and PySide.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Install the package with:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install pyqtcompat
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
You must also have at least one supported Qt binding installed in your Python environment:
|
|
29
|
+
|
|
30
|
+
- PyQt6
|
|
31
|
+
- PySide6
|
|
32
|
+
- PyQt5
|
|
33
|
+
- PySide2
|
|
34
|
+
- PyQt4
|
|
35
|
+
- PySide
|
|
36
|
+
|
|
37
|
+
The module uses [`detect-qt-binding`](https://pypi.org/project/detect-qt-binding/) to choose the active binding.
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Import the normalized Qt names from `pyqtcompat` instead of importing directly from a specific binding:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from pyqtcompat import QApplication, QLabel, QT_ALIGN_CENTER, execute
|
|
45
|
+
|
|
46
|
+
application = QApplication([])
|
|
47
|
+
label = QLabel('Hello from pyqtcompat')
|
|
48
|
+
label.setAlignment(QT_ALIGN_CENTER)
|
|
49
|
+
label.show()
|
|
50
|
+
raise SystemExit(execute(application))
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You can also inspect which binding was selected:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from pyqtcompat import QT_BINDING
|
|
57
|
+
|
|
58
|
+
print(QT_BINDING)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Public API
|
|
62
|
+
|
|
63
|
+
`pyqtcompat` defines `__all__` at the top of the module. These names are the intended application-facing imports.
|
|
64
|
+
|
|
65
|
+
Binding and module-level names:
|
|
66
|
+
|
|
67
|
+
- `QtBindings`
|
|
68
|
+
- `QT_BINDING`
|
|
69
|
+
- `IS_PYQT`, `IS_PYSIDE`, `IS_QT6`
|
|
70
|
+
- `QtSignal`
|
|
71
|
+
|
|
72
|
+
Common Qt classes exported directly:
|
|
73
|
+
|
|
74
|
+
- `QTimer`
|
|
75
|
+
- `QImage`, `QPixmap`, `QColor`, `QPainter`, `QPen`, `QScreen`
|
|
76
|
+
- `QAbstractSlider`
|
|
77
|
+
- `QApplication`
|
|
78
|
+
- `QCheckBox`, `QComboBox`, `QDesktopServices`, `QDesktopWidget`, `QFileDialog`
|
|
79
|
+
- `QFrame`, `QGroupBox`, `QHBoxLayout`, `QLabel`, `QLineEdit`
|
|
80
|
+
- `QMainWindow`, `QMessageBox`, `QPushButton`, `QScrollArea`
|
|
81
|
+
- `QSizePolicy`, `QSlider`, `QVBoxLayout`, `QWidget`
|
|
82
|
+
|
|
83
|
+
Compatibility constants exported directly:
|
|
84
|
+
|
|
85
|
+
- `Format_RGB32`, `Format_ARGB32`, `Format_RGB888`
|
|
86
|
+
- `QT_KEEP_ASPECT_RATIO`, `QT_SMOOTH_TRANSFORMATION`, `QT_ALIGN_CENTER`, `QT_HORIZONTAL`
|
|
87
|
+
- `QT_SCROLLBAR_ALWAYS_OFF`, `QT_SCROLLBAR_AS_NEEDED`
|
|
88
|
+
- `QSIZEPOLICY_EXPANDING`
|
|
89
|
+
- `SLIDER_SINGLE_STEP_ADD`, `SLIDER_SINGLE_STEP_SUB`, `SLIDER_PAGE_STEP_ADD`, `SLIDER_PAGE_STEP_SUB`, `SLIDER_MOVE`
|
|
90
|
+
|
|
91
|
+
Helper functions exported directly:
|
|
92
|
+
|
|
93
|
+
- `exec_qapplication(app)`
|
|
94
|
+
- Purpose: Run the Qt application event loop with the correct cross-binding call style.
|
|
95
|
+
- Returns: the integer exit code returned by the event loop.
|
|
96
|
+
- `execute(q_application)`
|
|
97
|
+
- Purpose: Alias for `exec_qapplication()` for codebases already using that name.
|
|
98
|
+
- Returns: the integer exit code returned by the event loop.
|
|
99
|
+
- `get_or_create_q_application(argv=None)`
|
|
100
|
+
- Purpose: Return the existing `QApplication` instance, or create one if none exists yet.
|
|
101
|
+
- Returns: a `QApplication` instance.
|
|
102
|
+
- `get_buffer(qimage)`
|
|
103
|
+
- Purpose: Return a Python buffer-compatible view of the pixel memory of a `QImage`, handling PyQt/PySide differences.
|
|
104
|
+
- Returns: a binding-specific buffer object suitable for zero-copy access.
|
|
105
|
+
- `qimage_get_buffer(qimage)`
|
|
106
|
+
- Purpose: Same as `get_buffer()`; provided as the explicit `QImage`-named form.
|
|
107
|
+
- Returns: a binding-specific buffer object suitable for zero-copy access.
|
|
108
|
+
- `get_primary_screen_geometry()`
|
|
109
|
+
- Purpose: Read the geometry of the primary screen using the correct API for old and new Qt bindings.
|
|
110
|
+
- Returns: a Qt rectangle object describing the primary screen bounds.
|
|
111
|
+
- `get_primary_screen_size()`
|
|
112
|
+
- Purpose: Get the primary screen width and height as plain Python values.
|
|
113
|
+
- Returns: a `(width, height)` tuple of integers.
|
|
114
|
+
- `grab_primary_screen_pixmap()`
|
|
115
|
+
- Purpose: Capture the full primary screen into a pixmap using the correct API for the active binding.
|
|
116
|
+
- Returns: a `QPixmap` containing the screen capture.
|
|
117
|
+
|
|
118
|
+
Example using `QImage` buffer access:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from pyqtcompat import QImage, Format_RGB32, get_buffer
|
|
122
|
+
|
|
123
|
+
image = QImage(64, 64, Format_RGB32)
|
|
124
|
+
buffer_object = get_buffer(image)
|
|
125
|
+
print(type(buffer_object))
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Example using screen-grab helpers:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from pyqtcompat import get_or_create_q_application, get_primary_screen_size, grab_primary_screen_pixmap
|
|
132
|
+
|
|
133
|
+
application = get_or_create_q_application()
|
|
134
|
+
width, height = get_primary_screen_size()
|
|
135
|
+
pixmap = grab_primary_screen_pixmap()
|
|
136
|
+
print(width, height, pixmap.width(), pixmap.height())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
detect-qt-binding
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyqtcompat
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
# Copyright (c) 2026 Jifeng Wu
|
|
2
|
+
# Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from detect_qt_binding import QtBindings, detect_qt_binding
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"QtBindings",
|
|
9
|
+
"QT_BINDING",
|
|
10
|
+
"IS_PYQT",
|
|
11
|
+
"IS_PYSIDE",
|
|
12
|
+
"IS_QT6",
|
|
13
|
+
"QtSignal",
|
|
14
|
+
"QTimer",
|
|
15
|
+
"QImage",
|
|
16
|
+
"QPixmap",
|
|
17
|
+
"QColor",
|
|
18
|
+
"QPainter",
|
|
19
|
+
"QPen",
|
|
20
|
+
"QScreen",
|
|
21
|
+
"QAbstractSlider",
|
|
22
|
+
"QApplication",
|
|
23
|
+
"QCheckBox",
|
|
24
|
+
"QComboBox",
|
|
25
|
+
"QDesktopServices",
|
|
26
|
+
"QDesktopWidget",
|
|
27
|
+
"QFileDialog",
|
|
28
|
+
"QFrame",
|
|
29
|
+
"QGroupBox",
|
|
30
|
+
"QHBoxLayout",
|
|
31
|
+
"QLabel",
|
|
32
|
+
"QLineEdit",
|
|
33
|
+
"QMainWindow",
|
|
34
|
+
"QMessageBox",
|
|
35
|
+
"QPushButton",
|
|
36
|
+
"QScrollArea",
|
|
37
|
+
"QSizePolicy",
|
|
38
|
+
"QSlider",
|
|
39
|
+
"QVBoxLayout",
|
|
40
|
+
"QWidget",
|
|
41
|
+
"Format_RGB32",
|
|
42
|
+
"Format_ARGB32",
|
|
43
|
+
"Format_RGB888",
|
|
44
|
+
"QT_KEEP_ASPECT_RATIO",
|
|
45
|
+
"QT_SMOOTH_TRANSFORMATION",
|
|
46
|
+
"QT_ALIGN_CENTER",
|
|
47
|
+
"QT_HORIZONTAL",
|
|
48
|
+
"QT_SCROLLBAR_ALWAYS_OFF",
|
|
49
|
+
"QT_SCROLLBAR_AS_NEEDED",
|
|
50
|
+
"QSIZEPOLICY_EXPANDING",
|
|
51
|
+
"SLIDER_SINGLE_STEP_ADD",
|
|
52
|
+
"SLIDER_SINGLE_STEP_SUB",
|
|
53
|
+
"SLIDER_PAGE_STEP_ADD",
|
|
54
|
+
"SLIDER_PAGE_STEP_SUB",
|
|
55
|
+
"SLIDER_MOVE",
|
|
56
|
+
"exec_qapplication",
|
|
57
|
+
"execute",
|
|
58
|
+
"get_or_create_q_application",
|
|
59
|
+
"get_buffer",
|
|
60
|
+
"qimage_get_buffer",
|
|
61
|
+
"get_primary_screen_geometry",
|
|
62
|
+
"get_primary_screen_size",
|
|
63
|
+
"grab_primary_screen_pixmap",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
SUPPORTED_QT_BINDINGS_MESSAGE = (
|
|
67
|
+
"We require one of PyQt6, PySide6, PyQt5, PySide2, PyQt4, or PySide. "
|
|
68
|
+
"None of these packages were detected in your Python environment."
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
QT_BINDING = detect_qt_binding()
|
|
72
|
+
if QT_BINDING is None:
|
|
73
|
+
raise ImportError(SUPPORTED_QT_BINDINGS_MESSAGE)
|
|
74
|
+
|
|
75
|
+
qt_binding = QT_BINDING
|
|
76
|
+
detected_qt_binding = QT_BINDING
|
|
77
|
+
|
|
78
|
+
IS_PYQT = False
|
|
79
|
+
IS_PYSIDE = False
|
|
80
|
+
IS_QT6 = False
|
|
81
|
+
|
|
82
|
+
QtCore = None
|
|
83
|
+
QtGui = None
|
|
84
|
+
QtWidgets = None
|
|
85
|
+
|
|
86
|
+
Qt = None
|
|
87
|
+
Signal = None
|
|
88
|
+
pyqtSignal = None
|
|
89
|
+
QtSignal = None
|
|
90
|
+
QTimer = None
|
|
91
|
+
|
|
92
|
+
QImage = None
|
|
93
|
+
QPixmap = None
|
|
94
|
+
QColor = None
|
|
95
|
+
QPainter = None
|
|
96
|
+
QPen = None
|
|
97
|
+
QScreen = None
|
|
98
|
+
|
|
99
|
+
QAbstractSlider = None
|
|
100
|
+
QApplication = None
|
|
101
|
+
QCheckBox = None
|
|
102
|
+
QComboBox = None
|
|
103
|
+
QDesktopServices = None
|
|
104
|
+
QDesktopWidget = None
|
|
105
|
+
QFileDialog = None
|
|
106
|
+
QFrame = None
|
|
107
|
+
QGroupBox = None
|
|
108
|
+
QHBoxLayout = None
|
|
109
|
+
QLabel = None
|
|
110
|
+
QLineEdit = None
|
|
111
|
+
QMainWindow = None
|
|
112
|
+
QMessageBox = None
|
|
113
|
+
QPushButton = None
|
|
114
|
+
QScrollArea = None
|
|
115
|
+
QSizePolicy = None
|
|
116
|
+
QSlider = None
|
|
117
|
+
QVBoxLayout = None
|
|
118
|
+
QWidget = None
|
|
119
|
+
|
|
120
|
+
QIMAGE_FORMAT_RGB32 = None
|
|
121
|
+
QIMAGE_FORMAT_ARGB32 = None
|
|
122
|
+
QIMAGE_FORMAT_RGB888 = None
|
|
123
|
+
Format_RGB32 = None
|
|
124
|
+
Format_ARGB32 = None
|
|
125
|
+
Format_RGB888 = None
|
|
126
|
+
|
|
127
|
+
QT_KEEP_ASPECT_RATIO = None
|
|
128
|
+
QT_SMOOTH_TRANSFORMATION = None
|
|
129
|
+
QT_ALIGN_CENTER = None
|
|
130
|
+
QT_HORIZONTAL = None
|
|
131
|
+
QT_SCROLLBAR_ALWAYS_OFF = None
|
|
132
|
+
QT_SCROLLBAR_AS_NEEDED = None
|
|
133
|
+
QSIZEPOLICY_EXPANDING = None
|
|
134
|
+
|
|
135
|
+
SLIDER_SINGLE_STEP_ADD = None
|
|
136
|
+
SLIDER_SINGLE_STEP_SUB = None
|
|
137
|
+
SLIDER_PAGE_STEP_ADD = None
|
|
138
|
+
SLIDER_PAGE_STEP_SUB = None
|
|
139
|
+
SLIDER_MOVE = None
|
|
140
|
+
|
|
141
|
+
if QT_BINDING == QtBindings.PyQt6:
|
|
142
|
+
import PyQt6.QtCore as QtCore
|
|
143
|
+
import PyQt6.QtGui as QtGui
|
|
144
|
+
import PyQt6.QtWidgets as QtWidgets
|
|
145
|
+
from PyQt6.QtCore import Qt, QTimer, pyqtSignal
|
|
146
|
+
from PyQt6.QtGui import QImage, QPixmap, QColor, QPainter, QPen, QScreen
|
|
147
|
+
from PyQt6.QtWidgets import (
|
|
148
|
+
QAbstractSlider,
|
|
149
|
+
QApplication,
|
|
150
|
+
QCheckBox,
|
|
151
|
+
QComboBox,
|
|
152
|
+
QFileDialog,
|
|
153
|
+
QFrame,
|
|
154
|
+
QGroupBox,
|
|
155
|
+
QHBoxLayout,
|
|
156
|
+
QLabel,
|
|
157
|
+
QLineEdit,
|
|
158
|
+
QMainWindow,
|
|
159
|
+
QMessageBox,
|
|
160
|
+
QPushButton,
|
|
161
|
+
QScrollArea,
|
|
162
|
+
QSizePolicy,
|
|
163
|
+
QSlider,
|
|
164
|
+
QVBoxLayout,
|
|
165
|
+
QWidget,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
Signal = pyqtSignal
|
|
169
|
+
QtSignal = pyqtSignal
|
|
170
|
+
IS_PYQT = True
|
|
171
|
+
IS_QT6 = True
|
|
172
|
+
|
|
173
|
+
QIMAGE_FORMAT_RGB32 = QImage.Format.Format_RGB32
|
|
174
|
+
QIMAGE_FORMAT_ARGB32 = QImage.Format.Format_ARGB32
|
|
175
|
+
QIMAGE_FORMAT_RGB888 = QImage.Format.Format_RGB888
|
|
176
|
+
Format_RGB32 = QIMAGE_FORMAT_RGB32
|
|
177
|
+
Format_ARGB32 = QIMAGE_FORMAT_ARGB32
|
|
178
|
+
Format_RGB888 = QIMAGE_FORMAT_RGB888
|
|
179
|
+
|
|
180
|
+
QT_KEEP_ASPECT_RATIO = Qt.AspectRatioMode.KeepAspectRatio
|
|
181
|
+
QT_SMOOTH_TRANSFORMATION = Qt.TransformationMode.SmoothTransformation
|
|
182
|
+
QT_ALIGN_CENTER = Qt.AlignmentFlag.AlignCenter
|
|
183
|
+
QT_HORIZONTAL = Qt.Orientation.Horizontal
|
|
184
|
+
QT_SCROLLBAR_ALWAYS_OFF = Qt.ScrollBarPolicy.ScrollBarAlwaysOff
|
|
185
|
+
QT_SCROLLBAR_AS_NEEDED = Qt.ScrollBarPolicy.ScrollBarAsNeeded
|
|
186
|
+
QSIZEPOLICY_EXPANDING = QSizePolicy.Policy.Expanding
|
|
187
|
+
|
|
188
|
+
SLIDER_SINGLE_STEP_ADD = QAbstractSlider.SliderAction.SliderSingleStepAdd.value
|
|
189
|
+
SLIDER_SINGLE_STEP_SUB = QAbstractSlider.SliderAction.SliderSingleStepSub.value
|
|
190
|
+
SLIDER_PAGE_STEP_ADD = QAbstractSlider.SliderAction.SliderPageStepAdd.value
|
|
191
|
+
SLIDER_PAGE_STEP_SUB = QAbstractSlider.SliderAction.SliderPageStepSub.value
|
|
192
|
+
SLIDER_MOVE = QAbstractSlider.SliderAction.SliderMove.value
|
|
193
|
+
elif QT_BINDING == QtBindings.PySide6:
|
|
194
|
+
import PySide6.QtCore as QtCore
|
|
195
|
+
import PySide6.QtGui as QtGui
|
|
196
|
+
import PySide6.QtWidgets as QtWidgets
|
|
197
|
+
from PySide6.QtCore import Qt, QTimer, Signal
|
|
198
|
+
from PySide6.QtGui import QImage, QPixmap, QColor, QPainter, QPen, QScreen
|
|
199
|
+
from PySide6.QtWidgets import (
|
|
200
|
+
QAbstractSlider,
|
|
201
|
+
QApplication,
|
|
202
|
+
QCheckBox,
|
|
203
|
+
QComboBox,
|
|
204
|
+
QFileDialog,
|
|
205
|
+
QFrame,
|
|
206
|
+
QGroupBox,
|
|
207
|
+
QHBoxLayout,
|
|
208
|
+
QLabel,
|
|
209
|
+
QLineEdit,
|
|
210
|
+
QMainWindow,
|
|
211
|
+
QMessageBox,
|
|
212
|
+
QPushButton,
|
|
213
|
+
QScrollArea,
|
|
214
|
+
QSizePolicy,
|
|
215
|
+
QSlider,
|
|
216
|
+
QVBoxLayout,
|
|
217
|
+
QWidget,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
pyqtSignal = Signal
|
|
221
|
+
QtSignal = Signal
|
|
222
|
+
IS_PYSIDE = True
|
|
223
|
+
IS_QT6 = True
|
|
224
|
+
|
|
225
|
+
QIMAGE_FORMAT_RGB32 = QImage.Format.Format_RGB32
|
|
226
|
+
QIMAGE_FORMAT_ARGB32 = QImage.Format.Format_ARGB32
|
|
227
|
+
QIMAGE_FORMAT_RGB888 = QImage.Format.Format_RGB888
|
|
228
|
+
Format_RGB32 = QIMAGE_FORMAT_RGB32
|
|
229
|
+
Format_ARGB32 = QIMAGE_FORMAT_ARGB32
|
|
230
|
+
Format_RGB888 = QIMAGE_FORMAT_RGB888
|
|
231
|
+
|
|
232
|
+
QT_KEEP_ASPECT_RATIO = Qt.AspectRatioMode.KeepAspectRatio
|
|
233
|
+
QT_SMOOTH_TRANSFORMATION = Qt.TransformationMode.SmoothTransformation
|
|
234
|
+
QT_ALIGN_CENTER = Qt.AlignmentFlag.AlignCenter
|
|
235
|
+
QT_HORIZONTAL = Qt.Orientation.Horizontal
|
|
236
|
+
QT_SCROLLBAR_ALWAYS_OFF = Qt.ScrollBarPolicy.ScrollBarAlwaysOff
|
|
237
|
+
QT_SCROLLBAR_AS_NEEDED = Qt.ScrollBarPolicy.ScrollBarAsNeeded
|
|
238
|
+
QSIZEPOLICY_EXPANDING = QSizePolicy.Policy.Expanding
|
|
239
|
+
|
|
240
|
+
SLIDER_SINGLE_STEP_ADD = QAbstractSlider.SliderAction.SliderSingleStepAdd.value
|
|
241
|
+
SLIDER_SINGLE_STEP_SUB = QAbstractSlider.SliderAction.SliderSingleStepSub.value
|
|
242
|
+
SLIDER_PAGE_STEP_ADD = QAbstractSlider.SliderAction.SliderPageStepAdd.value
|
|
243
|
+
SLIDER_PAGE_STEP_SUB = QAbstractSlider.SliderAction.SliderPageStepSub.value
|
|
244
|
+
SLIDER_MOVE = QAbstractSlider.SliderAction.SliderMove.value
|
|
245
|
+
elif QT_BINDING == QtBindings.PyQt5:
|
|
246
|
+
import PyQt5.QtCore as QtCore
|
|
247
|
+
import PyQt5.QtGui as QtGui
|
|
248
|
+
import PyQt5.QtWidgets as QtWidgets
|
|
249
|
+
from PyQt5.QtCore import Qt, QTimer, pyqtSignal
|
|
250
|
+
from PyQt5.QtGui import QImage, QPixmap, QColor, QPainter, QPen, QScreen
|
|
251
|
+
from PyQt5.QtWidgets import (
|
|
252
|
+
QAbstractSlider,
|
|
253
|
+
QApplication,
|
|
254
|
+
QCheckBox,
|
|
255
|
+
QComboBox,
|
|
256
|
+
QFileDialog,
|
|
257
|
+
QFrame,
|
|
258
|
+
QGroupBox,
|
|
259
|
+
QHBoxLayout,
|
|
260
|
+
QLabel,
|
|
261
|
+
QLineEdit,
|
|
262
|
+
QMainWindow,
|
|
263
|
+
QMessageBox,
|
|
264
|
+
QPushButton,
|
|
265
|
+
QScrollArea,
|
|
266
|
+
QSizePolicy,
|
|
267
|
+
QSlider,
|
|
268
|
+
QVBoxLayout,
|
|
269
|
+
QWidget,
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
Signal = pyqtSignal
|
|
273
|
+
QtSignal = pyqtSignal
|
|
274
|
+
IS_PYQT = True
|
|
275
|
+
|
|
276
|
+
QIMAGE_FORMAT_RGB32 = QImage.Format_RGB32
|
|
277
|
+
QIMAGE_FORMAT_ARGB32 = QImage.Format_ARGB32
|
|
278
|
+
QIMAGE_FORMAT_RGB888 = QImage.Format_RGB888
|
|
279
|
+
Format_RGB32 = QIMAGE_FORMAT_RGB32
|
|
280
|
+
Format_ARGB32 = QIMAGE_FORMAT_ARGB32
|
|
281
|
+
Format_RGB888 = QIMAGE_FORMAT_RGB888
|
|
282
|
+
|
|
283
|
+
QT_KEEP_ASPECT_RATIO = Qt.KeepAspectRatio
|
|
284
|
+
QT_SMOOTH_TRANSFORMATION = Qt.SmoothTransformation
|
|
285
|
+
QT_ALIGN_CENTER = Qt.AlignCenter
|
|
286
|
+
QT_HORIZONTAL = Qt.Horizontal
|
|
287
|
+
QT_SCROLLBAR_ALWAYS_OFF = Qt.ScrollBarAlwaysOff
|
|
288
|
+
QT_SCROLLBAR_AS_NEEDED = Qt.ScrollBarAsNeeded
|
|
289
|
+
QSIZEPOLICY_EXPANDING = QSizePolicy.Expanding
|
|
290
|
+
|
|
291
|
+
SLIDER_SINGLE_STEP_ADD = int(QAbstractSlider.SliderAction.SliderSingleStepAdd)
|
|
292
|
+
SLIDER_SINGLE_STEP_SUB = int(QAbstractSlider.SliderAction.SliderSingleStepSub)
|
|
293
|
+
SLIDER_PAGE_STEP_ADD = int(QAbstractSlider.SliderAction.SliderPageStepAdd)
|
|
294
|
+
SLIDER_PAGE_STEP_SUB = int(QAbstractSlider.SliderAction.SliderPageStepSub)
|
|
295
|
+
SLIDER_MOVE = int(QAbstractSlider.SliderAction.SliderMove)
|
|
296
|
+
elif QT_BINDING == QtBindings.PySide2:
|
|
297
|
+
import PySide2.QtCore as QtCore
|
|
298
|
+
import PySide2.QtGui as QtGui
|
|
299
|
+
import PySide2.QtWidgets as QtWidgets
|
|
300
|
+
from PySide2.QtCore import Qt, QTimer, Signal
|
|
301
|
+
from PySide2.QtGui import QImage, QPixmap, QColor, QPainter, QPen, QScreen
|
|
302
|
+
from PySide2.QtWidgets import (
|
|
303
|
+
QAbstractSlider,
|
|
304
|
+
QApplication,
|
|
305
|
+
QCheckBox,
|
|
306
|
+
QComboBox,
|
|
307
|
+
QFileDialog,
|
|
308
|
+
QFrame,
|
|
309
|
+
QGroupBox,
|
|
310
|
+
QHBoxLayout,
|
|
311
|
+
QLabel,
|
|
312
|
+
QLineEdit,
|
|
313
|
+
QMainWindow,
|
|
314
|
+
QMessageBox,
|
|
315
|
+
QPushButton,
|
|
316
|
+
QScrollArea,
|
|
317
|
+
QSizePolicy,
|
|
318
|
+
QSlider,
|
|
319
|
+
QVBoxLayout,
|
|
320
|
+
QWidget,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
pyqtSignal = Signal
|
|
324
|
+
QtSignal = Signal
|
|
325
|
+
IS_PYSIDE = True
|
|
326
|
+
|
|
327
|
+
QIMAGE_FORMAT_RGB32 = QImage.Format_RGB32
|
|
328
|
+
QIMAGE_FORMAT_ARGB32 = QImage.Format_ARGB32
|
|
329
|
+
QIMAGE_FORMAT_RGB888 = QImage.Format_RGB888
|
|
330
|
+
Format_RGB32 = QIMAGE_FORMAT_RGB32
|
|
331
|
+
Format_ARGB32 = QIMAGE_FORMAT_ARGB32
|
|
332
|
+
Format_RGB888 = QIMAGE_FORMAT_RGB888
|
|
333
|
+
|
|
334
|
+
QT_KEEP_ASPECT_RATIO = Qt.KeepAspectRatio
|
|
335
|
+
QT_SMOOTH_TRANSFORMATION = Qt.SmoothTransformation
|
|
336
|
+
QT_ALIGN_CENTER = Qt.AlignCenter
|
|
337
|
+
QT_HORIZONTAL = Qt.Horizontal
|
|
338
|
+
QT_SCROLLBAR_ALWAYS_OFF = Qt.ScrollBarAlwaysOff
|
|
339
|
+
QT_SCROLLBAR_AS_NEEDED = Qt.ScrollBarAsNeeded
|
|
340
|
+
QSIZEPOLICY_EXPANDING = QSizePolicy.Expanding
|
|
341
|
+
|
|
342
|
+
SLIDER_SINGLE_STEP_ADD = int(QAbstractSlider.SliderAction.SliderSingleStepAdd)
|
|
343
|
+
SLIDER_SINGLE_STEP_SUB = int(QAbstractSlider.SliderAction.SliderSingleStepSub)
|
|
344
|
+
SLIDER_PAGE_STEP_ADD = int(QAbstractSlider.SliderAction.SliderPageStepAdd)
|
|
345
|
+
SLIDER_PAGE_STEP_SUB = int(QAbstractSlider.SliderAction.SliderPageStepSub)
|
|
346
|
+
SLIDER_MOVE = int(QAbstractSlider.SliderAction.SliderMove)
|
|
347
|
+
elif QT_BINDING == QtBindings.PyQt4:
|
|
348
|
+
import PyQt4.QtCore as QtCore
|
|
349
|
+
import PyQt4.QtGui as QtGui
|
|
350
|
+
from PyQt4.QtCore import Qt, QTimer, pyqtSignal
|
|
351
|
+
from PyQt4.QtGui import (
|
|
352
|
+
QAbstractSlider,
|
|
353
|
+
QApplication,
|
|
354
|
+
QCheckBox,
|
|
355
|
+
QComboBox,
|
|
356
|
+
QDesktopServices,
|
|
357
|
+
QDesktopWidget,
|
|
358
|
+
QFileDialog,
|
|
359
|
+
QFrame,
|
|
360
|
+
QGroupBox,
|
|
361
|
+
QHBoxLayout,
|
|
362
|
+
QImage,
|
|
363
|
+
QLabel,
|
|
364
|
+
QLineEdit,
|
|
365
|
+
QMainWindow,
|
|
366
|
+
QMessageBox,
|
|
367
|
+
QPainter,
|
|
368
|
+
QPen,
|
|
369
|
+
QPixmap,
|
|
370
|
+
QPushButton,
|
|
371
|
+
QScrollArea,
|
|
372
|
+
QSizePolicy,
|
|
373
|
+
QSlider,
|
|
374
|
+
QVBoxLayout,
|
|
375
|
+
QWidget,
|
|
376
|
+
QColor,
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
QtWidgets = QtGui
|
|
380
|
+
Signal = pyqtSignal
|
|
381
|
+
QtSignal = pyqtSignal
|
|
382
|
+
IS_PYQT = True
|
|
383
|
+
|
|
384
|
+
QIMAGE_FORMAT_RGB32 = QImage.Format_RGB32
|
|
385
|
+
QIMAGE_FORMAT_ARGB32 = QImage.Format_ARGB32
|
|
386
|
+
QIMAGE_FORMAT_RGB888 = QImage.Format_RGB888
|
|
387
|
+
Format_RGB32 = QIMAGE_FORMAT_RGB32
|
|
388
|
+
Format_ARGB32 = QIMAGE_FORMAT_ARGB32
|
|
389
|
+
Format_RGB888 = QIMAGE_FORMAT_RGB888
|
|
390
|
+
|
|
391
|
+
QT_KEEP_ASPECT_RATIO = Qt.KeepAspectRatio
|
|
392
|
+
QT_SMOOTH_TRANSFORMATION = Qt.SmoothTransformation
|
|
393
|
+
QT_ALIGN_CENTER = Qt.AlignCenter
|
|
394
|
+
QT_HORIZONTAL = Qt.Horizontal
|
|
395
|
+
QT_SCROLLBAR_ALWAYS_OFF = Qt.ScrollBarAlwaysOff
|
|
396
|
+
QT_SCROLLBAR_AS_NEEDED = Qt.ScrollBarAsNeeded
|
|
397
|
+
QSIZEPOLICY_EXPANDING = QSizePolicy.Expanding
|
|
398
|
+
|
|
399
|
+
SLIDER_SINGLE_STEP_ADD = QAbstractSlider.SliderSingleStepAdd
|
|
400
|
+
SLIDER_SINGLE_STEP_SUB = QAbstractSlider.SliderSingleStepSub
|
|
401
|
+
SLIDER_PAGE_STEP_ADD = QAbstractSlider.SliderPageStepAdd
|
|
402
|
+
SLIDER_PAGE_STEP_SUB = QAbstractSlider.SliderPageStepSub
|
|
403
|
+
SLIDER_MOVE = QAbstractSlider.SliderMove
|
|
404
|
+
elif QT_BINDING == QtBindings.PySide:
|
|
405
|
+
import PySide.QtCore as QtCore
|
|
406
|
+
import PySide.QtGui as QtGui
|
|
407
|
+
from PySide.QtCore import Qt, QTimer, Signal
|
|
408
|
+
from PySide.QtGui import (
|
|
409
|
+
QAbstractSlider,
|
|
410
|
+
QApplication,
|
|
411
|
+
QCheckBox,
|
|
412
|
+
QComboBox,
|
|
413
|
+
QDesktopServices,
|
|
414
|
+
QDesktopWidget,
|
|
415
|
+
QFileDialog,
|
|
416
|
+
QFrame,
|
|
417
|
+
QGroupBox,
|
|
418
|
+
QHBoxLayout,
|
|
419
|
+
QImage,
|
|
420
|
+
QLabel,
|
|
421
|
+
QLineEdit,
|
|
422
|
+
QMainWindow,
|
|
423
|
+
QMessageBox,
|
|
424
|
+
QPainter,
|
|
425
|
+
QPen,
|
|
426
|
+
QPixmap,
|
|
427
|
+
QPushButton,
|
|
428
|
+
QScrollArea,
|
|
429
|
+
QSizePolicy,
|
|
430
|
+
QSlider,
|
|
431
|
+
QVBoxLayout,
|
|
432
|
+
QWidget,
|
|
433
|
+
QColor,
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
QtWidgets = QtGui
|
|
437
|
+
pyqtSignal = Signal
|
|
438
|
+
QtSignal = Signal
|
|
439
|
+
IS_PYSIDE = True
|
|
440
|
+
|
|
441
|
+
QIMAGE_FORMAT_RGB32 = QImage.Format_RGB32
|
|
442
|
+
QIMAGE_FORMAT_ARGB32 = QImage.Format_ARGB32
|
|
443
|
+
QIMAGE_FORMAT_RGB888 = QImage.Format_RGB888
|
|
444
|
+
Format_RGB32 = QIMAGE_FORMAT_RGB32
|
|
445
|
+
Format_ARGB32 = QIMAGE_FORMAT_ARGB32
|
|
446
|
+
Format_RGB888 = QIMAGE_FORMAT_RGB888
|
|
447
|
+
|
|
448
|
+
QT_KEEP_ASPECT_RATIO = Qt.KeepAspectRatio
|
|
449
|
+
QT_SMOOTH_TRANSFORMATION = Qt.SmoothTransformation
|
|
450
|
+
QT_ALIGN_CENTER = Qt.AlignCenter
|
|
451
|
+
QT_HORIZONTAL = Qt.Horizontal
|
|
452
|
+
QT_SCROLLBAR_ALWAYS_OFF = Qt.ScrollBarAlwaysOff
|
|
453
|
+
QT_SCROLLBAR_AS_NEEDED = Qt.ScrollBarAsNeeded
|
|
454
|
+
QSIZEPOLICY_EXPANDING = QSizePolicy.Expanding
|
|
455
|
+
|
|
456
|
+
SLIDER_SINGLE_STEP_ADD = int(QAbstractSlider.SliderAction.SliderSingleStepAdd)
|
|
457
|
+
SLIDER_SINGLE_STEP_SUB = int(QAbstractSlider.SliderAction.SliderSingleStepSub)
|
|
458
|
+
SLIDER_PAGE_STEP_ADD = int(QAbstractSlider.SliderAction.SliderPageStepAdd)
|
|
459
|
+
SLIDER_PAGE_STEP_SUB = int(QAbstractSlider.SliderAction.SliderPageStepSub)
|
|
460
|
+
SLIDER_MOVE = int(QAbstractSlider.SliderAction.SliderMove)
|
|
461
|
+
else:
|
|
462
|
+
raise ImportError(SUPPORTED_QT_BINDINGS_MESSAGE)
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
del detect_qt_binding
|
|
466
|
+
del SUPPORTED_QT_BINDINGS_MESSAGE
|
|
467
|
+
del qt_binding
|
|
468
|
+
del detected_qt_binding
|
|
469
|
+
del QtCore
|
|
470
|
+
del QtGui
|
|
471
|
+
del QtWidgets
|
|
472
|
+
del Qt
|
|
473
|
+
del Signal
|
|
474
|
+
del pyqtSignal
|
|
475
|
+
del QIMAGE_FORMAT_RGB32
|
|
476
|
+
del QIMAGE_FORMAT_ARGB32
|
|
477
|
+
del QIMAGE_FORMAT_RGB888
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def exec_qapplication(app):
|
|
481
|
+
# type: (QApplication) -> int
|
|
482
|
+
if IS_QT6:
|
|
483
|
+
return getattr(app, "exec")()
|
|
484
|
+
return app.exec_()
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def execute(q_application):
|
|
488
|
+
# type: (QApplication) -> int
|
|
489
|
+
return exec_qapplication(q_application)
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
def get_or_create_q_application(argv=None):
|
|
493
|
+
# type: (object) -> QApplication
|
|
494
|
+
q_application = QApplication.instance()
|
|
495
|
+
if q_application is None:
|
|
496
|
+
if argv is None:
|
|
497
|
+
argv = sys.argv
|
|
498
|
+
q_application = QApplication(argv)
|
|
499
|
+
return q_application
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def qimage_get_buffer(qimage):
|
|
503
|
+
# type: (QImage) -> object
|
|
504
|
+
buffer_object = qimage.constBits()
|
|
505
|
+
if IS_PYQT:
|
|
506
|
+
if QT_BINDING == QtBindings.PyQt4:
|
|
507
|
+
buffer_object.setsize(qimage.byteCount())
|
|
508
|
+
else:
|
|
509
|
+
buffer_object.setsize(qimage.sizeInBytes())
|
|
510
|
+
return buffer_object
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def get_buffer(qimage):
|
|
514
|
+
# type: (QImage) -> object
|
|
515
|
+
return qimage_get_buffer(qimage)
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def get_primary_screen_geometry():
|
|
519
|
+
# type: () -> object
|
|
520
|
+
get_or_create_q_application()
|
|
521
|
+
if QDesktopWidget is not None:
|
|
522
|
+
desktop_widget = QDesktopWidget()
|
|
523
|
+
return desktop_widget.screenGeometry()
|
|
524
|
+
primary_screen = QApplication.primaryScreen()
|
|
525
|
+
return primary_screen.geometry()
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def get_primary_screen_size():
|
|
529
|
+
# type: () -> tuple
|
|
530
|
+
geometry = get_primary_screen_geometry()
|
|
531
|
+
return geometry.width(), geometry.height()
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def grab_primary_screen_pixmap():
|
|
535
|
+
# type: () -> QPixmap
|
|
536
|
+
get_or_create_q_application()
|
|
537
|
+
if QDesktopWidget is not None:
|
|
538
|
+
desktop_widget = QDesktopWidget()
|
|
539
|
+
geometry = desktop_widget.screenGeometry()
|
|
540
|
+
return QPixmap.grabWindow(
|
|
541
|
+
desktop_widget.winId(), 0, 0, geometry.width(), geometry.height()
|
|
542
|
+
)
|
|
543
|
+
primary_screen = QApplication.primaryScreen()
|
|
544
|
+
geometry = primary_screen.geometry()
|
|
545
|
+
return primary_screen.grabWindow(0, 0, 0, geometry.width(), geometry.height())
|