-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 test(Wrapper): Wrapper for sip and shiboken
- Loading branch information
Showing
17 changed files
with
1,052 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project(WigglyWidget LANGUAGES CXX) | ||
|
||
add_subdirectory(LibWigglyWidget) | ||
add_subdirectory(TestWigglyWidget) | ||
add_subdirectory(PyQtWrapper) | ||
add_subdirectory(PySideWrapper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project(LibWigglyWidget LANGUAGES CXX) | ||
|
||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
# 配置安装目录 | ||
set(CMAKE_INSTALL_DIR "${CMAKE_SOURCE_DIR}/dist") | ||
|
||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) | ||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) | ||
|
||
add_library(LibWigglyWidget SHARED WigglyWidget_global.h wigglywidget.cpp | ||
wigglywidget.h) | ||
|
||
target_link_libraries(LibWigglyWidget PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) | ||
|
||
target_compile_definitions(LibWigglyWidget PRIVATE LIBWIGGLYWIDGET_LIBRARY) | ||
|
||
# 配置生成的文件安装目录 | ||
install( | ||
TARGETS ${PROJECT_NAME} | ||
RUNTIME DESTINATION "${CMAKE_INSTALL_DIR}/bin" | ||
LIBRARY DESTINATION "${CMAKE_INSTALL_DIR}/lib" | ||
ARCHIVE DESTINATION "${CMAKE_INSTALL_DIR}/lib") | ||
|
||
install(FILES wigglywidget.h DESTINATION "${CMAKE_INSTALL_DIR}/include") | ||
|
||
message( | ||
NOTICE | ||
"****${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef WIGGLYWIDGET_GLOBAL_H | ||
#define WIGGLYWIDGET_GLOBAL_H | ||
|
||
#include <QtCore/qglobal.h> | ||
|
||
#if defined(WIGGLYWIDGET_LIBRARY) | ||
#define WIGGLYWIDGET_EXPORT Q_DECL_EXPORT | ||
#else | ||
#define WIGGLYWIDGET_EXPORT Q_DECL_IMPORT | ||
#endif | ||
|
||
#endif // WIGGLYWIDGET_GLOBAL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "wigglywidget.h" | ||
|
||
#include <QFontMetrics> | ||
#include <QPainter> | ||
#include <QTimerEvent> | ||
|
||
WigglyWidget::WigglyWidget(QWidget *parent) : QWidget(parent), step(0) { | ||
setBackgroundRole(QPalette::Midlight); | ||
setAutoFillBackground(true); | ||
|
||
QFont newFont = font(); | ||
newFont.setPointSize(newFont.pointSize() + 20); | ||
setFont(newFont); | ||
|
||
timer.start(60, this); | ||
} | ||
|
||
void WigglyWidget::setText(const QString &newText) { text = newText; } | ||
|
||
void WigglyWidget::paintEvent(QPaintEvent * /* event */) | ||
|
||
{ | ||
static constexpr int sineTable[16] = {0, 38, 71, 92, 100, 92, 71, 38, | ||
0, -38, -71, -92, -100, -92, -71, -38}; | ||
|
||
QFontMetrics metrics(font()); | ||
int x = (width() - metrics.horizontalAdvance(text)) / 2; | ||
int y = (height() + metrics.ascent() - metrics.descent()) / 2; | ||
QColor color; | ||
|
||
QPainter painter(this); | ||
|
||
for (int i = 0; i < text.size(); ++i) { | ||
int index = (step + i) % 16; | ||
color.setHsv((15 - index) * 16, 255, 191); | ||
painter.setPen(color); | ||
painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400), | ||
QString(text[i])); | ||
x += metrics.horizontalAdvance(text[i]); | ||
} | ||
} | ||
|
||
void WigglyWidget::timerEvent(QTimerEvent *event) { | ||
if (event->timerId() == timer.timerId()) { | ||
++step; | ||
update(); | ||
} else { | ||
QWidget::timerEvent(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef WIGGLYWIDGET_H | ||
#define WIGGLYWIDGET_H | ||
|
||
#include <QBasicTimer> | ||
#include <QWidget> | ||
|
||
#include "WigglyWidget_global.h" | ||
|
||
class WIGGLYWIDGET_EXPORT WigglyWidget : public QWidget { | ||
Q_OBJECT | ||
|
||
public: | ||
WigglyWidget(QWidget *parent = nullptr); | ||
|
||
public slots: | ||
void setText(const QString &newText); | ||
|
||
protected: | ||
virtual void paintEvent(QPaintEvent *event) override; | ||
virtual void timerEvent(QTimerEvent *event) override; | ||
|
||
private: | ||
QBasicTimer timer; | ||
QString text; | ||
int step; | ||
}; | ||
|
||
#endif // WIGGLYWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project(PyQtWrapper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project(PySideWrapper) | ||
|
||
set(BINDINGS_HEADER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/bindings.h") | ||
set(BINDINGS_TYPESYSTEM_FILE "${CMAKE_CURRENT_SOURCE_DIR}/bindings.xml") | ||
set(BINDINGS_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dist") | ||
set(BINDINGS_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../dist/include/") | ||
|
||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bindings.txt.in" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/bindings.txt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Created on 2024/04/26 | ||
@author: Irony | ||
@site: https://pyqt.site | https://github.com/PyQt5 | ||
@email: [email protected] | ||
@file: TestWigglyWidget.py | ||
@description: | ||
""" | ||
|
||
import os | ||
import sys | ||
|
||
|
||
from PySide2.QtWidgets import QApplication, QLineEdit, QVBoxLayout, QWidget | ||
from PySide2.WigglyWidget import WigglyWidget | ||
|
||
class TestWigglyWidget(QWidget): | ||
def __init__(self, *args, **kwargs): | ||
super(TestWigglyWidget, self).__init__(*args, **kwargs) | ||
self._layout = QVBoxLayout(self) | ||
self._lineEdit = QLineEdit(self) | ||
self._wigglyWidget = WigglyWidget(self) | ||
self._layout.addWidget(self._lineEdit) | ||
self._layout.addWidget(self._wigglyWidget) | ||
|
||
self._lineEdit.textChanged.connect(self._wigglyWidget.setText) | ||
self._lineEdit.setText("pyqt.site") | ||
|
||
|
||
if __name__ == "__main__": | ||
import cgitb | ||
import sys | ||
|
||
cgitb.enable(format="text") | ||
app = QApplication(sys.argv) | ||
w = TestWigglyWidget() | ||
w.show() | ||
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef BINDINGS_H | ||
#define BINDINGS_H | ||
#include "wigglywidget.h" | ||
#endif // BINDINGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[generator-project] | ||
generator-set = shiboken | ||
header-file = ${BINDINGS_HEADER_FILE} | ||
typesystem-file = ${BINDINGS_TYPESYSTEM_FILE} | ||
output-directory = ${BINDINGS_OUTPUT_DIR} | ||
include-path = ${BINDINGS_INCLUDE_PATH} | ||
framework-include-paths = | ||
typesystem-paths = ${BINDINGS_TYPESYSTEM_PATH} | ||
|
||
enable-parent-ctor-heuristic | ||
enable-pyside-extensions | ||
enable-return-value-heuristic | ||
use-isnull-as-nb_nonzero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<typesystem package="PySide2"> | ||
<load-typesystem name="typesystem_widgets.xml" generate="no"/> | ||
<object-type name="WigglyWidget"/> | ||
</typesystem> |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
PySide2 | ||
|
||
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" | ||
|
||
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-win32.whl; platform_machine == "i686" and platform_system == "Windows" | ||
|
||
https://download.qt.io/official_releases/QtForPython/shiboken2-generator/shiboken2_generator-5.15.2.1-5.15.2-cp35.cp36.cp37.cp38.cp39.cp310-abi3-manylinux1_x86_64.whl; platform_machine == "x86_64" and platform_system == "Linux" | ||
|
||
https://download.qt.io/official_releases/QtForPython/shiboken2-generator/shiboken2_generator-5.15.2.1-5.15.2-cp35.cp36.cp37.cp38.cp39.cp310-abi3-macosx_10_13_intel.whl; platform_machine == "x86_64" and platform_system == "Darwin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project( | ||
TestWigglyWidget | ||
VERSION 0.1 | ||
LANGUAGES CXX) | ||
|
||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
# 配置安装目录 | ||
set(CMAKE_INSTALL_DIR "${CMAKE_SOURCE_DIR}/dist") | ||
|
||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) | ||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) | ||
|
||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../LibWigglyWidget") | ||
|
||
set(PROJECT_SOURCES main.cpp) | ||
|
||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) | ||
qt_add_executable(${PROJECT_NAME} MANUAL_FINALIZATION ${PROJECT_SOURCES}) | ||
# Define target properties for Android with Qt 6 as: set_property(TARGET | ||
# TestWigglyWidget APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR | ||
# ${CMAKE_CURRENT_SOURCE_DIR}/android) For more information, see | ||
# https://doc.qt.io/qt-6/qt-add-executable.html#target-creation | ||
else() | ||
if(ANDROID) | ||
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES}) | ||
# Define properties for Android with Qt 5 after find_package() calls as: | ||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") | ||
else() | ||
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES}) | ||
endif() | ||
endif() | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets | ||
LibWigglyWidget) | ||
|
||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. If | ||
# you are developing for iOS or macOS you should consider setting an explicit, | ||
# fixed bundle identifier manually though. | ||
if(${QT_VERSION} VERSION_LESS 6.1.0) | ||
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER | ||
com.example.TestWigglyWidget) | ||
endif() | ||
set_target_properties( | ||
${PROJECT_NAME} | ||
PROPERTIES ${BUNDLE_ID_OPTION} MACOSX_BUNDLE_BUNDLE_VERSION | ||
${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING | ||
${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE | ||
TRUE WIN32_EXECUTABLE | ||
TRUE) | ||
|
||
if(QT_VERSION_MAJOR EQUAL 6) | ||
qt_finalize_executable(${PROJECT_NAME}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <QApplication> | ||
|
||
#include "wigglywidget.h" | ||
|
||
int main(int argc, char *argv[]) { | ||
QApplication a(argc, argv); | ||
WigglyWidget w; | ||
w.setText("pyqt.site"); | ||
w.show(); | ||
return a.exec(); | ||
} |