Skip to content

Prepare support for PySide6 drawLines and friends#2596

Merged
j9ac9k merged 5 commits intopyqtgraph:masterfrom
pijyoi:drawargs
Apr 5, 2023
Merged

Prepare support for PySide6 drawLines and friends#2596
j9ac9k merged 5 commits intopyqtgraph:masterfrom
pijyoi:drawargs

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Jan 28, 2023

As PYSIDE-1924 (https://bugreports.qt.io/browse/PYSIDE-1924) feature has been added, we can prepare pyqtgraph to make use of it when it gets into a released version.
For now, testing can be done with the wheels at https://download.qt.io/snapshots/ci/pyside/dev/latest/

One issue is that PySide6's array API implementation will requirement passing of different arguments than the other codepaths. For this, we add a drawargs() method.

A synthetic benchmark to exercise the new API.

import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui

from time import perf_counter

def generate_pattern(nsegs, size):
    rng = np.random.default_rng()
    x = rng.random(nsegs) * size
    y = rng.random(nsegs) * size
    arr = np.empty((nsegs, 4), dtype=np.float64)
    arr[:, 0] = x
    arr[:, 1] = y
    arr[:, 2] = x + 2
    arr[:, 3] = y + 2
    return arr

nsegs = 10_000
size = 500
nframes = 100
pattern = generate_pattern(nsegs, size)

def run(use_array):
    # generate lines once
    segments = pg.Qt.internals.PrimitiveArray(QtCore.QLineF, 4, use_array=use_array)
    segments.resize(nsegs)
    memory = segments.ndarray()
    memory[:] = pattern

    # draw multiple frames using the same lines array
    t0 = perf_counter()
    for _ in range(nframes):
        qimg = QtGui.QImage(size, size, QtGui.QImage.Format.Format_RGB32)
        qimg.fill(QtCore.Qt.GlobalColor.transparent)
        painter = QtGui.QPainter(qimg)
        painter.setPen(QtCore.Qt.GlobalColor.cyan)
        painter.drawLines(*segments.drawargs())
        painter.end()
    t1 = perf_counter()
    return t1 - t0

for use_array in [False, None, True]:
    duration = run(use_array)
    fps = int(nframes / duration)
    print(f'{use_array=} {duration=:.3f} {fps=}')

raise NotImplementedError
return self._objs

def drawargs(self):

Check notice

Code scanning / CodeQL

Returning tuples with varying lengths

PrimitiveArray.drawargs returns [tuple of size 1](1) and [tuple of size 2](2).
@pijyoi pijyoi marked this pull request as draft January 28, 2023 23:36
@pijyoi pijyoi marked this pull request as ready for review January 29, 2023 00:44
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Feb 5, 2023

Added re-use of backing memory if new size is smaller than largest previous sizes.
This falls back to re-allocation when using PyQt sip.array as sip.array(s) will eventually segfault when sliced.

@pijyoi pijyoi marked this pull request as draft February 8, 2023 22:06
@pijyoi pijyoi force-pushed the drawargs branch 2 times, most recently from 5207f69 to e86a164 Compare February 13, 2023 14:23
@pijyoi pijyoi force-pushed the drawargs branch 2 times, most recently from 872f40b to 12586e8 Compare February 26, 2023 04:39
@pijyoi pijyoi force-pushed the drawargs branch 2 times, most recently from 8b22e9a to 009fcdc Compare March 5, 2023 01:52
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Mar 5, 2023

The re-use of backing memory now also works with the unreleased pyqt5-sip >= 12.11.2 and pyqt6-sip >= 13.4.2.
https://riverbankcomputing.com/pypi/simple/
It is not clear that those versions will be released at all as newer versions already exist (12.12.0 and 13.5.0).

To exercise this PR more within the CI, a temporary change was made to set 'segmentedLineMode': 'on'.
Obviously, that should not be merged.

@pijyoi pijyoi marked this pull request as ready for review March 5, 2023 02:09
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Mar 7, 2023

@pijyoi i love this diff, thank you for commenting the internals.py so thoroughly.

Since we just released 0.13.2, I would be good w/ merging this PR (once segmentedLineMode is set back to auto).

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 4, 2023

PySide 6.5.0 has been released, going to close/re-open this PR to trigger a new CI run.

@j9ac9k j9ac9k closed this Apr 4, 2023
@j9ac9k j9ac9k reopened this Apr 4, 2023
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 4, 2023

unrelated to this PR, but looks like we're getting a failure in CI

Run xvfb-run --server-args="-screen 0, 1920x1200x24 -ac +extension GLX +render -noreset" python -m pyqtgraph.util.glinfo
[14](https://github.com/pyqtgraph/pyqtgraph/actions/runs/4610114611/jobs/8148181442?pr=2596#step:10:15)
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
[15](https://github.com/pyqtgraph/pyqtgraph/actions/runs/4610114611/jobs/8148181442?pr=2596#step:10:16)
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
[16](https://github.com/pyqtgraph/pyqtgraph/actions/runs/4610114611/jobs/8148181442?pr=2596#step:10:17)

[17](https://github.com/pyqtgraph/pyqtgraph/actions/runs/4610114611/jobs/8148181442?pr=2596#step:10:18)
Available platform plugins are: xcb, eglfs, offscreen, vnc, wayland, minimalegl, linuxfb, vkkhrdisplay, minimal, wayland-egl.
[18](https://github.com/pyqtgraph/pyqtgraph/actions/runs/4610114611/jobs/8148181442?pr=2596#step:10:19)

[19](https://github.com/pyqtgraph/pyqtgraph/actions/runs/4610114611/jobs/8148181442?pr=2596#step:10:20)
Aborted (core dumped)

This will need to be addressed before we can test/review this PR.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 5, 2023

Closing and Re-Opening again now that Qt 6.5 works in CI.

@j9ac9k j9ac9k closed this Apr 5, 2023
@j9ac9k j9ac9k reopened this Apr 5, 2023
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 5, 2023

Looks like CI for pyside 6.5 is green across the board, let's undo the segmentation line check and merge 🎊

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Apr 5, 2023

It's already undone

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 5, 2023

It's already undone

oh... well, that's silly of me. Thanks for your work on this @pijyoi !

@j9ac9k j9ac9k merged commit 780449c into pyqtgraph:master Apr 5, 2023
@pijyoi pijyoi deleted the drawargs branch April 5, 2023 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants