annotate pyink/html5css3.py @ 1354:f92be354ad24

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