Mercurial > MadButterfly
diff 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 |
line wrap: on
line diff
--- a/pyink/domview.py Tue Jan 11 10:36:39 2011 +0800 +++ b/pyink/domview.py Tue Jan 11 11:43:32 2011 +0800 @@ -1,5 +1,5 @@ import random -import pybInkscape +import dom_event from tween import TweenObject class Layer: @@ -9,34 +9,6 @@ pass pass -class ObjectWatcher(pybInkscape.PYNodeObserver): - def __init__(self, obj, type, func, arg): - self.obj = obj - self.type = type - self.func = func - self.arg = arg - - def notifyChildAdded(self, node, child, prev): - if self.type == 'DOMNodeInserted': - self.func(node, child) - def notifyChildRemoved(self, node, child, prev): - if self.type == 'DOMNodeRemoved': - self.func(node, child) - def notifyChildOrderChanged(self,node,child,prev): - pass - def notifyContentChanged(self,node,old_content,new_content): - if self.type == 'DOMSubtreeModified': - self.func(node) - def notifyAttributeChanged(self,node, name, old_value, new_value): - if self.type == 'DOMAttrModified': - self.func(node, name, old_value, new_value) - -def addEventListener(obj, type, func, arg): - obs = ObjectWatcher(obj, type, func, arg) - obj.addSubtreeObserver(obs) - pass - - ## \brief Monitor changes of DOM-tree. # # This class monitors DOM-tree to maintain _maxframe and maps for node ID to @@ -55,9 +27,12 @@ self._collect_all_scenes() doc = self._doc - addEventListener(doc, 'DOMNodeInserted', self._on_insert_node, None) - addEventListener(doc, 'DOMNodeRemoved', self._on_remove_node, None) - addEventListener(doc, 'DOMAttrModified', self._on_attr_modified, None) + dom_event.addEventListener(doc, 'DOMNodeInserted', + self._on_insert_node, None) + dom_event.addEventListener(doc, 'DOMNodeRemoved', + self._on_remove_node, None) + dom_event.addEventListener(doc, 'DOMAttrModified', + self._on_attr_modified, None) pass def _on_insert_node(self, node, child):