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

Source Code for Package library.pyjamas.dnd

 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   
17 -def makeDraggable(widget):
18 element = widget.getElement() 19 DOM.setAttribute(element, 'draggable', True)
20 21 PROTECTED = 1 22 READ_WRITE = 2 23 READ_ONLY = 3 24 DISABLED = 4 25 26 # getTypes is provided to get around some of the 27 # various flavors dataTransfer.type objects. 28
29 -def getTypes(event):
30 types = [] 31 dt = event.dataTransfer 32 try: 33 dt_types = dt.types 34 if isinstance(dt_types, basestring): 35 return dt_types.split(',') 36 ct = 0 37 try: 38 type_i = dt_types.item(ct) 39 while type_i: 40 types.append(type_i) 41 ct += 1 42 type_i = dt_types.item(ct) 43 except: 44 try: 45 type_i = dt_types[ct] 46 while type_i: 47 types.append(type_i) 48 ct += 1 49 type_i = dt_types[ct] 50 except: 51 for item in ['Text', 'URL', 'File','HTML', 'Image', 'String']: 52 try: 53 if len(dt.getData(item)): 54 types.append(item) 55 except: 56 pass 57 except: 58 for item in ['Text', 'URL', 'File','HTML', 'Image']: 59 try: 60 if len(dt.getData(item)): 61 types.append(item) 62 except: 63 pass 64 return types
65