def rect(): gc = GraphicsContext((500, 500)) gc.clear() gc.rect(100, 100, 300, 300) gc.draw_path() with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file(fid.name, resist_width="weak", resist_height="weak") return image
def simple(): gc = GraphicsContext((100, 100)) gc.clear() gc.set_line_cap(constants.CAP_SQUARE) gc.set_line_join(constants.JOIN_MITER) gc.set_stroke_color((1, 0, 0)) gc.set_fill_color((0, 0, 1)) gc.rect(0, 0, 30, 30) gc.draw_path() with tempfile.NamedTemporaryFile(suffix=".bmp") as fid: gc.save(fid.name) image = Image.from_file( fid.name, resist_width="weak", resist_height="weak" ) return image
def create_mock_gc(self, width, height, methods=()): """ Create an image graphics context that with mocked methods. Parameters ---------- width, height : The size of the graphics context canvas. methods : iterable the methods which are going to be mocked with a Mock object. """ gc = GraphicsContext((int(width), int(height))) gc.clear((0.0, 0.0, 0.0, 0.0)) for method in methods: setattr(gc, method, Mock()) return gc
def create_mock_gc( self, width, height, methods=()): """ Create an image graphics context that with mocked methods. Parameters ---------- width, height : The size of the graphics context canvas. methods : iterable the methods which are going to be mocked with a Mock object. """ gc = GraphicsContext((int(width), int(height))) gc.clear((0.0, 0.0, 0.0, 0.0)) for method in methods: setattr(gc, method, Mock()) return gc
from kiva import constants from kiva.image import GraphicsContext gc = GraphicsContext((100,100)) gc.clear() gc.set_line_cap(constants.CAP_SQUARE) gc.set_line_join(constants.JOIN_MITER) gc.set_stroke_color((1,0,0)) gc.set_fill_color((0,0,1)) gc.rect(0, 0, 30, 30) gc.draw_path() gc.save("simple.bmp")
from kiva import constants from kiva.image import GraphicsContext gc = GraphicsContext((100, 100)) gc.clear() gc.set_line_cap(constants.CAP_SQUARE) gc.set_line_join(constants.JOIN_MITER) gc.set_stroke_color((1, 0, 0)) gc.set_fill_color((0, 0, 1)) gc.rect(0, 0, 30, 30) gc.draw_path() gc.save("simple.bmp")