mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-29 11:26:57 +08:00
BUG: Fix background update when canvas resized
This commit is contained in:
@@ -25,6 +25,7 @@ class CanvasToolBase(object):
|
||||
if useblit:
|
||||
self.canvas.draw()
|
||||
self.img_background = self.canvas.copy_from_bbox(self.ax.bbox)
|
||||
self.connect_event('resize_event', self._update_saved_image)
|
||||
self.useblit = useblit
|
||||
|
||||
if on_update is None:
|
||||
@@ -58,18 +59,30 @@ class CanvasToolBase(object):
|
||||
return not self.active
|
||||
|
||||
def set_visible(self, val):
|
||||
for a in self._artists:
|
||||
a.set_visible(val)
|
||||
for artist in self._artists:
|
||||
artist.set_visible(val)
|
||||
|
||||
def redraw(self):
|
||||
if self.useblit:
|
||||
self.canvas.restore_region(self.img_background)
|
||||
for artist in self._artists:
|
||||
self.ax.draw_artist(artist)
|
||||
self._draw_artists()
|
||||
self.canvas.blit(self.ax.bbox)
|
||||
else:
|
||||
self.canvas.draw_idle()
|
||||
|
||||
def _draw_artists(self):
|
||||
for artist in self._artists:
|
||||
self.ax.draw_artist(artist)
|
||||
|
||||
def _update_saved_image(self, event):
|
||||
# Hide canvas artists and save background image
|
||||
self.set_visible(False)
|
||||
self.canvas.draw()
|
||||
self.img_background = self.canvas.copy_from_bbox(self.ax.bbox)
|
||||
# Redraw canvas artists
|
||||
self.set_visible(True)
|
||||
self._draw_artists()
|
||||
|
||||
|
||||
class ToolHandles(object):
|
||||
"""Control handles for canvas tools.
|
||||
|
||||
@@ -105,6 +105,12 @@ class FigureCanvas(FigureCanvasQTAgg):
|
||||
QtGui.QSizePolicy.Expanding)
|
||||
FigureCanvasQTAgg.updateGeometry(self)
|
||||
|
||||
def resizeEvent(self, event):
|
||||
FigureCanvasQTAgg.resizeEvent(self, event)
|
||||
# Call to `resize_event` missing in FigureManagerQT.
|
||||
# See https://github.com/matplotlib/matplotlib/pull/1585
|
||||
self.resize_event()
|
||||
|
||||
#TODO: Consider overriding Matplotlib key-event handling
|
||||
# def keyPressEvent(self, event):
|
||||
# # Override key events defined by Matplotlib
|
||||
|
||||
Reference in New Issue
Block a user