Warning
This is highly experimental and subject to change. Don’t use it in production.
from kivy.app import App
from kivy.lang import Builder
from kivy.graphics.svg import Svg
from kivy.uix.widget import Widget
from kivy.properties import StringProperty
from kivy.graphics import Scale
kv = """
#:import Svg kivy.graphics.svg.Svg
GridLayout:
cols: 2
rows: 2
id: grid
BoxLayout:
id:box
Label:
text: 'Test'
Label:
text: 'Test'
Label:
text: 'Test'
"""
class SvgWidget(Widget):
filename = StringProperty()
def __init__(self, **kwargs):
f = kwargs.pop('filename')
super().__init__(**kwargs)
with self.canvas:
self.scale = Scale(1, 1, 1)
self.svg = Svg(f)
self.bind(size=self._do_resize)
self.bind(pos=self._do_position)
def _do_position(self, *args):
# self.svg.anchor_x = self.x
#self.svg.anchor_y = self.y
print(dir(self.svg))
#print(self.svg.anchor_y)
def _do_resize(self, *args):
self.scale.xyz = (self.width / self.svg.width, self.height / self.svg.height, 1)
class TestSvgApp(App):
def build(self):
return Builder.load_string(kv)
def on_start(self):
s = SvgWidget(filename='acid.svg')
self.root.ids.box.add_widget(s)
TestSvgApp().run()