comparison pyink/domview.py @ 1253:07e0cb1e051d

Add class consistency_checker for domview_ui. - consistency_checker is to check consistency of the DOM-tree associated with a domview_ui. - It is so closed to domview_ui, so it may access private variables. - But, it uses public interface of domview_ui if possible. - consistency_checker is not integrated to domview_ui for separating functions of consistency checking from the domview_ui. It collects relative logic into a place and setups a boundary from others.
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 11 Jan 2011 11:43:32 +0800
parents 45e9566ea5c0
children 8755415b5e99
comparison
equal deleted inserted replaced
1252:71222a6b4c06 1253:07e0cb1e051d
1 import random 1 import random
2 import pybInkscape 2 import dom_event
3 from tween import TweenObject 3 from tween import TweenObject
4 4
5 class Layer: 5 class Layer:
6 def __init__(self, node): 6 def __init__(self, node):
7 self.scenes = [] 7 self.scenes = []
8 self.group = node 8 self.group = node
9 pass 9 pass
10 pass 10 pass
11
12 class ObjectWatcher(pybInkscape.PYNodeObserver):
13 def __init__(self, obj, type, func, arg):
14 self.obj = obj
15 self.type = type
16 self.func = func
17 self.arg = arg
18
19 def notifyChildAdded(self, node, child, prev):
20 if self.type == 'DOMNodeInserted':
21 self.func(node, child)
22 def notifyChildRemoved(self, node, child, prev):
23 if self.type == 'DOMNodeRemoved':
24 self.func(node, child)
25 def notifyChildOrderChanged(self,node,child,prev):
26 pass
27 def notifyContentChanged(self,node,old_content,new_content):
28 if self.type == 'DOMSubtreeModified':
29 self.func(node)
30 def notifyAttributeChanged(self,node, name, old_value, new_value):
31 if self.type == 'DOMAttrModified':
32 self.func(node, name, old_value, new_value)
33
34 def addEventListener(obj, type, func, arg):
35 obs = ObjectWatcher(obj, type, func, arg)
36 obj.addSubtreeObserver(obs)
37 pass
38
39 11
40 ## \brief Monitor changes of DOM-tree. 12 ## \brief Monitor changes of DOM-tree.
41 # 13 #
42 # This class monitors DOM-tree to maintain _maxframe and maps for node ID to 14 # This class monitors DOM-tree to maintain _maxframe and maps for node ID to
43 # node and scene group ID to scene node. 15 # node and scene group ID to scene node.
53 def _start_monitor(self): 25 def _start_monitor(self):
54 self._collect_node_ids() 26 self._collect_node_ids()
55 self._collect_all_scenes() 27 self._collect_all_scenes()
56 28
57 doc = self._doc 29 doc = self._doc
58 addEventListener(doc, 'DOMNodeInserted', self._on_insert_node, None) 30 dom_event.addEventListener(doc, 'DOMNodeInserted',
59 addEventListener(doc, 'DOMNodeRemoved', self._on_remove_node, None) 31 self._on_insert_node, None)
60 addEventListener(doc, 'DOMAttrModified', self._on_attr_modified, None) 32 dom_event.addEventListener(doc, 'DOMNodeRemoved',
33 self._on_remove_node, None)
34 dom_event.addEventListener(doc, 'DOMAttrModified',
35 self._on_attr_modified, None)
61 pass 36 pass
62 37
63 def _on_insert_node(self, node, child): 38 def _on_insert_node(self, node, child):
64 for cchild in child.childList(): 39 for cchild in child.childList():
65 self._on_insert_node(child, cchild) 40 self._on_insert_node(child, cchild)