diff --git a/examples/kv/slider.kv b/examples/kv/slider.kv new file mode 100644 index 000000000..b105e0f06 --- /dev/null +++ b/examples/kv/slider.kv @@ -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 diff --git a/examples/svg/parse.py b/examples/svg/parse.py new file mode 100644 index 000000000..2a7d858bc --- /dev/null +++ b/examples/svg/parse.py @@ -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 + diff --git a/examples/svg/test.svg b/examples/svg/test.svg new file mode 100644 index 000000000..db95f5c1f --- /dev/null +++ b/examples/svg/test.svg @@ -0,0 +1,35 @@ + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/examples/test.svg b/examples/test.svg new file mode 100644 index 000000000..db95f5c1f --- /dev/null +++ b/examples/test.svg @@ -0,0 +1,35 @@ + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/kivy/data/style.kv b/kivy/data/style.kv index 294771d0a..586efceaa 100644 --- a/kivy/data/style.kv +++ b/kivy/data/style.kv @@ -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. diff --git a/kivy/uix/svg.py b/kivy/uix/svg.py new file mode 100644 index 000000000..ddced7891 --- /dev/null +++ b/kivy/uix/svg.py @@ -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) + +