diff options
| author | Christian Tismer <tismer@stackless.com> | 2022-01-26 12:21:19 +0100 |
|---|---|---|
| committer | Christian Tismer <tismer@stackless.com> | 2022-01-26 17:47:13 +0100 |
| commit | dc2046124f132ba0187d1bff97364448288b1cd6 (patch) | |
| tree | a9f9caa6de943019c06b62ef77905345eb93cafd /sources/pyside6/PySide6/glue/qtgui.cpp | |
| parent | c81ee3c92ac022bb5e9b3d0db72f157a1e1a6513 (diff) | |
PyPySide: Implement a context manager for QPainter
Context managers existed in Python since 2005 (PEP 343).
They were invented to support resource management for
different Python implementations that cannot rely on
immediate object destruction.
PyPy is the first alternate Python implementation
that can run PySide. QPainter does not work in PyPy
without an explicit end() call. For convenience, we
supply a context manager that handles this. Like in
file I/O, we now prefer instead of
painter = QPainter(paintable)
the new indented form
with QPainter(paintable) as painter:
[ChangeLog][PySide6] QPainter has become a context manager.
Using a with statement saves the need to call painter.end() .
Task-number: PYSIDE-535
Change-Id: Ib8bebbe121dc08334d31c9663a1e5bc8042c3b62
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/glue/qtgui.cpp')
| -rw-r--r-- | sources/pyside6/PySide6/glue/qtgui.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp index 5630406a4..16a10807a 100644 --- a/sources/pyside6/PySide6/glue/qtgui.cpp +++ b/sources/pyside6/PySide6/glue/qtgui.cpp @@ -577,6 +577,15 @@ const auto points = PySide::Numpy::xyDataToQPointFList(%PYARG_1, %PYARG_2); %CPPSELF.%FUNCTION_NAME(%1.constData(), %1.size(), %2); // @snippet qpainter-drawpolygon +// @snippet qpainter-enter +Py_INCREF(%PYSELF); +pyResult = %PYSELF; +// @snippet qpainter-enter + +// @snippet qpainter-exit +%CPPSELF.end(); +// @snippet qpainter-exit + // @snippet qmatrix4x4 // PYSIDE-795: All PySequences can be made iterable with PySequence_Fast. Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_1, "Can't turn into sequence")); |
