1 from pyjamas.Timer import Timer
2 from pyjamas.dnd.utils import cloneElement, DOMStringList
3
4 from pyjamas.dnd import READ_ONLY, READ_WRITE, PROTECTED, DISABLED
5
8
10 """
11 this is an in-browser string-kind-only implementation.
12 see: http://http://dev.w3.org/html5/spec/dnd.html#datatransferitem
13 """
15 self._type = type
16 self._data = data
17
19 if self.mode == DISABLED:
20 return ''
21 return self._type
22 type = property(getType)
23
25 if self.mode == DISABLED:
26 return ''
27 return 'string'
28 kind = property(getKind)
29
32
33
36 mode = property(getMode, setMode)
37
42
45
47
54 mode = property(getMode, setMode)
55
56
57
58
59
60
61
62
64 if not self.mode == READ_WRITE:
65 raise Exception('Cannot delete item except in READ_WRITE mode.')
66 else:
67 list.__delitem__(self, key)
68
73
78
79 - def add(self, data, mime):
85
86
87
89 _mode = PROTECTED
91 self.items = DataTransferItems()
92 self.default_feedback = None
93 self.elements = []
94 self.bitmap = None
95 self.hotspot_coordinate = None
96 self.allowed_effects_state = 'uninitialized'
97
102
105 mode = property(getMode, setMode)
106
107
109 """
110 DataTransfer implementation
111 http://dev.w3.org/html5/spec/dnd.html#datatransfer
112 """
113
115 self.dataStore = dataStore
116 self.setEffectAllowed(dataStore.allowed_effects_state)
117 self._dropEffect = 'none'
118 self._value = None
119
122
124 if effect in ('none', 'copy', 'link' ,'move'):
125 self._dropEffect = effect
126
128 return self._dropEffect
129
130 dropEffect = property(getDropEffect, setDropEffect)
131
133 if effect in ('none', 'copy', 'copyLink', 'copyMove',
134 'link', 'linkMove', 'move', 'all', 'uninitialized'):
135 self._effectAllowed = effect
136
138 return self._effectAllowed
139
140 effectAllowed = property(getEffectAllowed, setEffectAllowed)
141
143 if self.dataStore.mode == READ_WRITE:
144 format = format.strip().lower()
145 if format == 'text':
146 format = 'text/plain'
147 elif format == 'url':
148 format = 'text/uri-list'
149 self.clearData(format)
150 items = self.dataStore.items
151 z = items.add(data, format)
152 z.mode = READ_WRITE
153
155 theList = []
156 if self.dataStore is not None:
157 items = self.dataStore.items
158 for item in items:
159 theList.append(item.type)
160 return DOMStringList(theList)
161
162 types = property(getTypes)
163
165 format = format.strip().lower()
166 if format == 'text':
167 format = 'text/plain'
168 elif format == 'url':
169 format = 'text/uri-list'
170 theList = self.dataStore.items
171 for item in theList:
172 if item.type == format:
173 item.getAsString(self.acquireData)
174 return self._value
175 return ''
176
178 thelist = self.dataStore.items
179 if self.dataStore is not None:
180 if format is None:
181 thelist.clear()
182 else:
183 format = format.lower()
184 to_del = []
185 for idx, item in enumerate(thelist):
186 if item.type == format:
187 to_del.append(idx)
188 to_del.reverse()
189 for idx in to_del:
190 del thelist[idx]
191
194
196 self.dataStore.bitmap = element
197 self.dataStore.hotspot_coordinate = (x, y, )
198