view pyink/dom_event.py @ 1428:43369f3314d8

Fix the issue of loading components from SVG. - Users can not switch to components in the document that was loaded from previously saved SVG file. - Scribboo can not find components with names listed in the component list. - It is because that Scribboo is fault to use node name of ns0:component instead of 'name' attribute as component name. - It is fixed by using 'name' attribute of ns0:component node.
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 10 Apr 2011 15:28:33 +0800
parents 5313bbfafa67
children
line wrap: on
line source

import pybInkscape

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, old_prev, new_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