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