My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python

from __future__ import division

from os import listdir
from os.path import isfile, join
import sys
from random import uniform

from pyglet import app, clock
from pyglet.event import EVENT_HANDLED
from pyglet.window import key, Window
from pyglet.gl import (
glClear, glClearColor, glLoadIdentity, glMatrixMode, gluLookAt,
GL_COLOR_BUFFER_BIT, GL_MODELVIEW, GL_PROJECTION, GL_TRIANGLES
)
from pyglet.gl.glu import gluOrtho2D

from svgbatch import SvgBatch


class SvgFiles(object):

def __init__(self):
self.filenames = self.get_filenames(join('svgbatch', 'testdata'))
if len(self.filenames) == 0:
raise Exception('no testdata svg files found')

self.number = -1
self.current = None
self.next()

def get_filenames(self, path):
return [
join(path, filename)
for filename in listdir(path)
if filename.endswith('.svg')
]

def next(self):
self.number = (self.number + 1) % len(self.filenames)
filename = self.filenames[self.number]
print filename
self.current = SvgBatch(filename)
self.current.create_batch()

glClearColor(
uniform(0.0, 1.0),
uniform(0.0, 1.0),
uniform(0.0, 1.0),
1.0)

def draw(self):
self.current.create_batch().draw()



class PygletApp(object):

def __init__(self):
self.window = Window(visible=False, fullscreen=False)
self.window.on_resize = self.on_resize
self.window.on_draw = self.on_draw
self.window.on_key_press = self.on_key_press

self.files = SvgFiles()

glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(
0.0, -0.0, 1.0, # eye
0.0, -0.0, -1.0, # lookAt
0.0, 1.0, 0.0) # up


def on_draw(self):
glClear(GL_COLOR_BUFFER_BIT)
self.files.draw()
return EVENT_HANDLED


def on_resize(self, width, height):
# scale is distance from screen centre to top or bottom, in world coords
scale = 110
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
aspect = width / height
gluOrtho2D(
-scale * aspect,
+scale * aspect,
-scale,
+scale)
return EVENT_HANDLED


def on_key_press(self, symbol, modifiers):
if symbol == key.ESCAPE:
self.window.close()
return
self.files.next()


def run(self):
self.window.set_visible()
app.run()



def main():
app = PygletApp()
app.run()


if __name__ == '__main__':
main()

Change log

r46 by tartley on Aug 7, 2009   Diff
v0.1.6
+ include demo.py and testdata in the
source distribution
+ move demo.py and testdata inside
svgbatch
Go to: 
Project members, sign in to write a code review

Older revisions

r34 by tartley on Aug 4, 2009   Diff
+ Major overhaul of parsing svg path d
attribute. Designed to make it easier
to handle real-world variations in svg
data (eg. missing spaces, commas or
spaces, implied repeated commands,
...
r31 by tartley on Jul 23, 2009   Diff
change package name from svgload to
svgbatch
r30 by tartley on Jul 20, 2009   Diff
SvgBatch now exposes paths, indexable
by id
All revisions of this file

File info

Size: 2686 bytes, 116 lines

File properties

svn:executable
*
Powered by Google Project Hosting