Mercurial > MadButterfly
annotate pyink/html5css3.py @ 1535:9aff42a7e2b9 tip
Fix issue of add/remove a frame at a scene before all key frames of a layer.
When you added or removed a frame at a scene before all key frames of
a layer, frameline was not updated correctly. It seems nothing
happened, but domview is updated. This changeset fix this issue by
correcting logic for boundary case.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 30 Sep 2011 22:07:28 +0800 |
parents | 9e7ec3b96968 |
children |
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 |
1368
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
123 def _print_subtree(node, lvl, out): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
124 ## \brief Determize whether to skip a node and its descendants. |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
125 # |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
126 # Some part of the tree is useless in the result document. |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
127 # |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
128 def skip(node): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
129 node_name = node.name() |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
130 if node_name == 'svg:metadata': |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
131 return True |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
132 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
133 try: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
134 label = node.getAttribute('inkscape:label') |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
135 except: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
136 return False |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
137 if label == 'dup': |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
138 return True |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
139 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
140 return False |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
141 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
142 ## \brief Last modify style properties before generate output. |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
143 # |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
144 # This is function return a string that will be written out as |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
145 # value of style attribute. |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
146 # |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
147 def filter_style(node): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
148 from tween import _parse_style_ani |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
149 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
150 try: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
151 style = node.getAttribute('style') |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
152 except: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
153 style = '' |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
154 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
155 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
156 # |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
157 # Make scene groups hidden |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
158 # |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
159 try: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
160 scene_group = node.getAttribute('scene_group') |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
161 except: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
162 return style |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
163 |
1368
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
164 if scene_group != 'true': |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
165 return style |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
166 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
167 props = {} |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
168 _parse_style_ani(node, props) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
169 props['display'] = 'none' |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
170 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
171 return ';'.join([key + ':' + value for key, value in props.items()]) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
172 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
173 def _print_level(txt, lvl, out): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
174 indent = ' ' * lvl |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
175 print >> out, '%s%s' % (indent, txt) |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
176 pass |
1368
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
177 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
178 def _print_node_open(node, lvl, out): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
179 node_name = node.name() |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
180 if node_name.startswith('svg:'): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
181 node_name = node_name[4:] |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
182 pass |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
183 |
1368
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
184 attrs = [] |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
185 for attrname in node.allAttributes(): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
186 if attrname == 'style': |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
187 attrvalue = filter_style(node) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
188 if not attrvalue: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
189 continue |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
190 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
191 else: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
192 attrvalue = node.getAttribute(attrname) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
193 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
194 attr = '%s="%s"' % (attrname, attrvalue) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
195 attrs.append(attr) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
196 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
197 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
198 if attrs: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
199 attrs_str = ' '.join(attrs) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
200 line = '<%s %s>' % (node_name, attrs_str) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
201 else: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
202 line = '<%s>' % (node_name) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
203 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
204 _print_level(line, lvl, out) |
1361
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 |
1368
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
207 def _print_node_close(node, lvl, out): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
208 node_name = node.name() |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
209 if node_name.startswith('svg:'): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
210 node_name = node_name[4:] |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
211 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
212 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
213 line = '</%s>' % (node_name) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
214 _print_level(line, lvl, out) |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
215 pass |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
216 |
1368
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
217 def _print_node_single(node, lvl, out): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
218 node_name = node.name() |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
219 if node_name.startswith('svg:'): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
220 node_name = node_name[4:] |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
221 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
222 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
223 attrs = [] |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
224 for attrname in node.allAttributes(): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
225 attrvalue = node.getAttribute(attrname) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
226 attr = '%s="%s"' % (attrname, attrvalue) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
227 attrs.append(attr) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
228 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
229 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
230 if attrs: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
231 attrs_str = ' '.join(attrs) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
232 line = '<%s %s/>' % (node_name, attrs_str) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
233 else: |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
234 line = '<%s/>' % (node_name) |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
235 pass |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
236 _print_level(line, lvl, out) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
237 pass |
1368
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
238 |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
239 def _print_node_content(node, lvl, out): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
240 line = node.content() |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
241 _print_level(line, lvl, out) |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
242 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
243 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
244 children = node.childList() |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
245 if not children: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
246 if node.name() != 'string': |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
247 _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
|
248 else: |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
249 _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
|
250 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
251 return |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
252 |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
253 _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
|
254 for child in children: |
1368
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
255 if skip(child): |
9e7ec3b96968
Skip and fielt content of the tree before being written out
Thinker K.F. Li <thinker@codemud.net>
parents:
1367
diff
changeset
|
256 continue |
1361
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
257 _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
|
258 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
259 _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
|
260 pass |
cf5ed0b8f45d
Write out all content of a DOM-tree
Thinker K.F. Li <thinker@codemud.net>
parents:
1354
diff
changeset
|
261 |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
262 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
263 ## \brief CSS3 animation code generator. |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
264 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
265 # 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
|
266 # nodes. |
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 @trait |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
269 class css3_ani_gen(object): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
270 _parse_ani_attrs = require |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
271 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
272 _passing = lambda name, value: (name, str(value)) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
273 _trans_transform = lambda name, value: \ |
1367
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
274 (name, 'matrix(' + ','.join([str(e) for e in value[0]]) + ')') |
1362
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 _translators = {'x': _passing, 'y': _passing, |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
277 'width': _passing, 'height': _passing, |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
278 'opacity': _passing, 'transform': _trans_transform |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
279 } |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
280 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
281 del _trans_transform |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
282 del _passing |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
283 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
284 @staticmethod |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
285 def _ani_attr_to_css3(attrname, attrvalue, css): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
286 translator = css3_ani_gen._translators[attrname] |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
287 cssname, cssvalue = translator(attrname, attrvalue) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
288 css[cssname] = cssvalue |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
289 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
290 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
291 def _make_css3_transition(self, node1, node2, duration): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
292 from tween import _normalize_attrs |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
293 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
294 ani_attrs1 = self._parse_ani_attrs(node1) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
295 ani_attrs2 = self._parse_ani_attrs(node2) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
296 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
297 _normalize_attrs(node1, ani_attrs1, node2, ani_attrs2) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
298 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
299 css = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
300 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
301 attrnames = set(ani_attrs1.keys() + ani_attrs2.keys()) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
302 for attrname in attrnames: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
303 attrvalue = ani_attrs2[attrname] |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
304 self._ani_attr_to_css3(attrname, attrvalue, css) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
305 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
306 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
307 properties = css.keys() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
308 css['transition-property'] = ', '.join(properties) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
309 css['transition-duration'] = '%gs' % (duration) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
310 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
311 return css |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
312 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
313 def _write_css(self, selector, css_props, out): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
314 print >> out, '%s {' % (selector) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
315 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
|
316 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
|
317 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
318 print >> out, '}' |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
319 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
320 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
321 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
322 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
323 @composite |
1341
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
324 class html5css3_ext(pybExtension.PYBindExtImp): |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
325 use_traits = (css3_ani_gen,) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
326 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
|
327 '_make_css3_transition', |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
328 css3_ani_gen._write_css: '_write_css' |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
329 } |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
330 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
331 _frame_rate = 12 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
332 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
333 def __init__(self): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
334 self._stylesheet = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
335 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
336 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
337 @staticmethod |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
338 def _parse_ani_attrs(node): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
339 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
|
340 attrs = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
341 _parse_attr_ani(node, attrs) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
342 _parse_style_ani(node, attrs) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
343 return attrs |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
344 |
1341
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
345 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
|
346 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
|
347 parser = dom_parser() |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
348 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
|
349 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
|
350 |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
351 self._handle_transition_layers() |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
352 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
353 out = file(filename, 'w+') |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
354 print >> out, '''\ |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
355 <html |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 > |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
365 <head> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
366 <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
|
367 <!-- Style for animation transitions --> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
368 <style type='text/css'>''' |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
369 |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
370 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
|
371 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
|
372 pass |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
373 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
374 print >> out, '''\ |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
375 </style> |
1367
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
376 <script>''' |
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
377 |
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
378 print >>out, 'var animation_info = ' |
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
379 import pprint |
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
380 pprint.pprint(self._stylesheet, stream=out, indent=4, depth=2) |
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
381 |
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
382 print >> out, '''\ |
9d46f2982fa3
Write animation information in javascript variable
Thinker K.F. Li <thinker@codemud.net>
parents:
1366
diff
changeset
|
383 </script> |
1364
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
384 </head> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
385 <body>''' |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
386 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
387 root = doc.rdoc.root() |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
388 _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
|
389 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
390 print >> out, '''\ |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
391 </body> |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
392 </html>''' |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
393 |
aa7cbf2cbf34
Fix bug of SVG been fault for showing
Thinker K.F. Li <thinker@codemud.net>
parents:
1363
diff
changeset
|
394 out.close() |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
395 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
396 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
397 ## \brief Find all animation pairs. |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
398 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
399 # 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
|
400 # 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
|
401 # 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
|
402 # This method is responsible for finding all pairs. |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
403 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
404 @staticmethod |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
405 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
|
406 # Collect all nodes in stop scene |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
407 stop_nodes = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
408 node = stop_scene_group.firstChild() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
409 while node: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
410 try: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
411 node_label = node.getAttribute("ns0:duplicate-src") |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
412 stop_nodes[node_label] = node |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
413 except: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
414 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
415 node = node.next() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
416 pass |
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 # Collect all nodes in start scene |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
419 start_nodes = {} |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
420 node = start_scene_group.firstChild() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
421 while node: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
422 try: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
423 node_label = node.getAttribute("id") |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
424 start_nodes[node_label] = node |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
425 except: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
426 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
427 node = node.next() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
428 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
429 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
430 pairs = [] |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
431 for start_node in start_scene_group.childList(): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
432 start_node_id = start_node.getAttribute('id') |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
433 try: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
434 stop_node = stop_nodes[start_node_id] |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
435 except: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
436 stop_node = start_node |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
437 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
438 pairs.append((start_node, stop_node)) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
439 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
440 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
441 return pairs |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
442 |
1363
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
443 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
|
444 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
|
445 gid = scene_group.getAttribute('id') |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
446 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
|
447 style = {'display': 'inline'} |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
448 self._stylesheet[selector] = style |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
449 pass |
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
450 |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
451 def _handle_transition_layer(self, layer_idx): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
452 parser = self._parser |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
453 maxframe = parser.get_maxframe() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
454 stylesheet = self._stylesheet |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
455 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
456 frame_idx = 0 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
457 while frame_idx < maxframe: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
458 scene = parser.get_scene(frame_idx, layer_idx) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
459 if not scene: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
460 frame_idx = frame_idx + 1 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
461 continue |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
462 |
1363
a05ea7fa43ec
Generate CSS rule for key frames
Thinker K.F. Li <thinker@codemud.net>
parents:
1362
diff
changeset
|
463 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
|
464 |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
465 start, end, tween_type = scene |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
466 if start == end: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
467 frame_idx = frame_idx + 1 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
468 continue |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
469 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
470 next_start = end + 1 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
471 scene = parser.get_scene(next_start, layer_idx) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
472 if not scene: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
473 frame_idx = next_start + 1 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
474 continue |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
475 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
476 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
|
477 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
|
478 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
479 duration = float(next_start - start) / self._frame_rate |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
480 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
481 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
482 # Generate style for every transition pair |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
483 # |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
484 transition_pairs = \ |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
485 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
|
486 for start_node, stop_node in transition_pairs: |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
487 css_props = self._make_css3_transition(start_node, |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
488 stop_node, |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
489 duration) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
490 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
|
491 selector = '.frame%04d #%s' % (start, node_id) |
1362
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
492 stylesheet[selector] = css_props |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
493 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
494 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
495 frame_idx = next_start |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
496 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
497 pass |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
498 |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
499 def _handle_transition_layers(self): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
500 num_layers = self._parser.get_layer_num() |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
501 for layer_idx in range(num_layers): |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
502 self._handle_transition_layer(layer_idx) |
bb76f9d57363
Generate CSS3 transition rules
Thinker K.F. Li <thinker@codemud.net>
parents:
1361
diff
changeset
|
503 pass |
1341
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
504 pass |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
505 pass |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
506 |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
507 extension = (html5css3_ext(), |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
508 'net.scribboo.html5css3', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
509 'HTML5/CSS3 exporter', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
510 'output', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
511 {'extension': '.html', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
512 'mimetype': 'text/html', |
599b606c4669
Start to implement HTML5/CSS3 exporter
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
513 '_filetypename': 'HTML5/CSS3 (*.html)'}) |