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
|
#!/usr/bin/python2
# -*- encoding:utf-8 -*-
from xml.dom import minidom
from xml.sax.saxutils import quoteattr
class Leaf(minidom.Element):
def __init__(self, TagName, Text):
minidom.Element.__init__(self, TagName)
t = minidom.Text()
t.data = Text
self.appendChild(t)
class StaticFrame(minidom.Element):
def __init__(self, duration, filename):
minidom.Element.__init__(self, "static")
self.appendChild(Leaf("duration", duration))
self.appendChild(Leaf("file", filename))
class TransitionFrame(minidom.Element):
def __init__(self, duration, ffile, tfile):
minidom.Element.__init__(self, "transition")
self.appendChild(Leaf("duration", duration))
self.appendChild(Leaf("from", ffile))
self.appendChild(Leaf("to", tfile))
class StepFrame():
def __init__(self, duration, transition, ffile, tfile):
self.s = StaticFrame(duration, ffile)
self.t = TransitionFrame(transition, ffile, tfile)
def appendToNode(self, node):
node.appendChild(self.s)
node.appendChild(self.t)
class Header(minidom.Element):
def __init__(self, data={"y":"1990","m":"12","d":"06","hh":"00","mm":"00","ss":"00"}):
minidom.Element.__init__(self, "starttime")
self.appendChild(Leaf("year", data["y"]))
self.appendChild(Leaf("month", data["m"]))
self.appendChild(Leaf("day", data["d"]))
self.appendChild(Leaf("hour", data["hh"]))
self.appendChild(Leaf("minute", data["mm"]))
self.appendChild(Leaf("second", data["ss"]))
class XmlGen():
name = 'nuova_prova'
files = [u'/usr/share/backgrounds/Arboreal_ballet_by_Bob_Farrell.jpg',
u'/usr/share/backgrounds/White_flowers_by_Garuna_bor-bor.jpg']
hold = "1795.0"
transition = "5.0"
xml = 'nuova_prova.xml'
r_xml = 'prova-slideshow.xml'
def makeXml(self):
xmldoc = minidom.Document()
bg = minidom.Element("background")
bg.appendChild(Header())
l = len(self.files)
for i in range(l):
step = StepFrame(self.hold, self.transition, self.files[i], self.files[(i+1)%l])
step.appendToNode(bg)
xmldoc.appendChild(bg)
f = open(self.xml, 'w')
xmldoc.writexml(f, '', '', '', "utf8")
f.close()
print xmldoc.toprettyxml('\t', '\n', "utf8")
def readXml(self):
xmldoc = minidom.parse(self.r_xml)
print xmldoc.toprettyxml('\t', '\n', "utf8")
foo = raw_input()
f_elements = xmldoc.getElementsByTagName('file')
files = map(lambda x: x.firstChild.nodeValue, f_elements)
self.files = files
def test():
prova = XmlGen()
prova.readXml()
print prova.files
prova.makeXml()
|