-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Qt5: Add flag that informs paintEvent if the agg buffer needs to updated, fix rubberband #4962
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,20 +58,26 @@ class FigureCanvasQTAggBase(object): | |
|
||
Public attribute | ||
|
||
figure - A Figure instance | ||
""" | ||
figure - A Figure instance | ||
""" | ||
|
||
def __init__(self, figure): | ||
super(FigureCanvasQTAggBase, self).__init__(figure=figure) | ||
self._agg_redraw_flag = True | ||
|
||
def drawRectangle(self, rect): | ||
self._drawRect = rect | ||
self.draw_idle() | ||
self.update() | ||
|
||
def paintEvent(self, e): | ||
""" | ||
Copy the image from the Agg canvas to the qt.drawable. | ||
In Qt, all drawing should be done inside of here when a widget is | ||
shown onscreen. | ||
""" | ||
FigureCanvasAgg.draw(self) | ||
if self._agg_redraw_flag: | ||
self._agg_redraw_flag = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please flip the order on these lines so it is only cleared after the Agg draw has succeeded with out exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have, but I'm still confused about these draw_idle callbacks from within the draw call. If there is a reason for those you cannot clear the flag after draw since it might have been re-set during draw on purpose. |
||
FigureCanvasAgg.draw(self) | ||
|
||
# FigureCanvasQT.paintEvent(self, e) | ||
if DEBUG: | ||
|
@@ -134,9 +140,14 @@ def paintEvent(self, e): | |
pixmap = QtGui.QPixmap.fromImage(qImage) | ||
p = QtGui.QPainter(self) | ||
p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap) | ||
|
||
# draw the zoom rectangle to the QPainter | ||
if self._drawRect is not None: | ||
p.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.DotLine)) | ||
x, y, w, h = self._drawRect | ||
p.drawRect(x, y, w, h) | ||
p.end() | ||
self.blitbox = None | ||
self._drawRect = None | ||
|
||
def draw(self): | ||
""" | ||
|
@@ -147,6 +158,11 @@ def draw(self): | |
# causes problems with code that uses the result of the | ||
# draw() to update plot elements. | ||
FigureCanvasAgg.draw(self) | ||
self._agg_redraw_flag = False | ||
self.update() | ||
|
||
def draw_idle(self): | ||
self._agg_redraw_flag = True | ||
self.update() | ||
|
||
def blit(self, bbox=None): | ||
|
@@ -161,15 +177,16 @@ def blit(self, bbox=None): | |
self.blitbox = bbox | ||
l, b, w, h = bbox.bounds | ||
t = b + h | ||
self._agg_redraw_flag = False # don't repaint the agg buffer in blit() | ||
self.repaint(l, self.renderer.height-t, w, h) | ||
|
||
def print_figure(self, *args, **kwargs): | ||
FigureCanvasAgg.print_figure(self, *args, **kwargs) | ||
self.draw() | ||
|
||
|
||
class FigureCanvasQTAgg(FigureCanvasQTAggBase, | ||
FigureCanvasQT, FigureCanvasAgg): | ||
class FigureCanvasQTAgg(FigureCanvasQT, FigureCanvasQTAggBase, | ||
FigureCanvasAgg): | ||
""" | ||
The canvas the figure renders into. Calls the draw and print fig | ||
methods, creates the renderers, etc. | ||
|
@@ -184,8 +201,7 @@ class FigureCanvasQTAgg(FigureCanvasQTAggBase, | |
def __init__(self, figure): | ||
if DEBUG: | ||
print('FigureCanvasQtAgg: ', figure) | ||
FigureCanvasQT.__init__(self, figure) | ||
FigureCanvasAgg.__init__(self, figure) | ||
super(FigureCanvasQTAgg, self).__init__(figure=figure) | ||
self._drawRect = None | ||
self.blitbox = None | ||
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably stay, do we want to fallback to the base implementation of
draw_idle
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not really clear to me what's the idea of the split between qt5 and qt5agg. Draw is defined in qt5agg, draw_idle is defined in qt5. It seems reasonable to have both at the same spot where the whole draw mechanism is implemented. Its not gone, it just moved from qt5 to qt5agg.