Dr. Cristiรกn Maureira-Fredes
@cmaureir
You can find the slides in qtinfo.dev/qtforpython_qtdevcon22
def add(a: int, b: int) -> int:
return a + b
add(30, 12)
# 42
# n -> int
if n&~-n<1:
# ???
_="_=%r;print(_%%_)";print(_%_)
One can argue, those numbers are not really representative.
But we cannot neglect the impact on fields like Data Science, and AI, and the many conferences and organizations.
Many of the most popular Python modules, rely on compiled languages, like Fortran, C, or C++.
The official set of Python bindings for the Qt framework.
...but not only that ๐ค.
# Common Qt structure
# - Using setter/getter
# - No writable properties
table = QTableWidget()
table.setColumnCount(2)
button = QPushButton("Add")
button.setEnabled(False)
layout = QVBoxLayout()
layout.addWidget(table)
layout.addWidget(button)
layout.setSpacing(2)
from __feature__ import (
snake_case
)
table = QTableWidget()
table.set_column_count(2)
button = QPushButton("Add")
button.set_enabled(False)
layout = QVBoxLayout()
layout.add_widget(table)
layout.add_widget(button)
layout.set_spacing(2)
from __feature__ import (
snake_case, true_property
)
table = QTableWidget()
table.column_count = 2
button = QPushButton("Add")
button.enabled = False
layout = QVBoxLayout()
layout.add_widget(table)
layout.add_widget(button)
layout.spacing = 2
QPointList
vs
list(QList)
vs
deque(QList)
Extreme case, but not impossible ๐
# Appending
Opaque QPointList 0.55s
Python list 0.79s
Python deque 0.84s
- 51% faster (list)
# Pop the first element
Opaque QPointList 0.07s
Python list 69.28s
- 96831% faster
# Pop the first element
Opaque QPointList 0.07s
Python deque 0.29s
- 298%
Name | License | Qt 6 | Qt 5 | Linux | macOS | Windows |
---|---|---|---|---|---|---|
fbs | GPL | partial | โ | โ | โ | โ |
PyInstaller | GPL | partial | โ | โ | โ | โ |
cx_Freeze | MIT | โ | โ | โ | โ | โ |
py2exe | MIT | partial | partial | โ | โ | โ |
py2app | MIT | โ | โ | โ | โ | โ |
briefcase | BSD3 | โ | โ | โ | โ | โ |
Nuitka | MIT | โ | โ | โ | โ | โ |
bugreports.qt.io/browse/PYSIDE-535
# Python
1/8, max ite: 96, time: 4.111s
2/8, max ite: 288, time: 7.179s
3/8, max ite: 1056, time: 22.156s
4/8, max ite: 4128, time: 82.706s
5/8, max ite: 16416, time: 371.348s
# PyPy
1/8, max ite: 96, time: 4.732s
2/8, max ite: 288, time: 4.99s
3/8, max ite: 1056, time: 6.872s
4/8, max ite: 4128, time: 12.451s
5/8, max ite: 16416, time: 33.341s
CMakeLists.txt
test.cpp
test.h
bindings.h
(right top)bindings.xml
(right bottom)
#include "test.hpp"
Simple typesystem
Python usage
from wiggly import WigglyWidget as WigglyWidgetCPP
from wigglywidget import WigglyWidget as WigglyWidgetPY
# ...
widget_py = WigglyWidgetPY(self)
widget_cpp = WigglyWidgetCPP(self)
# ...
layout.addWidget(widget_py)
layout.addWidget(widget_cpp)
Overview
// Simple Engine
QScryptEngine e;
e.execute(...);
QVariant r = e.evaluate(...);
// Load Python module
QScryptModule mod(...);
// Get Function Reference
QScryptFunction f(..., &mod;);
// Call Function
QVariantList args;
QVariant r = f.call(args);
// [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
e.execute("print([i**3 for i in range(10)])");
// QVariant(QString, "Hello This Is A Test")
qDebug() << e.evaluate("f'hello this is a test'.title()");
//QVariant(double, 4950)
qDebug() << e.evaluate("sum(i for i in range(100))")
QScryptModule mod("super"); // super.py
QScryptFunction f1("add_three_numbers", &mod);
QVariantList args1;
args1 << 5 << 6 << 9;
// QVariant(double, 20)
qDebug() << f1.call(args1);
More platforms at wiki.qt.io/Qt_for_Python#Community
Dr. Cristiรกn Maureira-Fredes
@cmaureir
Qt DevCon 2022 | June 15, 2022 | @cmaureir