1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libxml2dom/events.py Tue Mar 13 00:16:45 2007 +0000
1.3 @@ -0,0 +1,94 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +DOM events support.
1.8 +
1.9 +Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This library is free software; you can redistribute it and/or
1.12 +modify it under the terms of the GNU Lesser General Public
1.13 +License as published by the Free Software Foundation; either
1.14 +version 2.1 of the License, or (at your option) any later version.
1.15 +
1.16 +This library is distributed in the hope that it will be useful,
1.17 +but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.19 +Lesser General Public License for more details.
1.20 +
1.21 +You should have received a copy of the GNU Lesser General Public
1.22 +License along with this library; if not, write to the Free Software
1.23 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.24 +"""
1.25 +
1.26 +class EventException(Exception):
1.27 +
1.28 + UNSPECIFIED_EVENT_TYPE_ERR = 0
1.29 + DISPATCH_REQUEST_ERR = 1
1.30 +
1.31 +class Event:
1.32 +
1.33 + CAPTURING_PHASE = 1
1.34 + AT_TARGET = 2
1.35 + BUBBLING_PHASE = 3
1.36 +
1.37 + def __init__(self):
1.38 + type
1.39 + target
1.40 + currentTarget
1.41 + eventPhase
1.42 + bubbles
1.43 + cancelable
1.44 + timeStamp
1.45 + namespaceURI
1.46 + defaultPrevented
1.47 +
1.48 + def initEvent(self, eventTypeArg, canBubbleArg, cancelableArg):
1.49 + pass
1.50 +
1.51 + def initEvent(self, eventTypeArg, canBubbleArg, cancelableArg):
1.52 + pass
1.53 +
1.54 + def initEventNS(self, namespaceURIArg, eventTypeArg, canBubbleArg, cancelableArg):
1.55 + pass
1.56 +
1.57 + def preventDefault(self):
1.58 + pass
1.59 +
1.60 + def stopPropagation(self):
1.61 + pass
1.62 +
1.63 + def stopImmediatePropagation(self):
1.64 + pass
1.65 +
1.66 +class EventTarget:
1.67 +
1.68 + "An event target class."
1.69 +
1.70 + def __init__(self):
1.71 + self.listeners = {}
1.72 +
1.73 + def addEventListener(self, type, listener, useCapture):
1.74 + self.addEventListenerNS(None, type, listener, useCapture)
1.75 +
1.76 + def addEventListenerNS(self, namespaceURI, type, listener, useCapture):
1.77 + if not self.listeners.has_key((namespaceURI, type)):
1.78 + self.listeners[(namespaceURI, type)] = []
1.79 + self.listeners[(namespaceURI, type)].append((listener, useCapture))
1.80 +
1.81 + def dispatchEvent(self, evt):
1.82 + if not evt.type:
1.83 + raise EventException(EventException.UNSPECIFIED_EVENT_TYPE_ERR)
1.84 + # NOTE: Dispatch on namespaceURI, type...
1.85 +
1.86 + def removeEventListener(self, type, listener, useCapture):
1.87 + self.removeEventListenerNS(None, type, listener, useCapture)
1.88 +
1.89 + def removeEventListenerNS(self, namespaceURI, type, listener, useCapture):
1.90 + if self.listeners.has_key((namespaceURI, type)):
1.91 + listeners = self.listeners[(namespaceURI, type)]
1.92 + try:
1.93 + listeners.remove((listener, useCapture))
1.94 + except ValueError:
1.95 + pass
1.96 +
1.97 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/libxml2dom/svg.py Tue Mar 13 00:15:13 2007 +0000
2.2 +++ b/libxml2dom/svg.py Tue Mar 13 00:16:45 2007 +0000
2.3 @@ -1,7 +1,8 @@
2.4 #!/usr/bin/env python
2.5
2.6 """
2.7 -SVG-specific document support.
2.8 +SVG-specific document support. See:
2.9 +http://www.w3.org/TR/SVGMobile12/python-binding.html
2.10
2.11 Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk>
2.12
2.13 @@ -29,20 +30,51 @@
2.14 toString as Node_toString, toStream as Node_toStream, \
2.15 toFile as Node_toFile
2.16
2.17 +SVG_NAMESPACE = "http://www.w3.org/2000/svg"
2.18 +
2.19 class SVGImplementation(libxml2dom.Implementation):
2.20
2.21 "Contains an SVG-specific implementation."
2.22
2.23 + # Wrapping of documents.
2.24 +
2.25 + def adoptDocument(self, node):
2.26 + return SVGDocument(node, self)
2.27 +
2.28 + # Factory functions.
2.29 +
2.30 def get_node(self, _node, context_node):
2.31 if Node_nodeType(_node) == context_node.ELEMENT_NODE and \
2.32 - Node_namespaceURI(_node) == "http://www.w3.org/2000/svg" and \
2.33 - Node_localName(_node) == "svg":
2.34 + Node_namespaceURI(_node) == SVG_NAMESPACE:
2.35
2.36 - return SVGElement(_node, self, context_node.ownerDocument)
2.37 + if Node_localName(_node) == "svg":
2.38 + return SVGSVGElement(_node, self, context_node.ownerDocument)
2.39 + else:
2.40 + return SVGElement(_node, self, context_node.ownerDocument)
2.41 else:
2.42 return libxml2dom.Implementation.get_node(self, _node, context_node)
2.43
2.44 -class SVGElement(libxml2dom.Node):
2.45 +class SVGElement(libxml2dom.Node): # Element, EventTarget, TraitAccess, ElementTraversal
2.46 +
2.47 + "An SVG-specific element."
2.48 +
2.49 + def _id(self):
2.50 + return self.getAttribute("id")
2.51 +
2.52 + def _setId(self, value):
2.53 + self.setAttribute("id", value)
2.54 +
2.55 + id = property(_id, _setId)
2.56 +
2.57 +class SVGLocatable:
2.58 +
2.59 + "A locatable interface."
2.60 +
2.61 +class SVGLocatableElement(SVGElement, SVGLocatable):
2.62 +
2.63 + "A locatable element."
2.64 +
2.65 +class SVGSVGElement(SVGLocatableElement): # SVGTimedElement
2.66
2.67 "An SVG-specific top-level element."
2.68
2.69 @@ -58,6 +90,14 @@
2.70 NAV_LEFT = 10
2.71 NAV_UP_LEFT = 11
2.72
2.73 +class SVGDocument(libxml2dom.Document):
2.74 +
2.75 + "An SVG-specific document node."
2.76 +
2.77 + # NOTE: Define global (SVGGlobal).
2.78 +
2.79 +# Convenience functions.
2.80 +
2.81 def parse(stream_or_string, html=0):
2.82 return libxml2dom.parse(stream_or_string, html, default_impl)
2.83