def __init__(self, width, height, start_year, end_year, border, space): """Setup the graph with basic preset values.""" if 'self.surface' in locals(): self.surface = cairo.Surface() self.ctx = cairo.Context(self.surface) self.ctx.scale(width, width) self.user_space_dim = self.ctx.device_to_user(width, height) self.ctx.rectangle(border, border, 1 - border, self.user_space_dim[1] - border) self.ctx.clip() self.start_year = start_year self.end_year = end_year self.border = border self.space = space # Variable for storing rectangles of space that is already used self.used_space = []
def test_surface(): # TypeError: The Surface type cannot be instantiated with pytest.raises(TypeError): cairo.Surface() f, w, h = cairo.FORMAT_ARGB32, 100, 100 s = cairo.ImageSurface(f, w, h) assert s.get_format() == f assert s.get_width() == w assert s.get_height() == h f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 s = cairo.PDFSurface(f, w, h) f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 s = cairo.PSSurface(f, w, h) s = cairo.RecordingSurface(cairo.CONTENT_COLOR, None) s = cairo.RecordingSurface(cairo.CONTENT_COLOR, (1, 1, 10, 10)) f, w, h = tfi.TemporaryFile(mode='w+b'), 100, 100 s = cairo.SVGSurface(f, w, h)
def exportMapAs(self, filepath, fileType=".svg"): ''' This method is similar to update_ownUI only that it exports a file it makes a surface as svg instead of wx.dc ''' # create new surface: fo = file(filepath, 'w') width, height = 1000,1000 # set to 1000x1000, can be anything if fileType==".svg": surface = cairo.SVGSurface (fo, width, height) elif fileType==".png": # does not work yet! surface = cairo.Surface (fo, width, height) else: return False ctx = cairo.Context (surface) self.DrawCairo(ctx, (width,height) ) surface.finish() self.update_ownUI() return True
def __new__(cls, *args, **kwargs): import cairo return cairo.Surface(*args, **kwargs)