Mercurial > MadButterfly
annotate pyink/html5css3.py @ 1366:dc6591b4079d
Collect functions together
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 04 Mar 2011 11:41:51 +0800 |
parents | aa7cbf2cbf34 |
children | 9d46f2982fa3 |
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 |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
3 from trait import composite, trait, require |
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
|
4 |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
5 |
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
|
6 @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
|
7 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
|
8 use_traits = (component_manager, layers_parser, scenes_parser) |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
9 provide_traits = {layers_parser.get_scene: '_scenes_get_scene'} |
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
|
10 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
|
11 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
|
12 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
|
13 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
|
14 component_manager._start_component_manager: |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
15 '_start_component_manager', |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
16 scenes_parser.get_scene: '_scenes_get_scene' |
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
|
17 } |
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 |
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 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
|
20 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
|
21 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
|
22 |
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._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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 |
1366
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
33 def _find_metadata(self): |
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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 |
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 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 '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
|
50 |
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 pass |
1366
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
52 |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
53 ## \brief Return the range of a scene node. |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
54 # |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
55 @staticmethod |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
56 def _scene_node_range(node): |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
57 start = node.getAttribute('start') |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
58 try: |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
59 end = node.getAttribute('end') |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
60 except: |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
61 end = start |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
62 pass |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
63 try: |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
64 scene_type = node.getAttribute('type') |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
65 except: |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
66 scene_type = 'normal' |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
67 pass |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
68 |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
69 return int(start), int(end), scene_type |
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
|
70 |
1366
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
71 ## \brief To handle the parsing for the given document. |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
72 # |
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 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
|
74 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
|
75 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
|
76 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
|
77 |
1366
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
78 self._find_metadata() |
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
|
79 |
ce19a11657a7
Try parsing DOM in html5css3.py try with parser from domview.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1341
diff
changeset
|
80 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
|
81 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
|
82 |
ce19a11657a7
Try parsing DOM in html5css3.py try with parser from domview.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1341
diff
changeset
|
83 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
|
84 |
ce19a11657a7
Try parsing DOM in html5css3.py try with parser from domview.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1341
diff
changeset
|
85 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
|
86 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
|
87 |
1366
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
88 ## \brief Reset the content of the parser before next parsing. |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
89 # |
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
|
90 def reset(self): |
1354
f92be354ad24
Refactory code to layer_parser.reset_layers()
Thinker K.F. Li <thinker@codemud.net>
parents:
1353
diff
changeset
|
91 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
|
92 pass |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
93 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
94 def get_maxframe(self): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
95 return self._maxframe |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
96 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
97 def _find_scene_node(self, frame_idx, layer_idx): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
98 layer = self._layers[layer_idx] |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
99 for scene_node in layer.scenes: |
1366
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
100 start, end, scene_type = self._scene_node_range(scene_node) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
101 if start <= frame_idx and frame_idx <= end: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
102 return scene_node |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
103 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
104 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
105 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
106 def get_scene(self, frame_idx, layer_idx): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
107 scene_node = self._find_scene_node(frame_idx, layer_idx) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
108 if scene_node: |
1366
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
109 start, end, scene_type = self._scene_node_range(scene_node) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
110 return start, end, scene_type |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
111 return None |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
112 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
113 def get_scene_group(self, frame_idx, layer_idx): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
114 scene_node = self._find_scene_node(frame_idx, layer_idx) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
115 if scene_node: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
116 gid = scene_node.getAttribute('ref') |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
117 scene_group = self.get_node(gid) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
118 return scene_group |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
119 return None |
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
|
120 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
|
121 |
1341
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
122 |
1366
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
123 # |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
124 # Following functions are used to print XML from a DOM-tree. |
dc6591b4079d
Collect functions together
Thinker K.F. Li <thinker@codemud.net>
parents:
1364
diff
changeset
|
125 # |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
126 def _print_level(txt, lvl, out): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
127 indent = ' ' * lvl |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
128 print >> out, '%s%s' % (indent, txt) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
129 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
130 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
131 def _print_node_open(node, lvl, out): |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
132 node_name = node.name() |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
133 if node_name.startswith('svg:'): |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
134 node_name = node_name[4:] |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
135 pass |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
136 |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
137 attrs = [] |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
138 for attrname in node.allAttributes(): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
139 attrvalue = node.getAttribute(attrname) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
140 attr = '%s="%s"' % (attrname, attrvalue) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
141 attrs.append(attr) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
142 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
143 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
144 if attrs: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
145 attrs_str = ' '.join(attrs) |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
146 line = '<%s %s>' % (node_name, attrs_str) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
147 else: |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
148 line = '<%s>' % (node_name) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
149 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
150 _print_level(line, lvl, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
151 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
152 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
153 def _print_node_close(node, lvl, out): |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
154 node_name = node.name() |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
155 if node_name.startswith('svg:'): |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
156 node_name = node_name[4:] |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
157 pass |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
158 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
159 line = '</%s>' % (node_name) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
160 _print_level(line, lvl, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
161 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
162 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
163 def _print_node_single(node, lvl, out): |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
164 node_name = node.name() |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
165 if node_name.startswith('svg:'): |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
166 node_name = node_name[4:] |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
167 pass |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
168 |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
169 attrs = [] |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
170 for attrname in node.allAttributes(): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
171 attrvalue = node.getAttribute(attrname) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
172 attr = '%s="%s"' % (attrname, attrvalue) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
173 attrs.append(attr) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
174 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
175 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
176 if attrs: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
177 attrs_str = ' '.join(attrs) |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
178 line = '<%s %s/>' % (node_name, attrs_str) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
179 else: |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
180 line = '<%s/>' % (node_name) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
181 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
182 _print_level(line, lvl, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
183 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
184 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
185 def _print_node_content(node, lvl, out): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
186 line = node.content() |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
187 _print_level(line, lvl, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
188 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
189 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
190 def _print_subtree(node, lvl, out): |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
191 children = node.childList() |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
192 if not children: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
193 if node.name() != 'string': |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
194 _print_node_single(node, lvl, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
195 else: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
196 _print_node_content(node, lvl, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
197 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
198 return |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
199 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
200 _print_node_open(node, lvl, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
201 for child in children: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
202 _print_subtree(child, lvl + 1, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
203 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
204 _print_node_close(node, lvl, out) |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
205 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
206 |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
207 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
208 ## \brief CSS3 animation code generator. |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
209 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
210 # This trait parses and generate transition code, in CSS3, for two |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
211 # nodes. |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
212 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
213 @trait |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
214 class css3_ani_gen(object): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
215 _parse_ani_attrs = require |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
216 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
217 _passing = lambda name, value: (name, str(value)) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
218 _trans_transform = lambda name, value: \ |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
219 (name, 'matrix(' + ','.join([str(e) for e in value]) + ')') |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
220 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
221 _translators = {'x': _passing, 'y': _passing, |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
222 'width': _passing, 'height': _passing, |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
223 'opacity': _passing, 'transform': _trans_transform |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
224 } |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
225 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
226 del _trans_transform |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
227 del _passing |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
228 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
229 @staticmethod |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
230 def _ani_attr_to_css3(attrname, attrvalue, css): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
231 translator = css3_ani_gen._translators[attrname] |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
232 cssname, cssvalue = translator(attrname, attrvalue) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
233 css[cssname] = cssvalue |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
234 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
235 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
236 def _make_css3_transition(self, node1, node2, duration): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
237 from tween import _normalize_attrs |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
238 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
239 ani_attrs1 = self._parse_ani_attrs(node1) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
240 ani_attrs2 = self._parse_ani_attrs(node2) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
241 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
242 _normalize_attrs(node1, ani_attrs1, node2, ani_attrs2) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
243 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
244 css = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
245 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
246 attrnames = set(ani_attrs1.keys() + ani_attrs2.keys()) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
247 for attrname in attrnames: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
248 attrvalue = ani_attrs2[attrname] |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
249 self._ani_attr_to_css3(attrname, attrvalue, css) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
250 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
251 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
252 properties = css.keys() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
253 css['transition-property'] = ', '.join(properties) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
254 css['transition-duration'] = '%gs' % (duration) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
255 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
256 return css |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
257 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
258 def _write_css(self, selector, css_props, out): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
259 print >> out, '%s {' % (selector) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
260 for prop_name, prop_value in css_props.items(): |
1363
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
261 print >> out, ' %s: %s;' % (prop_name, prop_value) |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
262 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
263 print >> out, '}' |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
264 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
265 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
266 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
267 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
268 @composite |
1341
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
269 class html5css3_ext(pybExtension.PYBindExtImp): |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
270 use_traits = (css3_ani_gen,) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
271 method_map_traits = {css3_ani_gen._make_css3_transition: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
272 '_make_css3_transition', |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
273 css3_ani_gen._write_css: '_write_css' |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
274 } |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
275 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
276 _frame_rate = 12 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
277 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
278 def __init__(self): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
279 self._stylesheet = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
280 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
281 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
282 @staticmethod |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
283 def _parse_ani_attrs(node): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
284 from tween import _parse_attr_ani, _parse_style_ani |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
285 attrs = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
286 _parse_attr_ani(node, attrs) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
287 _parse_style_ani(node, attrs) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
288 return attrs |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
289 |
1341
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
290 def save(self, module, doc, filename): |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
291 import sys |
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
|
292 parser = dom_parser() |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
293 self._parser = parser |
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
|
294 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
|
295 |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
296 self._handle_transition_layers() |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
297 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
298 out = file(filename, 'w+') |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
299 print >> out, '''\ |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
300 <html |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
301 xmlns:dc="http://purl.org/dc/elements/1.1/" |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
302 xmlns:cc="http://creativecommons.org/ns#" |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
303 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
304 xmlns:svg="http://www.w3.org/2000/svg" |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
305 xmlns:xlink="http://www.w3.org/1999/xlink" |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
306 xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
307 xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
308 xmlns:ns0="http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd" |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
309 > |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
310 <head> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
311 <title>Scribboo Test Page</title> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
312 <!-- Style for animation transitions --> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
313 <style type='text/css'>''' |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
314 |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
315 for selector, style in self._stylesheet.items(): |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
316 self._write_css(selector, style, out) |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
317 pass |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
318 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
319 print >> out, '''\ |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
320 </style> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
321 </head> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
322 <body>''' |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
323 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
324 root = doc.rdoc.root() |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
325 _print_subtree(root, 1, out) |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
326 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
327 print >> out, '''\ |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
328 </body> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
329 </html>''' |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
330 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
331 out.close() |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
332 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
333 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
334 ## \brief Find all animation pairs. |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
335 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
336 # An animation pair is two nodes, one from start scene group and |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
337 # another from stop scene group. The node from start scene group |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
338 # will transite to the state of the node from stop scene group. |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
339 # This method is responsible for finding all pairs. |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
340 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
341 @staticmethod |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
342 def _find_transition_pairs(start_scene_group, stop_scene_group): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
343 # Collect all nodes in stop scene |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
344 stop_nodes = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
345 node = stop_scene_group.firstChild() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
346 while node: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
347 try: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
348 node_label = node.getAttribute("ns0:duplicate-src") |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
349 stop_nodes[node_label] = node |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
350 except: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
351 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
352 node = node.next() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
353 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
354 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
355 # Collect all nodes in start scene |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
356 start_nodes = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
357 node = start_scene_group.firstChild() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
358 while node: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
359 try: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
360 node_label = node.getAttribute("id") |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
361 start_nodes[node_label] = node |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
362 except: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
363 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
364 node = node.next() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
365 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
366 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
367 pairs = [] |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
368 for start_node in start_scene_group.childList(): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
369 start_node_id = start_node.getAttribute('id') |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
370 try: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
371 stop_node = stop_nodes[start_node_id] |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
372 except: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
373 stop_node = start_node |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
374 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
375 pairs.append((start_node, stop_node)) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
376 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
377 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
378 return pairs |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
379 |
1363
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
380 def _make_scene_group_style(self, frame_idx, layer_idx): |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
381 scene_group = self._parser.get_scene_group(frame_idx, layer_idx) |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
382 gid = scene_group.getAttribute('id') |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
383 selector = '.frame%04d #%s' % (frame_idx, gid) |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
384 style = {'display': 'inline'} |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
385 self._stylesheet[selector] = style |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
386 pass |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
387 |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
388 def _handle_transition_layer(self, layer_idx): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
389 parser = self._parser |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
390 maxframe = parser.get_maxframe() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
391 stylesheet = self._stylesheet |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
392 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
393 frame_idx = 0 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
394 while frame_idx < maxframe: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
395 scene = parser.get_scene(frame_idx, layer_idx) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
396 if not scene: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
397 frame_idx = frame_idx + 1 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
398 continue |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
399 |
1363
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
400 self._make_scene_group_style(frame_idx, layer_idx) |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
401 |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
402 start, end, tween_type = scene |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
403 if start == end: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
404 frame_idx = frame_idx + 1 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
405 continue |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
406 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
407 next_start = end + 1 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
408 scene = parser.get_scene(next_start, layer_idx) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
409 if not scene: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
410 frame_idx = next_start + 1 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
411 continue |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
412 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
413 scene_group = parser.get_scene_group(start, layer_idx) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
414 next_scene_group = parser.get_scene_group(next_start, layer_idx) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
415 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
416 duration = float(next_start - start) / self._frame_rate |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
417 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
418 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
419 # Generate style for every transition pair |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
420 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
421 transition_pairs = \ |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
422 self._find_transition_pairs(scene_group, next_scene_group) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
423 for start_node, stop_node in transition_pairs: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
424 css_props = self._make_css3_transition(start_node, |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
425 stop_node, |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
426 duration) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
427 node_id = start_node.getAttribute('id') |
1363
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
428 selector = '.frame%04d #%s' % (start, node_id) |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
429 stylesheet[selector] = css_props |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
430 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
431 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
432 frame_idx = next_start |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
433 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
434 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
435 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
436 def _handle_transition_layers(self): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
437 num_layers = self._parser.get_layer_num() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
438 for layer_idx in range(num_layers): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
439 self._handle_transition_layer(layer_idx) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
440 pass |
1341
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
441 pass |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
442 pass |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
443 |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
444 extension = (html5css3_ext(), |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
445 'net.scribboo.html5css3', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
446 'HTML5/CSS3 exporter', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
447 'output', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
448 {'extension': '.html', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
449 'mimetype': 'text/html', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
450 '_filetypename': 'HTML5/CSS3 (*.html)'}) |