shashi278 / svg-anim-kivy Goto Github PK
View Code? Open in Web Editor NEWSVG path drawing and animation support in kivy application
License: MIT License
SVG path drawing and animation support in kivy application
License: MIT License
Hi there, thanks for this life-saver, I am however having a rather puzzling issue, when I try this package with SVGs in the demo folder, everything works great but as soon as I use my own SVG files, nothing is rendered, as in there is no error that comes up but in the UI there is literally nothing being rendered. To Test, please use these svg files
When you click on so.svg
or text.svg
it crashes with the error AttributeError: 'Kivg' object has no attribute 'closed_shapes'
traceback:
Traceback (most recent call last):
File "/usr/quick-tests/svg-anim-kivy/demo/main.py", line 155, in <module>
KivgDemo().run()
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivy/app.py", line 956, in run
runTouchApp()
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivy/base.py", line 574, in runTouchApp
EventLoop.mainloop()
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivy/base.py", line 339, in mainloop
self.idle()
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivy/base.py", line 383, in idle
self.dispatch_input()
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivy/base.py", line 334, in dispatch_input
post_dispatch_input(*pop(0))
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivy/base.py", line 302, in post_dispatch_input
wid.dispatch('on_touch_up', me)
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivy/uix/behaviors/button.py", line 179, in on_touch_up
self.dispatch('on_release')
File "kivy/_event.pyx", line 727, in kivy._event.EventDispatcher.dispatch
File "kivy/_event.pyx", line 1307, in kivy._event.EventObservers.dispatch
File "kivy/_event.pyx", line 1191, in kivy._event.EventObservers._dispatch
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivy/lang/builder.py", line 60, in custom_callback
exec(__kvlang__.co_value, idmap)
File "<string>", line 65, in <module>
File "/usr/quick-tests/svg-anim-kivy/demo/main.py", line 146, in shape_animate
self.s.shape_animate(svg_file, anim_config_list=eval(config), on_complete=self.completed)
File "/usr/quick-tests/svg-anim-kivy/demo/kivg/main.py", line 93, in shape_animate
anim_list = self._shape_animate(
^^^^^^^^^^^^^^^^^^^^
File "/usr/quick-tests/svg-anim-kivy/demo/kivg/main.py", line 132, in _shape_animate
if self.closed_shapes.get(id_, None):
^^^^^^^^^^^^^^^^^^
AttributeError: 'Kivg' object has no attribute 'closed_shapes'
run the app
kivy.svg
pie_chart.svg
It gives the error: KeyError: 'neck
run the app
pie_chart.svg
It gives the same error as #8
Exception in thread Thread-1 (show_button_icon):
Traceback (most recent call last):
File "/usr/.pyenv/versions/3.11.6/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
self.run()
File "/usr/.pyenv/versions/3.11.6/lib/python3.11/threading.py", line 982, in run
self._target(*self._args, **self._kwargs)
File "/usr/quick-tests/svg-anim-kivy/demo/main.py", line 90, in show_button_icon
self.draw_filled(s, b.svg_icon)
File "/usr/quick-tests/svg-anim-kivy/demo/main.py", line 93, in draw_filled
s.draw(icon)
File "/usr/quick-tests/svg-anim-kivy/.venv/lib/python3.11/site-packages/kivg/main.py", line 455, in draw
self.b.canvas.clear()
File "kivy/graphics/instructions.pyx", line 630, in kivy.graphics.instructions.Canvas.clear
File "kivy/graphics/instructions.pyx", line 638, in kivy.graphics.instructions.Canvas.clear
File "kivy/graphics/instructions.pyx", line 674, in kivy.graphics.instructions.Canvas.remove
File "kivy/graphics/instructions.pyx", line 88, in kivy.graphics.instructions.Instruction.flag_data_update
TypeError: Cannot change graphics instruction outside the main Kivy thread
Using this svg here:
<svg width="1543" height="575" viewBox="0 0 1543 575" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M699.103 63.8921C927.9 62.235 1159.28 -38.598 1350.47 16.3971C1545.67 72.5449 1567.52 200.866 1524.44 301.298C1487.02 388.509 1306.31 442.57 1144.63 496.169C1011.93 540.162 865.54 577.105 699.103 574.907C537.236 572.769 390.169 536.533 279.692 484.744C173.21 434.828 146.157 368.232 115.431 301.298C72.3292 207.404 -91.3811 90.8952 68.9567 25.6785C230.39 -39.9836 478.685 65.4885 699.103 63.8921Z" fill="#F4B65B"/>
</svg>
On React Native it looks like this:
import WelcomeSplash from '@/assets/welcome_splash.svg'
export default function WelcomeScreen1() {
return (
<WelcomeSplash />
)
}
using Kivg
, it looks like this:
from kivg import Kivg
from kivy.app import App
from kivy.factory import Factory as F
from kivy.lang import Builder
kv = Builder.load_string(
"""
<MainScreen@Screen>:
box: box
BoxLayout:
id: box
canvas.before:
Color:
rgba: .5, .5, 0, 1
Rectangle:
pos: self.pos
size: self.size
"""
)
class MainApp(App):
def build(self):
main_screen = F.MainScreen()
self.s = Kivg(main_screen.box)
self.s.draw(
"welcome_splash.svg",
fill=True,
animate=True,
anim_type="seq",
line_width=1,
)
return main_screen
MainApp().run()
It seems the rendered size is not width="1543" height="575"
as the original svg file
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.