Package pyjamas :: Package ui :: Module DragHandler
[hide private]
[frames] | no frames]

Source Code for Module pyjamas.ui.DragHandler

 1  # Copyright (C) 2010 Jim Washington 
 2  # 
 3  # Licensed under the Apache License, Version 2.0 (the "License"); 
 4  # you may not use this file except in compliance with the License. 
 5  # You may obtain a copy of the License at 
 6  # 
 7  #     http://www.apache.org/licenses/LICENSE-2.0 
 8  # 
 9  # Unless required by applicable law or agreed to in writing, software 
10  # distributed under the License is distributed on an "AS IS" BASIS, 
11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
12  # See the License for the specific language governing permissions and 
13  # limitations under the License. 
14   
15  from pyjamas import DOM 
16  from pyjamas.ui import Event 
17   
18  DRAG_EVENTS = [ "dragstart", "drag", "dragend"] 
19   
20 -def fireDragEvent(listeners, event):
21 etype = DOM.eventGetType(event) 22 if etype == "dragstart": 23 for listener in listeners: 24 listener.onDragStart(event) 25 return True 26 elif etype == "drag": 27 for listener in listeners: 28 listener.onDrag(event) 29 return True 30 elif etype == "dragend": 31 for listener in listeners: 32 listener.onDragEnd(event) 33 return True 34 return False
35
36 -class DragHandler(object):
37
38 - def __init__(self):
39 self._dragListeners = [] 40 self.sinkEvents(Event.DRAGEVENTS)
41
42 - def onBrowserEvent(self, event):
43 event_type = DOM.eventGetType(event) 44 if event_type in DRAG_EVENTS: 45 return fireDragEvent(self._dragListeners, event) 46 return False
47
48 - def addDragListener(self, listener):
49 self._dragListeners.append(listener)
50
51 - def removeDragListener(self, listener):
52 self._dragListeners.remove(listener)
53
54 - def onDragStart(self, event):
55 """ 56 Store data into the DataTransfer object and set the allowed effects. 57 58 Set data into the event's dataTransfer with a content-type and some 59 string data. 60 61 Some native dataTransfer objects will only set content-type of "Text" 62 and/or "URL". 63 64 allowedEffects is one of: 'none', 'copy', 'copyLink', 'copyMove', 65 'link', 'linkMove', 'move', or 'all' 66 67 an example:: 68 69 dt = event.dataTransfer 70 dt.setData('text/plain','Hello, World!') 71 dt.allowedEffects = 'copyMove' 72 """ 73 pass
74
75 - def onDrag(self, event):
76 """ 77 this happens periodically while the drag is in progress. 78 use DOM.eventPreventDefault(event) to cancel drag operation 79 """ 80 pass
81
82 - def onDragEnd(self, event):
83 """ 84 This happens on the initiating widget after the dragging mouse 85 is released. 86 """ 87 pass
88