def on_draw(self, widget, cr): DotWidget.on_draw(self, widget, cr) if True: # Cairo screenshot import cairo # Scale to give 96 dpi instead of 72 dpi dpi = 96.0 scale = dpi/72.0 w = int(self.graph.width*scale) h = int(self.graph.height*scale) CAIRO_XMAX = 32767 CAIRO_YMAX = 32767 if w >= CAIRO_XMAX: w = CAIRO_XMAX scale = w/self.graph.width h = int(self.graph.height*scale) if h >= CAIRO_YMAX: h = CAIRO_YMAX scale = h/self.graph.height w = int(self.graph.width*scale) assert w <= CAIRO_XMAX assert h <= CAIRO_YMAX surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) cr = cairo.Context(surface) cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) cr.paint() cr.scale(scale, scale) self.graph.draw(cr, highlight_items=self.highlight) surface.write_to_png(self.name + '.png') if False: # GTK 3 screenshot window = self.get_window() w = window.get_width() h = window.get_height() pixbuf = Gdk.pixbuf_get_from_window(window, 0, 0, w, h) pixbuf.savev(self.name + '.png', 'png', (), ()) Gtk.main_quit()