# HG changeset patch # User Thinker K.F. Li # Date 1297572584 -28800 # Node ID ce19a11657a77273521c24b25ad6552f54edd513 # Parent 9164a0782ba7422f8d92af98b69d0c611a6d5591 Try parsing DOM in html5css3.py try with parser from domview.py diff -r 9164a0782ba7 -r ce19a11657a7 pyink/html5css3.py --- a/pyink/html5css3.py Sun Feb 13 12:33:31 2011 +0800 +++ b/pyink/html5css3.py Sun Feb 13 12:49:44 2011 +0800 @@ -1,7 +1,79 @@ import pybExtension +from domview import component_manager, layers_parser, scenes_parser +from trait import composite + +@composite +class dom_parser(object): + use_traits = (component_manager, layers_parser, scenes_parser) + method_map_traits = { + scenes_parser._find_maxframe: '_find_maxframe', + scenes_parser._collect_all_scenes: '_collect_all_scenes', + scenes_parser._collect_node_ids: '_collect_node_ids', + component_manager._start_component_manager: + '_start_component_manager' + } + + def __init__(self): + self._metadata_node = None + self._scenes_node = None + + self._doc = None + self._root = None + self._layers = [] + self._layers_parent = None + self._maxframe = 0 + self.current = 0 + self._id2node = {} + self._group2scene = {} + pass + + def _find_meta(self): + for child in self._root.childList(): + if child.name() == 'svg:metadata': + self._metadata_node = child + break + pass + else: + raise RuntimeError, 'can not find \'svg:metadata\' node' + + for child in self._metadata_node.childList(): + if child.name() == 'ns0:scenes': + self._scenes_node = child + break + pass + else: + raise RuntimeError, \ + 'can not find \'ns0:scenes\' node under \'svg:metadata\'' + + pass + + def start_handle(self, doc): + self._doc = doc + self._root = doc.root() + self._layers_parent = self._root + + self._find_meta() + + self._collect_node_ids() + self._collect_all_scenes() + + self.parse_all_layers() + + self._start_component_manager() + pass + + def reset(self): + self._layers[:] = [] + self._parse_all_layers() + pass + pass + class html5css3_ext(pybExtension.PYBindExtImp): def save(self, module, doc, filename): + parser = dom_parser() + parser.start_handle(doc.rdoc) + print parser._metadata_node print 'save to ' + filename pass pass