Skip to content

Commit bbb8a55

Browse files
author
Steve Chaplin
committed
SC 2005/03/15
svn path=/trunk/matplotlib/; revision=1077
1 parent 9a0c184 commit bbb8a55

File tree

4 files changed

+54
-57
lines changed

4 files changed

+54
-57
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
New entries should be added at the top
22

3+
2005-03-15 backend_gtkagg.py: changed to use double buffering, this fixes
4+
the problem reported Joachim Berdal Haga - "Parts of plot lagging
5+
from previous frame in animation". Tested with anim.py and it makes
6+
no noticable difference to performance (23.7 before, 23.6 after)
7+
- SC
8+
39
2005-03-14 add src/_backend_gdk.c extension to provide a substitute function
410
for pixbuf.get_pixels_array(). Currently pixbuf.get_pixels_array()
511
only works with Numeric, and then only works if pygtk has been

lib/matplotlib/backends/backend_cairo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def draw_markers(self, gc, path, rgbFace, x, y, transform):
224224

225225
path_list = [path.vertex() for i in range(path.total_vertices())]
226226

227-
def generate_path (path):
227+
def generate_path (path_list):
228228
for code, xp, yp in path_list:
229229
if code == agg.path_cmd_move_to:
230230
ctx.move_to (xp, -yp)
@@ -237,8 +237,8 @@ def generate_path (path):
237237
ctx.save()
238238
ctx.new_path()
239239
ctx.translate(x, self.height - y)
240-
generate_path (path)
241-
240+
generate_path (path_list)
241+
242242
if rgbFace:
243243
ctx.save()
244244
ctx.set_rgb_color (*rgbFace)

lib/matplotlib/backends/backend_gtk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def _renderer_init(self):
216216

217217

218218
def _render_figure(self, width, height):
219-
"""Render the figure to a gdk.Pixmap, is used for
219+
"""Render the figure to a gdk.Pixmap, used by expose_event().
220+
Is used for
220221
- rendering the pixmap to display (pylab.draw)
221222
- rendering the pixmap to save to a file (pylab.savefig)
222223
Should not be overridden by GTK backends
@@ -262,7 +263,6 @@ def expose_event(self, widget, event):
262263
width, height = self.allocation.width, self.allocation.height
263264
self._render_figure(width, height)
264265

265-
#return True
266266
return False # allow signal to propagate further
267267

268268

lib/matplotlib/backends/backend_gtkagg.py

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"""
44
from __future__ import division
55

6-
import os, sys
7-
from matplotlib import verbose
8-
from matplotlib.cbook import enumerate
6+
import os
97
from matplotlib.figure import Figure
108

119
from backend_agg import FigureCanvasAgg
@@ -16,7 +14,7 @@
1614
from _gtkagg import agg_to_gtk_drawable
1715

1816

19-
DEBUG = 0
17+
DEBUG = False
2018

2119

2220
def new_figure_manager(num, *args, **kwargs):
@@ -28,26 +26,53 @@ def new_figure_manager(num, *args, **kwargs):
2826
canvas = FigureCanvasGTKAgg(thisFig)
2927
return FigureManagerGTK(canvas, num)
3028

29+
3130
class FigureCanvasGTKAgg(FigureCanvasGTK, FigureCanvasAgg):
3231

33-
def draw(self):
34-
"""
35-
Draw to the Agg backend and then copy the image to the
36-
gtk.gdk.drawable.
32+
def configure_event(self, widget, event=None):
33+
if DEBUG: print 'FigureCanvasGTKAgg.configure_event'
34+
if widget.window is None:
35+
return
36+
try:
37+
del self.renderer
38+
except AttributeError:
39+
pass
40+
w,h = widget.window.get_size()
41+
if w==1 or h==1: return # empty fig
42+
43+
# compute desired figure size in inches
44+
dpival = self.figure.dpi.get()
45+
winch = w/dpival
46+
hinch = h/dpival
47+
self.figure.set_figsize_inches(winch, hinch)
48+
self._draw_pixmap = True
49+
50+
if DEBUG: print 'FigureCanvasGTKAgg.configure_event end'
51+
return True
52+
3753

54+
def _render_figure(self, width, height):
55+
"""Render the figure to a gdk.Pixmap, used by expose_event().
3856
"""
39-
if DEBUG: print 'FigureCanvasGTKAgg.draw'
40-
57+
if DEBUG: print 'FigureCanvasGTKAgg._render_figure'
58+
create_pixmap = False
59+
if width > self._pixmap_width:
60+
# increase the pixmap in 10%+ (rather than 1 pixel) steps
61+
self._pixmap_width = max (int (self._pixmap_width * 1.1), width)
62+
create_pixmap = True
63+
64+
if height > self._pixmap_height:
65+
self._pixmap_height = max (int (self._pixmap_height * 1.1), height)
66+
create_pixmap = True
67+
68+
if create_pixmap:
69+
if DEBUG: print 'FigureCanvasGTK._render_figure new pixmap'
70+
self._pixmap = gtk.gdk.Pixmap (self.window, self._pixmap_width,
71+
self._pixmap_height)
72+
4173
FigureCanvasAgg.draw(self)
42-
if self.window is None:
43-
return
44-
else:
45-
self.blit()
46-
74+
agg_to_gtk_drawable(self._pixmap, self.renderer._renderer)
4775

48-
def blit(self):
49-
if self.window is None: return
50-
agg_to_gtk_drawable(self.window, self.renderer._renderer)
5176

5277
def print_figure(self, filename, dpi=150,
5378
facecolor='w', edgecolor='w',
@@ -68,37 +93,3 @@ def print_figure(self, filename, dpi=150,
6893
error_msg_gtk('Failed to save\nError message: %s'%(msg,), self)
6994

7095
self.figure.set_canvas(self)
71-
72-
73-
def configure_event(self, widget, event=None):
74-
if DEBUG: print 'FigureCanvasGTKAgg.configure_event'
75-
if widget.window is None: return
76-
try: del self.renderer
77-
except AttributeError: pass
78-
w,h = widget.window.get_size()
79-
if w==1 or h==1: return # empty fig
80-
81-
# compute desired figure size in inches
82-
dpival = self.figure.dpi.get()
83-
winch = w/dpival
84-
hinch = h/dpival
85-
86-
self.figure.set_figsize_inches(winch, hinch)
87-
88-
return gtk.TRUE
89-
90-
def expose_event(self, widget, event):
91-
if DEBUG: print 'FigureCanvasGTKAgg.expose_event'
92-
if widget.window is None: return
93-
94-
def callback(w):
95-
if hasattr(self, 'renderer'): self.blit()
96-
else: self.draw()
97-
self._idleID=0
98-
return gtk.FALSE
99-
100-
if self._idleID==0:
101-
self._idleID = gtk.idle_add(callback, self)
102-
103-
104-
return gtk.TRUE

0 commit comments

Comments
 (0)