comparison pyink/consistency.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
children 027cd060d9ba
comparison
equal deleted inserted replaced
1252:71222a6b4c06 1253:07e0cb1e051d
1 import dom_event
2 from data_monitor import data_monitor
3
4 ## \brief Check consistency of a DOM-tree associated with a domview_ui.
5 #
6 # This is a co-worker of \ref domview_ui to check DOM-tree and make
7 # sure consistency of scenes, scene groups in the DOM-tree. It also
8 # updates layer list of \ref domview_ui to reflect last changes of the
9 # DOM-tree.
10 #
11 # Since it is a consistency checker, it must well understanding
12 # structure that expected by domview_ui. So, this class is highly
13 # closed to the internal of \ref domview_ui. It is separated from
14 # domview_ui for collecting related logic and functions in a place to
15 # set up a clear boundary from the functions provided by \ref
16 # domview_ui.
17 #
18 # This class is expected to access private variables of \ref
19 # domview_ui. But, use public interface of domview_ui if possible.
20 #
21 # This class is also monitored by \ref data_monitor to monitor the
22 # accessing to domview_ui.
23 #
24 class consistency_checker(object):
25 __metaclass__ = data_monitor
26
27 def __init__(self, domview_ui):
28 self._domview = domview_ui
29 self._doc = None
30 self._root = None
31 pass
32
33 def _start_check(self):
34 doc = self._doc
35 dom_event.addEventListener(doc, 'DOMNodeInserted',
36 self.do_insert_node, None)
37 dom_event.addEventListener(doc, 'DOMNodeRemoved',
38 self.do_remove_node, None)
39 dom_event.addEventListener(doc, 'DOMAttrModified',
40 self.do_attr_modified, None)
41 pass
42
43 ## \brief Handle a new document.
44 #
45 # This method is called by domview_ui.handle_doc_root().
46 #
47 def handle_doc_root(self, doc, root):
48 self._doc = doc
49 self._root = root
50
51 self._start_check()
52 pass
53
54 def do_insert_node(self, node, child):
55 pass
56
57 def do_remove_node(self, node, child):
58 pass
59
60 def do_attr_modified(self, node, name, old_value, new_value):
61 pass
62 pass