1 """
2 Copyright (C) 2008, 2009 - Luke Kenneth Casson Leighton <lkcl@lkcl.net>
3
4 """
5 from pyjamas import DOM
6 from pyjamas.ui import Event
7
9
10 - def __init__(self, preventDefault=False):
17
20
23
25 self._doubleclickListeners.append(listener)
26
28 stylename = self.getStyleName()
29 if stylename:
30 self.addStyleName("%s-clickable" % stylename.split()[0])
31 self._clickListeners.append(listener)
32
34 """Listen to events raised by the browser and call the appropriate
35 method of the listener (widget, ..) object.
36 """
37 type = DOM.eventGetType(event)
38 if type == "click":
39 if self._clickPreventDefault:
40 DOM.eventPreventDefault(event)
41 for listener in self._clickListeners:
42 if hasattr(listener, "onClick"):
43 listener.onClick(self)
44 else:
45 listener(self)
46 elif type == "dblclick":
47 if self._clickPreventDefault:
48 DOM.eventPreventDefault(event)
49 for listener in self._doubleclickListeners:
50 if hasattr(listener, "onDoubleClick"):
51 listener.onDoubleClick(self)
52 else:
53 listener(self)
54
56 self._clickListeners.remove(listener)
57
59 self._doubleclickListeners.remove(listener)
60
62 self._clickListeners[:] = []
63
65 self._doubleclickListeners.remove(listener)[:] = []
66