Package library :: Package pyjamas :: Package dnd :: Module DragEvent
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.dnd.DragEvent

  1  from pyjamas import DOM 
2 3 -class DragEvent(object):
4 """ 5 emulates a drag event. 6 http://dev.w3.org/html5/spec/dnd.html#dragevent 7 """ 8 relatedTarget = None 9 detail = 0 10 returnValue = True
11 - def __init__(self, evt, type, dataTransfer, target=None):
12 self.evt = evt 13 self.type = type 14 self.setTarget(target) 15 self.dataTransfer = dataTransfer 16 self.canBubble = True 17 if self.type in ['dragleave', 'dragend']: 18 self.cancelable = False 19 else: 20 self.cancelable = True
21
22 - def setTarget(self, target=None):
23 if target is not None: 24 self.target = target 25 else: 26 self.target = DOM.eventGetTarget(self.evt)
27 28 # rather than copying a bunch of attributes on init, we provide a bunch 29 # of property statements. These properties hardly ever get looked at 30 # during dnd events anyway, but they're there if we need them. 31
32 - def stopPropagation(self):
33 self.evt.stopPropagation()
34 35 @property
36 - def screenX(self):
37 return self.evt.screenX
38 39 @property
40 - def screenY(self):
41 return self.evt.screenY
42 43 @property
44 - def pageX(self):
45 return self.evt.pageX
46 47 @property
48 - def pageY(self):
49 return self.evt.pageY
50 51 @property
52 - def clientX(self):
53 return self.evt.clientX
54 55 @property
56 - def clientY(self):
57 return self.evt.clientY
58 59 @property
60 - def altKey(self):
61 return self.evt.altKey
62 63 @property
64 - def ctrlKey(self):
65 return self.evt.ctrlKey
66 67 @property
68 - def shiftKey(self):
69 return self.evt.shiftKey
70 71 @property
72 - def metaKey(self):
73 return self.evt.metaKey
74 75 @property
76 - def button(self):
77 return self.evt.button
78
79 - def preventDefault(self):
80 """ 81 ie6 sets returnValue to False, so we do, too. 82 """ 83 self.returnValue = False
84
85 - def initDragEvent(self, type, canBubble, cancelable, dummy, detail, screenX, 86 screenY, clientX, clientY, ctrlKey, altKey, shiftKey, 87 metaKey, button, relatedTarget, dataTransfer):
88 """ 89 Just raise NotImplemented. Provided only for completeness with the 90 Interface. 91 """ 92 raise NotImplemented("Instanciate this class with a mouse event.")
93 # self.type = type 94 # self.canBubble = canBubble 95 # self.cancelable = cancelable 96 # self.dummy = dummy 97 # self.detail = detail 98 # self.screenX = screenX 99 # self.screenY = screenY 100 # self.clientX = clientX 101 # self.clientY = clientY 102 # self.ctrlKey = ctrlKey 103 # self.altKey = altKey 104 # self.shiftKey = shiftKey 105 # self.metaKey = metaKey 106 # self.button = button 107 # self.relatedTarget = relatedTarget 108 # self.dataTransfer = dataTransfer 109