mirror of https://github.com/kivy/kivy.git
fix svg commit. should have done branch...will do next time ;P
This commit is contained in:
parent
f2d3629cae
commit
8768333a64
|
@ -0,0 +1,26 @@
|
|||
maybe something like this for data binding? List can be just python class
|
||||
|
||||
|
||||
Beer:
|
||||
id: 'beer_template'
|
||||
canvas: #maybe use SVG with ${image}, ${name} etc
|
||||
Image:
|
||||
source: self.data['image']
|
||||
Text:
|
||||
text: self.data['name']
|
||||
font-size: 2em
|
||||
pos: (self.top, self.center[1])
|
||||
Text:
|
||||
text: self.data['desc']
|
||||
pos: self.pos
|
||||
size: (self.width, self.height/2)
|
||||
|
||||
List:
|
||||
Script:
|
||||
for beer in open(self.data):
|
||||
self.add_widget( beer_template.__class__(data=beer) )
|
||||
|
||||
Widget:
|
||||
List:
|
||||
data: "http://mydb/beers"
|
||||
class: Beer
|
|
@ -0,0 +1,43 @@
|
|||
from xml.dom.minidom import parse
|
||||
from pprint import pprint
|
||||
|
||||
doc = parse('test.svg')
|
||||
root = doc.documentElement
|
||||
|
||||
path = root.getElementsByTagName("path")[0]
|
||||
attribs = dict(path.attributes.items())
|
||||
|
||||
svg_data = attribs['d']
|
||||
path = []
|
||||
|
||||
|
||||
state = {}
|
||||
origin = (0,0)
|
||||
position = None
|
||||
for command in svg_data.split(' '):
|
||||
|
||||
if command.isalpha():
|
||||
if command.isupper():
|
||||
origin = (0,0)
|
||||
else:
|
||||
origin = position
|
||||
|
||||
if command == 'M':
|
||||
PathStart()
|
||||
state['command'] = PathLineTo
|
||||
|
||||
elif command == 'c':
|
||||
state['command'] = "PathLineTo" #"PathRCubicTo"
|
||||
|
||||
elif command == 'z':
|
||||
path.append('PathClose')
|
||||
|
||||
else:
|
||||
pos = map(float, command.split(','))
|
||||
position = pos[0]+origin[0], pos[1]+origin[1]
|
||||
path.append( state['command']+ str(position))
|
||||
|
||||
|
||||
for instr in path:
|
||||
print instr
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.1"
|
||||
width="744.09448"
|
||||
height="1052.3622"
|
||||
id="svg2">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="layer1">
|
||||
<path
|
||||
d="M 314.28572,832.36218 311.42857,1040.9336 22.857147,1038.0765 C 22.857147,1038.0765 22.857141,829.50504 314.28572,832.36218 z"
|
||||
id="path3778"
|
||||
style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.0 KiB |
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.1"
|
||||
width="744.09448"
|
||||
height="1052.3622"
|
||||
id="svg2">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="layer1">
|
||||
<path
|
||||
d="M 314.28572,832.36218 311.42857,1040.9336 22.857147,1038.0765 C 22.857147,1038.0765 22.857141,829.50504 314.28572,832.36218 z"
|
||||
id="path3778"
|
||||
style="fill:#ff0000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.0 KiB |
|
@ -13,10 +13,6 @@
|
|||
Color:
|
||||
rgb: (1, 1, 1)
|
||||
Rectangle:
|
||||
|
||||
241f47f5:w
|
||||
27-3018-110810-m8-08-00-des-iow
|
||||
|
||||
texture: self.texture
|
||||
size: self.texture_size
|
||||
pos: root.center[0] - self.texture_size[0] / 2., root.center[1] - self.texture_size[1] / 2.
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
|
||||
'''
|
||||
SVG widget
|
||||
'''
|
||||
|
||||
__all__ = ('SVG', )
|
||||
|
||||
from xml.dom.minidom import parse
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.resources import resource_find
|
||||
from kivy.c_ext.properties import StringProperty, ObjectProperty, ListProperty
|
||||
from kivy.c_ext.graphics import *
|
||||
|
||||
def t(*args):
|
||||
print "ASASASAS", args
|
||||
|
||||
class SVG(Widget):
|
||||
|
||||
|
||||
#: Filename of the image
|
||||
fname = StringProperty("")
|
||||
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(SVG, self).__init__()
|
||||
|
||||
|
||||
with self.canvas:
|
||||
|
||||
Color(1,0,0 ,1)
|
||||
doc = parse('examples/test.svg')
|
||||
root = doc.documentElement
|
||||
|
||||
path = root.getElementsByTagName("path")[0]
|
||||
attribs = dict(path.attributes.items())
|
||||
svg_data = attribs['d']
|
||||
|
||||
instruction = ""
|
||||
origin = (0,0)
|
||||
pos = None
|
||||
for command in svg_data.split(' '):
|
||||
if command.isalpha():
|
||||
if command.isupper():
|
||||
origin = (0,0)
|
||||
else:
|
||||
print "setting pos, fpor relative"
|
||||
origin = pos
|
||||
|
||||
instruction = command
|
||||
else:
|
||||
npos = tuple(map(float, command.split(',')))
|
||||
pos = npos
|
||||
x = (origin[0]+ pos[0]) *0.5
|
||||
y = (origin[1]+ pos[1]) *0.5
|
||||
print "####### ", instruction, (x,y)
|
||||
#instruction(x,y)
|
||||
|
||||
|
Loading…
Reference in New Issue