def __init__(self, **kwargs): super(SvgWidget, self).__init__(**kwargs) with self.canvas: self.scale = Scale(1, 1, 1) self.svg = Svg(kwargs['filename']) self.bind(size=self._do_scale)
def start(self, evt): with self.canvas.before: self.gradients = [[1, 0, 0, 1], [0, 0, 1, 1]] self.color = Color(1, 0, 0, 1) self.scale = Scale(1, 1, 1) self.svg = Svg(self.source) self.bind(size=self._do_scale) self.size = self.svg.width, self.svg.height
def kivy_svg(self): """An SVG object. :return: an SVG object :rtype: kivy.graphics.svg.Svg :raises ImportError: if the module was not found """ from kivy.graphics.svg import Svg path = self.temporary_path(".svg") try: return Svg(path) finally: remove_file(path)
def __init__(self, **kwargs): super(SvgRoundGauge, self).__init__(**kwargs) self.mask_rotations=[] size = self.height if self.height < self.width else self.width gauge_height = size / self.gauge_height x_center = self.pos[0] + self.width / 2 - self.gauge_width / 2 y_center = self.pos[1] + self.height / 2 - self.gauge_height / 2 with self.canvas: PushMatrix() self.gauge_translate=Translate(x_center, y_center, 0) self.gauge_scale=Scale(x=gauge_height, y=gauge_height) self.dial = Svg('resource/gauge/round_gauge_270.svg', bezier_points=1, circle_points=1,color=[1,1,1,1]) Translate(0, self.mask_offset) PushMatrix() self.mask_rotations.append(Rotate(angle=-135, axis=(0,0,1), origin=(self.center[0], self.center[1]))) Svg('resource/gauge/gauge_mask.svg') PopMatrix() PushMatrix() self.mask_rotations.append(Rotate(angle=-225, axis=(0,0,1), origin=(self.center[0], self.center[1]))) Svg('resource/gauge/gauge_mask.svg') PopMatrix() PushMatrix() self.mask_rotations.append(Rotate(angle=-315, axis=(0,0,1), origin=(self.center[0], self.center[1]))) Svg('resource/gauge/gauge_mask.svg') PopMatrix() PopMatrix() with self.canvas.after: PushMatrix() self.shadow_translate=Translate(x_center, y_center, 0) self.shadow_scale=Scale(x=gauge_height, y=gauge_height) Svg('resource/gauge/round_gauge_270_shadow.svg', bezier_points=1, circle_points=1) PopMatrix() self.bind(pos=self.update_all, size=self.update_all)
def __init__(self, filename): super(SvgWidget, self).__init__() with self.canvas: svg = Svg(filename) self.size = svg.width, svg.height
from kivy.core.window import Window from kivy.graphics.svg import Svg from time import time import sys import os filename = sys.argv[1] if "PROFILE" in os.environ: import pstats, cProfile cProfile.runctx("Svg(filename)", globals(), locals(), "Profile.prof") s = pstats.Stats("Profile.prof") s.sort_stats("time").print_callers() else: print("Loading {}".format(filename)) start = time() svg = Svg(filename) end = time() print("Loaded in {:.2f}s".format((end - start)))
def __init__(self, filename, **kwargs): super(SvgWidget, self).__init__(**kwargs) with self.canvas: svg = Svg(filename) self.size = 10000, 10000
def on_source(self, instance, value): self.canvas.clear() with self.canvas: svg = Svg(value) self.size = svg.width, svg.height
from kivy.graphics.svg import Svg with widget.canvas: svg = Svg("image.svg")