From f63d1e42066f4e9ffd1f8d5890a6ca64359491ca Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Tue, 15 Jun 2021 11:40:27 +0800 Subject: [PATCH] document PyQt boxing and unboxing --- pyqtgraph/graphicsItems/ScatterPlotItem.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index e8ffd29d..42c689d3 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -154,6 +154,17 @@ class PixmapFragments: self.alloc(0) def alloc(self, size): + # The C++ native API is: + # drawPixmapFragments(const PixmapFragment *fragments, int fragmentCount, + # const QPixmap &pixmap) + # + # PySide exposes this API whereas PyQt wraps it to be more Pythonic. + # In PyQt, a Python list of PixmapFragment instances needs to be provided. + # This is inefficient because: + # 1) constructing the Python list involves calling sip.wrapinstance multiple times. + # - this is mitigated here by reusing the instance pointers + # 2) PyQt will anyway deconstruct the Python list and repack the PixmapFragment + # instances into a contiguous array, in order to call the underlying C++ native API. self.arr = np.empty((size, 10), dtype=np.float64) if QT_LIB.startswith('PyQt'): self.ptrs = list(map(sip.wrapinstance,