comparison pyink/html5css3.py @ 1353:ce19a11657a7

Try parsing DOM in html5css3.py try with parser from domview.py
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 13 Feb 2011 12:49:44 +0800
parents 599b606c4669
children f92be354ad24
comparison
equal deleted inserted replaced
1352:9164a0782ba7 1353:ce19a11657a7
1 import pybExtension 1 import pybExtension
2 from domview import component_manager, layers_parser, scenes_parser
3 from trait import composite
4
5 @composite
6 class dom_parser(object):
7 use_traits = (component_manager, layers_parser, scenes_parser)
8 method_map_traits = {
9 scenes_parser._find_maxframe: '_find_maxframe',
10 scenes_parser._collect_all_scenes: '_collect_all_scenes',
11 scenes_parser._collect_node_ids: '_collect_node_ids',
12 component_manager._start_component_manager:
13 '_start_component_manager'
14 }
15
16 def __init__(self):
17 self._metadata_node = None
18 self._scenes_node = None
19
20 self._doc = None
21 self._root = None
22 self._layers = []
23 self._layers_parent = None
24 self._maxframe = 0
25 self.current = 0
26 self._id2node = {}
27 self._group2scene = {}
28 pass
29
30 def _find_meta(self):
31 for child in self._root.childList():
32 if child.name() == 'svg:metadata':
33 self._metadata_node = child
34 break
35 pass
36 else:
37 raise RuntimeError, 'can not find \'svg:metadata\' node'
38
39 for child in self._metadata_node.childList():
40 if child.name() == 'ns0:scenes':
41 self._scenes_node = child
42 break
43 pass
44 else:
45 raise RuntimeError, \
46 'can not find \'ns0:scenes\' node under \'svg:metadata\''
47
48 pass
49
50 def start_handle(self, doc):
51 self._doc = doc
52 self._root = doc.root()
53 self._layers_parent = self._root
54
55 self._find_meta()
56
57 self._collect_node_ids()
58 self._collect_all_scenes()
59
60 self.parse_all_layers()
61
62 self._start_component_manager()
63 pass
64
65 def reset(self):
66 self._layers[:] = []
67 self._parse_all_layers()
68 pass
69 pass
70
2 71
3 class html5css3_ext(pybExtension.PYBindExtImp): 72 class html5css3_ext(pybExtension.PYBindExtImp):
4 def save(self, module, doc, filename): 73 def save(self, module, doc, filename):
74 parser = dom_parser()
75 parser.start_handle(doc.rdoc)
76 print parser._metadata_node
5 print 'save to ' + filename 77 print 'save to ' + filename
6 pass 78 pass
7 pass 79 pass
8 80
9 extension = (html5css3_ext(), 81 extension = (html5css3_ext(),