Skip to content

Commit 2311dfe

Browse files
committed
🔧 build(sip): PyQt5 support wrapper
1 parent e943272 commit 2311dfe

12 files changed

+167
-24
lines changed

Test/WigglyWidget/LibWigglyWidget/CMakeLists.txt

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ set(CMAKE_INSTALL_DIR "${CMAKE_SOURCE_DIR}/dist")
1414
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
1515
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
1616

17-
add_library(LibWigglyWidget SHARED WigglyWidget_global.h wigglywidget.cpp
18-
wigglywidget.h)
17+
add_library(LibWigglyWidget STATIC wigglywidget.cpp wigglywidget.h)
1918

2019
target_link_libraries(LibWigglyWidget PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
2120

@@ -29,8 +28,3 @@ install(
2928
ARCHIVE DESTINATION "${CMAKE_INSTALL_DIR}/lib")
3029

3130
install(FILES wigglywidget.h DESTINATION "${CMAKE_INSTALL_DIR}/include")
32-
33-
message(
34-
NOTICE
35-
"****${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS}"
36-
)

Test/WigglyWidget/LibWigglyWidget/WigglyWidget_global.h

-12
This file was deleted.

Test/WigglyWidget/LibWigglyWidget/wigglywidget.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@
44
#include <QBasicTimer>
55
#include <QWidget>
66

7-
#include "WigglyWidget_global.h"
7+
#ifdef Q_OS_WIN
8+
#include <QtCore/qglobal.h>
89

10+
#if defined(WIGGLYWIDGET_LIBRARY)
11+
#define WIGGLYWIDGET_EXPORT Q_DECL_EXPORT
12+
#else
13+
#define WIGGLYWIDGET_EXPORT Q_DECL_IMPORT
14+
#endif
15+
#endif
16+
17+
#ifdef Q_OS_WIN
918
class WIGGLYWIDGET_EXPORT WigglyWidget : public QWidget {
19+
#else
20+
class WigglyWidget : public QWidget {
21+
#endif
1022
Q_OBJECT
1123

1224
public:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Created on 2024/04/26
6+
@author: Irony
7+
@site: https://pyqt.site | https://github.com/PyQt5
8+
9+
@file: TestWigglyWidget.py
10+
@description:
11+
"""
12+
13+
import os
14+
import sys
15+
16+
sys.path.append(
17+
os.path.join(os.path.dirname(os.path.abspath(__file__)), "build/WigglyWidget")
18+
)
19+
20+
from PyQt5.QtWidgets import QApplication, QLineEdit, QVBoxLayout, QWidget
21+
from WigglyWidget import WigglyWidget
22+
23+
24+
class TestWigglyWidget(QWidget):
25+
def __init__(self, *args, **kwargs):
26+
super(TestWigglyWidget, self).__init__(*args, **kwargs)
27+
self._layout = QVBoxLayout(self)
28+
self._lineEdit = QLineEdit(self)
29+
self._wigglyWidget = WigglyWidget(self)
30+
self._layout.addWidget(self._lineEdit)
31+
self._layout.addWidget(self._wigglyWidget)
32+
33+
self._lineEdit.textChanged.connect(self._wigglyWidget.setText)
34+
self._lineEdit.setText("pyqt.site")
35+
36+
37+
if __name__ == "__main__":
38+
import cgitb
39+
import sys
40+
41+
cgitb.enable(format="text")
42+
app = QApplication(sys.argv)
43+
w = TestWigglyWidget()
44+
w.show()
45+
sys.exit(app.exec_())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Specify sip v6 as the build system for the package.
2+
[build-system]
3+
requires = ["sip >=5.3, <7", "PyQt-builder >=1.9, <2"]
4+
build-backend = "sipbuild.api"
5+
6+
# Specify the PEP 621 metadata for the project.
7+
[project]
8+
name = "WigglyWidget"
9+
version = "0.1.0"
10+
description = "Python bindings for the WigglyWidget library"
11+
urls.homepage = "https://github.com/PyQt5/PyQt"
12+
dependencies = ["PyQt5 (>=5.15.0, <6.0.0)"]
13+
14+
[[project.authors]]
15+
name = "Irony"
16+
17+
18+
# Specify a PyQt-based project.
19+
[tool.sip]
20+
project-factory = "pyqtbuild:PyQtProject"
21+
22+
# Specify the PEP 566 metadata for the project.
23+
[tool.sip.metadata]
24+
name = "WigglyWidget"
25+
summary = "Python bindings for the WigglyWidget library"
26+
home-page = "https://github.com/PyQt5/PyQt"
27+
author = "Irony"
28+
author-email = "[email protected]"
29+
requires-dist = "PyQt5 (>=5.15.0, <6.0.0)"
30+
31+
# Configure the project.
32+
[tool.sip.project]
33+
tag-prefix = "WigglyWidget"
34+
sip-include-dirs = [
35+
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PyQt5/bindings",
36+
"/usr/local/lib64/python3.6/site-packages/PyQt5/bindings",
37+
"C:/soft/Python311/Lib/site-packages/PyQt5/bindings",
38+
]
39+
40+
# Configure the building of the fib bindings.
41+
[tool.sip.bindings.WigglyWidget]
42+
qmake-QT = ["core", "gui", "widgets"]
43+
headers = ["wigglywidget.h"]
44+
include-dirs = ["../dist/include"]
45+
libraries = ["LibWigglyWidget"]
46+
library-dirs = ["../dist/lib"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PyQt5
2+
sip
3+
PyQt5-sip
4+
PyQt-builder
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class WigglyWidget : QWidget
2+
{
3+
%TypeHeaderCode
4+
#include "wigglywidget.h"
5+
%End
6+
7+
public:
8+
WigglyWidget(QWidget *parent /TransferThis/ = 0);
9+
10+
public slots:
11+
void setText(const QString &newText);
12+
13+
protected:
14+
virtual void paintEvent(QPaintEvent *);
15+
virtual void timerEvent(QTimerEvent *);
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%Module(name=WigglyWidget, keyword_arguments="Optional", use_limited_api=True)
2+
3+
4+
%Import QtCore/QtCoremod.sip
5+
%Import QtWidgets/QtWidgetsmod.sip
6+
7+
%DefaultSupertype sip.simplewrapper
8+
9+
%Include WigglyWidget.sip

Test/WigglyWidget/PySideWrapper/CMakeLists.txt

+19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
cmake_minimum_required(VERSION 3.14)
2+
cmake_policy(VERSION 3.14)
3+
4+
# Enable policy to not use RPATH settings for install_name on macOS.
5+
if(POLICY CMP0068)
6+
cmake_policy(SET CMP0068 NEW)
7+
endif()
8+
9+
# Enable policy to run automoc on generated files.
10+
if(POLICY CMP0071)
11+
cmake_policy(SET CMP0071 NEW)
12+
endif()
213

314
project(PySideWrapper)
415

16+
set(CMAKE_AUTOUIC ON)
17+
set(CMAKE_AUTOMOC ON)
18+
set(CMAKE_AUTORCC ON)
19+
20+
set(CMAKE_CXX_STANDARD 17)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
23+
524
set(BINDINGS_HEADER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/bindings.h")
625
set(BINDINGS_TYPESYSTEM_FILE "${CMAKE_CURRENT_SOURCE_DIR}/bindings.xml")
726
set(BINDINGS_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dist")

Test/WigglyWidget/PySideWrapper/TestWigglyWidget.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
@description:
1111
"""
1212

13-
import os
1413
import sys
1514

16-
1715
from PySide2.QtWidgets import QApplication, QLineEdit, QVBoxLayout, QWidget
18-
from PySide2.WigglyWidget import WigglyWidget
16+
from WigglyWidget import WigglyWidget
17+
1918

2019
class TestWigglyWidget(QWidget):
2120
def __init__(self, *args, **kwargs):

Test/WigglyWidget/PySideWrapper/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PySide2
1+
PySide2==5.15.2.1
22

33
https://download.qt.io/official_releases/QtForPython/shiboken2-generator/shiboken2_generator-5.15.2.1-5.15.2-cp35.cp36.cp37.cp38.cp39.cp310-none-win_amd64.whl; platform_machine == "x86_64" and platform_system == "Windows"
44

Test/WigglyWidget/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# WigglyWidget
2+
3+
## Build
4+
5+
Windows
6+
7+
1. 使用 `QtCreator` 打开项目 `CMakeLists.txt`,勾选对应的Qt版本。
8+
2.`QtCreator` 中通过 `项目`->`构建`->`构建步骤`->`详情` 里勾选 `all``install`
9+
3. 进入 `PyQtWrapper` 目录,打开`vs cmd`,运行 `python -m pip install -r requirements.txt`
10+
4. `sip-build --verbose --tracing --qmake=你的Qt目录下的qmake.exe路径`,等待编译完成
11+
5. `python TestWigglyWidget.py` 进行测试

0 commit comments

Comments
 (0)