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