def onMouseUp(self, sender, x, y): # event = DOM.eventGetCurrentEvent() self.dragging = NOT_DRAGGING if self.draggingImage: GlassWidget.hide() if (self.currentDragOperation == 'none' or not self.currentTargetElement): if self.currentTargetElement: # leave_event = self.makeDragEvent(event, 'dragleave', # self.currentTargetElement) self.fireDNDEvent('dragleave', self.currentTargetElement, self.currentDropWidget) # self.currentDropWidget.onDragLeave(leave_event) # self.finalize(leave_event) else: self.currentDragOperation = 'none' self.returnDrag() else: # self.dragDataStore.mode = READ_ONLY # drop_event = self.makeDragEvent(event, 'drop', # self.currentTargetElement) drop_event = self.fireDNDEvent('drop', self.currentTargetElement, self.currentDropWidget) #self.dropEffect = self.currentDragOperation # self.currentDropWidget.onDrop(drop_event) # self.finalize(drop_event) if isCanceled(drop_event): self.currentDragOperation = drop_event.dataTransfer.dropEffect else: self.currentDragOperation = 'none' self.zapDragImage() #self.dropEffect = self.currentDragOperation self.fireDNDEvent('dragend', None, self.dragWidget)
def _stopDragging(self): if self._drag_start is not None: # we are no longer dragging self._drag_start = None # deactivate the transparent overlay GlassWidget.hide() # don't let a mouse-up become a click event DOM.eventCancelBubble(DOM.eventGetCurrentEvent(), True)
def startSplitterDrag(self, x, y): if self._drag_start is None: # remember where on the slider we are dragging if self._vertical: self._drag_start = y else: self._drag_start = x # activate the transparent overlay to keep mouse events flowing to # the splitter (and to us) even if the mouse leaves the splitter GlassWidget.show(self)
def onMouseDown(self, sender, x, y): # regardless of drag_enabled, onMouseDown must prevent # default, in order to avoid losing focus. self.setFocus(True) DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) if not self.drag_enabled: return self.dragging = True GlassWidget.show(self) self.moveControl(x + Window.getScrollLeft(), y + Window.getScrollTop(), True)
def onMouseMove(self, sender, x, y): event = DOM.eventGetCurrentEvent() self.mouseEvent = event button = DOM.eventGetButton(event) if not button == Event.BUTTON_LEFT: return ## The following commented code lets the native dnd happen in IE. sucks. ## But it may enable dragging our widgets out of IE into other apps. # else: # try: # self.dragWidget.getElement().dragDrop() # return # except: # pass # Adjust x and y to absolute coordinates. x, y = eventCoordinates(event) if self.dragging == DRAGGING_NO_MOVEMENT_YET: self.origMouseX = x self.origMouseY = y self.currentDragOperation = 'none' fromElement = self.dragWidget.getElement() # Is the widget itself draggable? try: draggable = fromElement.draggable except: draggable = False # if not, find the draggable element at (x, y) in the widget if not draggable: fromElement = findDraggable(sender.getElement(), self.origMouseX, self.origMouseY) # Nothing draggable found. return. if fromElement is None: self.dragging = NOT_DRAGGING return # Get the location for the dragging widget #self.absParent = None #self.absParent = self.dragWidget.getParent() #self.absLeft = DOM.getStyleAttribute(fromElement, 'left') #print self.absLeft #self.absTop = DOM.getStyleAttribute(fromElement, 'top') #print self.absTop #self.origTop = DOM.getAbsoluteTop(fromElement) + parent.getAbsoluteTop() #self.origLeft = DOM.getAbsoluteLeft(fromElement) + parent.getAbsoluteLeft() self.origTop = DOM.getAbsoluteTop(fromElement) self.origLeft = DOM.getAbsoluteLeft(fromElement) #self.glassTop = DOM.getAbsoluteTop(fromElement.offsetParent) #self.glassLeft = DOM.getAbsoluteTop(fromElement.offsetParent) position_absolute = DOM.getStyleAttribute(fromElement, 'position') == 'absolute' if position_absolute: self.dragLeftOffset = ( self.origMouseX - DOM.getAbsoluteLeft(fromElement.offsetParent)) self.dragTopOffset = ( self.origMouseY - DOM.getAbsoluteTop(fromElement.offsetParent)) else: self.dragLeftOffset = self.origMouseX - self.origLeft self.dragTopOffset = self.origMouseY - self.origTop # self.setDragImage(fromElement, # self.origMouseX - self.origLeft, # self.origMouseY - self.origTop) self.dragDataStore.elements = [fromElement] dragStartEvent = self.fireDNDEvent('dragstart', None, self.dragWidget) if not isCanceled(dragStartEvent): self.initFeedbackImage() RootPanel().add(self.draggingImage) self.setDragImageLocation(x, y) self.dragging = ACTIVELY_DRAGGING GlassWidget.show(self) elif self.dragging == ACTIVELY_DRAGGING: try: doc().selection.empty() except: wnd().getSelection().removeAllRanges() self.setDragImageLocation(x, y) # If we are still working on the previous iteration, or if we have # done this recently, we'll wait for the next event. if self.dragBusy or time.time() - self.drag_time < 0.25: return self.doDrag(event, x, y) self.drag_time = time.time()
def endDragging(self): if not self.dragging: return self.dragging = False GlassWidget.hide()
def onMouseDown(self, sender, x, y): self.dragging = True GlassWidget.show(self.caption) self.dragStartX = x self.dragStartY = y
def onMouseMove(self, sender, x, y): event = DOM.eventGetCurrentEvent() self.mouseEvent = event button = DOM.eventGetButton(event) if not button == Event.BUTTON_LEFT: return ## The following commented code lets the native dnd happen in IE. sucks. ## But it may enable dragging our widgets out of IE into other apps. # else: # try: # self.dragWidget.getElement().dragDrop() # return # except: # pass # Adjust x and y to absolute coordinates. x, y = eventCoordinates(event) if self.dragging == DRAGGING_NO_MOVEMENT_YET: self.origMouseX = x self.origMouseY = y self.currentDragOperation = 'none' fromElement = self.dragWidget.getElement() # Is the widget itself draggable? try: draggable = fromElement.draggable except: draggable = False # if not, find the draggable element at (x, y) in the widget if not draggable: fromElement = findDraggable(sender.getElement(), self.origMouseX, self.origMouseY) # Nothing draggable found. return. if fromElement is None: self.dragging = NOT_DRAGGING return # Get the location for the dragging widget #self.absParent = None #self.absParent = self.dragWidget.getParent() #self.absLeft = DOM.getStyleAttribute(fromElement, 'left') #print self.absLeft #self.absTop = DOM.getStyleAttribute(fromElement, 'top') #print self.absTop #self.origTop = DOM.getAbsoluteTop(fromElement) + parent.getAbsoluteTop() #self.origLeft = DOM.getAbsoluteLeft(fromElement) + parent.getAbsoluteLeft() self.origTop = DOM.getAbsoluteTop(fromElement) self.origLeft = DOM.getAbsoluteLeft(fromElement) #self.glassTop = DOM.getAbsoluteTop(fromElement.offsetParent) #self.glassLeft = DOM.getAbsoluteTop(fromElement.offsetParent) position_absolute = DOM.getStyleAttribute(fromElement, 'position') == 'absolute' if position_absolute: self.dragLeftOffset = (self.origMouseX - DOM.getAbsoluteLeft(fromElement.offsetParent)) self.dragTopOffset = (self.origMouseY - DOM.getAbsoluteTop(fromElement.offsetParent)) else: self.dragLeftOffset = self.origMouseX - self.origLeft self.dragTopOffset = self.origMouseY - self.origTop # self.setDragImage(fromElement, # self.origMouseX - self.origLeft, # self.origMouseY - self.origTop) self.dragDataStore.elements = [fromElement] dragStartEvent = self.fireDNDEvent('dragstart', None, self.dragWidget) if not isCanceled(dragStartEvent): self.initFeedbackImage() RootPanel().add(self.draggingImage) self.setDragImageLocation(x, y) self.dragging = ACTIVELY_DRAGGING GlassWidget.show(self) elif self.dragging == ACTIVELY_DRAGGING: try: doc().selection.empty() except: wnd().getSelection().removeAllRanges() self.setDragImageLocation(x, y) # If we are still working on the previous iteration, or if we have # done this recently, we'll wait for the next event. if self.dragBusy or time.time() - self.drag_time < 0.25: return self.doDrag(event, x, y) self.drag_time = time.time()