13 |
|
|
14 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
15 |
|
|
16 |
|
# fix for people using python2.1 |
17 |
|
from __future__ import nested_scopes |
18 |
|
|
19 |
import os |
import os |
20 |
import string |
import string |
21 |
|
|
103 |
|
|
104 |
def write_attribs(self, attrs): |
def write_attribs(self, attrs): |
105 |
for name, value in attrs.items(): |
for name, value in attrs.items(): |
106 |
self.file.write(' %s="%s"' % (escape(name), value)) |
self.file.write(' %s="%s"' % (escape(name), escape(value))) |
107 |
|
|
108 |
def open_element(self, element, attrs = {}): |
def open_element(self, element, attrs = {}): |
109 |
|
|
243 |
|
|
244 |
# just playing now with lambdas and dictionaries |
# just playing now with lambdas and dictionaries |
245 |
|
|
246 |
types = {ClassData.DEFAULT: |
types = [[lambda p: 'clnull', |
247 |
[lambda p: 'clnull', |
lambda p: 'clnull'], |
248 |
lambda p: 'clnull'], |
[lambda p: 'clpoint value="%s"' % |
249 |
ClassData.POINT: |
str(p.GetValue()), |
250 |
[lambda p: 'clpoint value="%s"' % |
lambda p: 'clpoint'], |
251 |
str(p.GetValue()), |
[lambda p: 'clrange min="%s" max="%s"' % |
252 |
lambda p: 'clpoint'], |
(str(p.GetMin()), |
253 |
ClassData.RANGE: |
(str(p.GetMax()))), |
254 |
[lambda p: 'clrange min="%s" max="%s"' % |
lambda p: 'clrange']] |
255 |
(str(p.GetMin()), |
|
256 |
(str(p.GetMax()))), |
def write_class_group(group): |
257 |
lambda p: 'clrange']} |
type = -1 |
258 |
|
if isinstance(group, ClassGroupDefault): type = 0 |
259 |
def write_class_data(data): |
elif isinstance(group, ClassGroupSingleton): type = 1 |
260 |
dict = {'stroke' : data.GetStroke().hex(), |
elif isinstance(group, ClassGroupRange): type = 2 |
261 |
'stroke_width': str(data.GetStrokeWidth()), |
elif isinstance(group, ClassGroupMap): type = 3 |
262 |
'fill' : data.GetFill().hex()} |
assert(type >= 0) |
263 |
t = data.GetType() |
|
264 |
self.open_element(types[t][0](data)) |
if type <= 2: |
265 |
self.write_element("cldata", dict) |
data = group.GetProperties() |
266 |
self.close_element(types[t][1](data)) |
dict = {'stroke' : data.GetStroke().hex(), |
267 |
|
'stroke_width': str(data.GetStrokeWidth()), |
268 |
|
'fill' : data.GetFill().hex()} |
269 |
|
|
270 |
|
self.open_element(types[type][0](group)) |
271 |
|
self.write_element("cldata", dict) |
272 |
|
self.close_element(types[type][1](group)) |
273 |
|
else: pass # XXX: we need to handle maps |
274 |
|
|
275 |
for i in lc: |
for i in lc: |
276 |
write_class_data(i) |
write_class_group(i) |
277 |
|
|
278 |
# for i in lc: |
# for i in lc: |
279 |
# t = i.GetType() |
# t = i.GetType() |