Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa58552

Browse files
committed
Had to explicitly remove previous bitmap image reps
svn path=/trunk/matplotlib/; revision=1494
1 parent 855fc89 commit fa58552

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

lib/matplotlib/backends/backend_cocoaagg.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from backend_agg import FigureCanvasAgg
3030
import pylab
3131

32-
DEBUG = True
32+
DEBUG = False
3333

3434
mplBundle = NSBundle.bundleWithPath_(matplotlib.get_data_path())
3535

@@ -62,44 +62,41 @@ def awakeFromNib(self):
6262
self.plotWindow.plotView = self.plotView
6363
self.plotView.canvas = self.canvas
6464

65+
self.plotWindow.setAcceptsMouseMovedEvents_(True)
66+
self.plotWindow.makeKeyAndOrderFront_(self)
67+
self.plotWindow.setDelegate_(self.plotWindow)
68+
69+
self.plotView.setImageFrameStyle_(NSImageFrameGroove)
70+
self.plotView.image = NSImage.alloc().initWithSize_((0,0))
71+
self.plotView.setImage_(self.plotView.image)
72+
6573
# Make imageview first responder for key events
6674
self.plotWindow.makeFirstResponder_(self.plotView)
6775

68-
# Issue a resize to update plot
76+
# Force the first update
6977
self.plotWindow.windowDidResize_(self)
7078

7179
def saveFigure_(self, sender):
72-
pass
73-
74-
def quit_(self, sender):
75-
pass
80+
if DEBUG: print >>sys.stderr, 'saveFigure_'
7681

7782
class PlotWindow(NibClassBuilder.AutoBaseClass):
78-
def awakeFromNib(self):
79-
if DEBUG: print 'PlotWindow awakeFromNib'
80-
self.setAcceptsMouseMovedEvents_(True)
81-
self.useOptimizedDrawing_(True)
82-
self.makeKeyAndOrderFront_(self)
83-
self.setDelegate_(self)
84-
8583
def windowDidResize_(self, sender):
8684
w,h = self.plotView.bounds().size
8785
dpi = self.plotView.canvas.figure.dpi.get()
8886
self.plotView.canvas.figure.set_figsize_inches(w / dpi, h / dpi)
8987
self.plotView.updatePlot()
9088

9189
class PlotView(NibClassBuilder.AutoBaseClass):
92-
def awakeFromNib(self):
93-
if DEBUG: print 'PlotView awakeFromNib'
94-
self.setImageFrameStyle_(NSImageFrameGroove)
95-
9690
def updatePlot(self):
9791
self.canvas.draw() # tell the agg to render
9892

9993
w,h = self.canvas.get_width_height()
100-
101-
image = NSImage.alloc().initWithSize_((w,h))
102-
brep = NSBitmapImageRep.alloc().initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_(
94+
95+
if (hasattr(self, 'brep')):
96+
self.image.removeRepresentation_(self.brep)
97+
self.image.setSize_((w,h))
98+
99+
self.brep = NSBitmapImageRep.alloc().initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_(
103100
(self.canvas.buffer_rgba(),'','','',''), # Image data
104101
w, # width
105102
h, # height
@@ -111,8 +108,7 @@ def updatePlot(self):
111108
w*4, # row bytes
112109
32) # bits per pixel
113110

114-
image.addRepresentation_(brep)
115-
self.setImage_(image)
111+
self.image.addRepresentation_(self.brep)
116112
self.setNeedsDisplay_(True)
117113

118114
def mouseDown_(self, event):

0 commit comments

Comments
 (0)