Skip to content

Fix blitting selector #20264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2021
Merged

Conversation

ericpre
Copy link
Member

@ericpre ericpre commented May 19, 2021

PR Summary

This PR fixes two bugs with blitting Selectors:

  1. A recursive paint loop when resizing the figure with the qt backend.
  2. Fix a similar issue as describe in Update background in SpanSelector._press whenever useblit=True. #9660 but for RectangleSelector/EllipseSelector and SpanSelector once Interactive span selector improvement #20113 is merged, therefore fixing Update background in SpanSelector._press whenever useblit=True. #9660 too!

To reproduce 1

Fix in 94a2f46
From a juptyer qtconsole:

%matplotlib qt
import matplotlib.pyplot as plt
from matplotlib.widgets import RectangleSelector
import numpy as np

values = np.arange(100)

fig = plt.figure()
ax = fig.add_subplot()
ax.plot(values)

span = RectangleSelector(ax, print, useblit=True, interactive=True)

# flush events to get a first draw of the figure before setting the extents
fig.canvas.flush_events()
span.extents = (26, 55, 32, 71)

When resizing the figure, the figure is flickering (in spyder the console crashes when a custom DPI scaling is used) and it gives the following error:

QWidget::repaint: Recursive repaint detected
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::end: Painter not active, aborted

My understanding is that calling _SelectorWidget.ax.blit in _SelectorWidget.update_background (through _SelectorWidget.update) when resizing the figure create the recursive repaint loop.

To reproduce 2

Fix in 031f77c
Adapted from #9660 to reproduce the issue with RectangleSelector and this PR uses the fix suggested in #9660 (comment)

import sys
from PyQt5.QtWidgets import *
from matplotlib.backends.backend_qt5agg import *
from matplotlib.figure import Figure
from matplotlib.widgets import RectangleSelector

class App(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setCentralWidget(QWidget())
        layout = QVBoxLayout()
        self.centralWidget().setLayout(layout)
        self._fig = Figure()
        self._fig.subplots()
        layout.addWidget(FigureCanvas(self._fig))
        layout.addWidget(QPushButton("span", clicked=self._span_cb))

    def _span_cb(self):
        self._span = RectangleSelector(
            self._fig.axes[0], print, useblit=True)

qapp = QApplication(sys.argv)
app = App()
app.show()
qapp.exec_()

The selector is included in the background:
image

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymak jklymak added this to the v3.5.0 milestone May 19, 2021
@jklymak jklymak requested a review from ianhi May 19, 2021 23:56
@jklymak
Copy link
Member

jklymak commented May 19, 2021

@ianhi if you have a chance can you take a look at this? Thanks!

@jklymak jklymak removed the request for review from ianhi May 20, 2021 16:42
@jklymak jklymak merged commit 762666f into matplotlib:master May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants