def onMouseMove(self, sender, x, y): event = DOM.eventGetCurrentEvent() DOM.eventPreventDefault(event) # mousing auto re-enables mouse-over hover feedback if not self.theChild.getHoverTouchingEnabled(): self.theChild.setHoverTouchingEnabled(True) self.theChild.update()
def onBrowserEvent(self, event): Widget.onBrowserEvent(self, event) event_type = DOM.eventGetType(event) if event_type == "click": DOM.eventPreventDefault(event) if self.targetHistoryToken is not None: History.newItem(self.targetHistoryToken)
def onElementContextmenu(self, sender,event): x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(self.canvas.getElement()) y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(self.canvas.getElement()) s = self.desc[self.elements.index(sender)] self.set_status('Contextmenue on Element '+s+' at '+str(x)+', '+str(y)) DOM.eventCancelBubble(event,True) DOM.eventPreventDefault(event)
def onDrop(self, event): dt = event.dataTransfer item = dt.getData("Text") data = json.decode(item) if 'name' in data and 'age' in data: age = data['age'] name = data['name'] self.removeStyleName('dragover') if self.age_is_ok(age): self.addStudent(name, age) dt.dropEffect = 'copy' self.addStyleName('flash') def removeFlash(timer): self.removeStyleName('flash') Timer(250, notify=removeFlash) else: dt.dropEffect = 'none' self.addMessage('student could not be added') # setting dropEffect to 'none' should be sufficient to notify # that the drop failed, but # we need to cheat a bit for now... # this is the only reason for parent id in data item_parent_id = data['parent'] item_parent = self.parent.containerFromId(item_parent_id) item_parent.addStyleName('drop_fail') # prevent default allows onDragEnd to see the dropEffect we set here DOM.eventPreventDefault(event)
def onBrowserEvent(self, event): # farm out the event to convenience handlers. # detect existence by checking for the listener lists of each # type of handler. there's probably a better way to do this... if hasattr(self, "_clickListeners"): ClickHandler.onBrowserEvent(self, event) if hasattr(self, "_keyboardListeners"): KeyboardHandler.onBrowserEvent(self, event) if hasattr(self, "_mouseListeners"): MouseHandler.onBrowserEvent(self, event) if hasattr(self, "_mouseWheelListeners"): MouseWheelHandler.onBrowserEvent(self, event) if hasattr(self, "_focusListeners"): FocusHandler.onBrowserEvent(self, event) if hasattr(self, "_dragListeners"): DragHandler.onBrowserEvent(self, event) if hasattr(self, "_dropListeners"): DropHandler.onBrowserEvent(self, event) if self.contextMenu is None: return True type = DOM.eventGetType(event) if type == "contextmenu": DOM.eventCancelBubble(event, True) DOM.eventPreventDefault(event) self.contextMenu.onContextMenu(self) return False return True
def onBrowserEvent(self, event): # farm out the event to convenience handlers. # detect existence by checking for the listener lists of each # type of handler. there's probably a better way to do this... if hasattr(self, "_clickListeners"): ClickHandler.onBrowserEvent(self, event) if hasattr(self, "_keyboardListeners"): KeyboardHandler.onBrowserEvent(self, event) if hasattr(self, "_mouseListeners"): MouseHandler.onBrowserEvent(self, event) if hasattr(self, "_mouseWheelListeners"): MouseWheelHandler.onBrowserEvent(self, event) if hasattr(self, "_focusListeners"): FocusHandler.onBrowserEvent(self, event) if hasattr(self, "_dragListeners"): DragHandler.onBrowserEvent(self, event) if hasattr(self, "_changeListeners"): ChangeHandler.onBrowserEvent(self, event) if hasattr(self, "_inputListeners"): InputHandler.onBrowserEvent(self, event) if hasattr(self, "_dropListeners"): DropHandler.onBrowserEvent(self, event) if self.contextMenu is None: return True type = DOM.eventGetType(event) if type == "contextmenu": DOM.eventCancelBubble(event, True) DOM.eventPreventDefault(event) self.contextMenu.onContextMenu(self) return False return True
def onDrop(self, event): dt = event.dataTransfer types = getTypes(event) self.addMessage("drop types received: " + ", ".join(types)) parent = self.getParent() parent.clearContent() self.addMessage('dt: ' + str(dt)) types.sort() for ctype in types: data = dt.getData(ctype) if ctype == 'Files': file_names = [] files = dt.files # files is a FileList # http://help.dottoro.com/ljuelxgf.php for idx in range(files.length): item = files.item(idx) try: name = item.name except: name = item.fileName file_names.append(name) data = '<br>'.join(file_names) parent.addContent(ctype, data) DOM.eventPreventDefault(event) # cancel bubble so first file is not opened in browser. DOM.eventCancelBubble(event, True)
def onDrop(self, event): dt = event.dataTransfer text = dt.getData('text') package = json.decode(text) x = DOM.eventGetClientX(event) y = DOM.eventGetClientY(event) scrollY = Window.getScrollTop() scrollX = Window.getScrollLeft() offsetX = int(package['offsetX']) offsetY = int(package['offsetY']) at = self.getAbsoluteTop() al = self.getAbsoluteLeft() posX, posY = x - (al - scrollX), y - (at - scrollY) w = DragWidget6(package['text']) self.add(w) makeDraggable(w) # firefox seems to be off-by-one in x. # firefox-specific code? #w.setStyleAttribute('left', posX - offsetX -1) w.setStyleAttribute('left', posX - offsetX) w.setStyleAttribute('top', posY - offsetY) w.removeStyleName('invisible') self.addMessage( "top:%s, left:%s, cy:%s cx:%s, sy:%s sx:%s dropy:%s dropx:%s" % ( at, al, y, x, scrollY, scrollX, posY, posX)) DOM.eventPreventDefault(event)
def action(self,element,event): x = DOM.eventGetClientX(event) - self.ox y = DOM.eventGetClientY(event) - self.oy DOM.eventCancelBubble(event,True) DOM.eventPreventDefault(event) #alert('clic %s %s'%(x,y)) self._action(x,y)
def onBrowserEvent(self, event): etype = DOM.eventGetType(event) if etype in MOUSE_EVENTS: if self._mousePreventDefault: DOM.eventPreventDefault(event) return fireMouseEvent(self._mouseListeners, self, event) return False
def onKeyDown(self, sender, keycode, modifiers): evt = DOM.eventGetCurrentEvent() DOM.eventPreventDefault(evt) if self.word_selected_pos is None: return val = chr(keycode) done = False if keycode == KeyboardListener.KEY_DELETE: self.shift_letters_back() done = True elif keycode == KeyboardListener.KEY_BACKSPACE: if not self.nasty_hack(): if self.moveCursor(-1): self.shift_letters_back() done = True elif keycode == KeyboardListener.KEY_LEFT: self.moveCursor(-1) done = True elif keycode == KeyboardListener.KEY_RIGHT: self.moveCursor(1) done = True print "onKeyDown", keycode, val, self.rexp.match(val) if not done: if self.rexp.match(val): self.press_letter(val) for listener in self._keypressListeners: listener.onKeyPressed(sender, keycode, modifiers)
def onDrop(self, event): dt = event.dataTransfer text = dt.getData('text') package = json.decode(text) x = DOM.eventGetClientX(event) y = DOM.eventGetClientY(event) scrollY = Window.getScrollTop() scrollX = Window.getScrollLeft() offsetX = int(package['offsetX']) offsetY = int(package['offsetY']) at = self.getAbsoluteTop() al = self.getAbsoluteLeft() posX, posY = x - (al - scrollX), y - (at - scrollY) w = DragWidget6(package['text']) self.add(w) makeDraggable(w) # firefox seems to be off-by-one in x. # firefox-specific code? #w.setStyleAttribute('left', posX - offsetX -1) w.setStyleAttribute('left', posX - offsetX) w.setStyleAttribute('top', posY - offsetY) w.removeStyleName('invisible') self.addMessage( "top:%s, left:%s, cy:%s cx:%s, sy:%s sx:%s dropy:%s dropx:%s" % (at, al, y, x, scrollY, scrollX, posY, posX)) DOM.eventPreventDefault(event)
def onCanvasContextmenu(self, sender, event): x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft( self.canvas.getElement()) y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop( self.canvas.getElement()) self.set_status('Contextmenue on Canvas at ' + str(x) + ', ' + str(y)) DOM.eventPreventDefault(event)
def onBrowserEvent(self, event): type = DOM.eventGetType(event) if type == 'mousedown' or type == 'mouseup' or type == 'mousemove' or type == 'mouseover' or type == 'mouseout': MouseListener.fireMouseEvent(self.mouseListeners, self, event) # stop event falling through esp. for drag on image DOM.eventPreventDefault(event) else: Hyperlink.onBrowserEvent(self, event)
def onMouseWheel(self, sender, x, y): event = DOM.eventGetCurrentEvent() DOM.eventPreventDefault(event) if self.getCurve(self.SELECTION_CURVE).isVisible(): if event.isNorth(): self.zoomIn() elif event.isSouth(): self.zoomOut()
def onBrowserEvent(self, event): etype = DOM.eventGetType(event) if etype == "mousewheel": if self._mouseWheelPreventDefault: DOM.eventPreventDefault(event) velocity = DOM.eventGetMouseWheelVelocityY(event) for listener in self._mouseWheelListeners: listener.onMouseWheel(self, velocity) return True
def onMouseUp(self, sender, x, y): event = DOM.eventGetCurrentEvent() DOM.eventPreventDefault(event) if self.selecting or self.moving: self.p2.x = self.getXAxis().getMouseCoordinate() self.p2.y = self.getYAxis().getMouseCoordinate() self.updateCursor() self.selecting = False self.moving = False
def onDragOver(self, event): if getWorkspace().getMovingBlock() is None: return dt = event.dataTransfer dt.dropEffect = 'copy' if hasattr(getWorkspace().getMovingBlock(), 'original'): if not getWorkspace().getMovingBlock().original: self.addStyleName('dragover') self.trashCan.setStyleName('trashCanOpen') DOM.eventPreventDefault(event)
def onMouseDown(self, sender, x, y): # regardless of drag_enabled, onMouseDown must prevent # default, in order to avoid losing focus. DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) if not self.drag_enabled: return self.dragging = True DOM.setCapture(self.getElement()) self.moveControl(x + Window.getScrollLeft(), y + Window.getScrollTop())
def onDragOver(self, event): target = DOM.eventGetTarget(event) t = Widget(Element=target) dt = event.dataTransfer dt.dropEffect = 'copy' class_names = t.getStyleName() if class_names is not None: if 'drophere' in class_names: DOM.eventPreventDefault(event)
def onMouseDown(self, sender, x, y): # regardless of drag_enabled, onMouseDown must prevent # default, in order to avoid losing focus. DOM.eventPreventDefault(DOM.eventGetCurrentEvent()); if not self.drag_enabled: return self.dragging = True DOM.setCapture(self.getElement()) self.moveControl(x + Window.getScrollLeft(), y + Window.getScrollTop())
def onKeyPress(self, sender, keycode, modifiers): DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) #not needed if keycode == KeyboardListener.KEY_UP: self.nextContest() if keycode == KeyboardListener.KEY_DOWN: self.nextContest() if keycode == KeyboardListener.KEY_LEFT: self.nextSelection() if keycode == KeyboardListener.KEY_RIGHT: self.nextSelection()
def onMouseUp(self, sender, x, y): ev = DOM.eventGetCurrentEvent() # ignore right-button ups if DOM.eventGetButton(ev) != Event.BUTTON_LEFT: return DOM.eventPreventDefault(ev) # if we are dragging if self._isDragging(): # stop dragging on mouse up self._stopDragging()
def onMouseDown(self, sender, x, y): """ catch a mouse down for parent """ ev = DOM.eventGetCurrentEvent() # ignore right-button downs if DOM.eventGetButton(ev) != Event.BUTTON_LEFT: return DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) # parent will capture the mouse and handle the dragging from here self._splitpanel.startSplitterDrag(x, y)
def onElementContextmenu(self, sender, event): x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft( self.canvas.getElement()) y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop( self.canvas.getElement()) s = self.desc[self.elements.index(sender)] self.set_status('Contextmenue on Element ' + s + ' at ' + str(x) + ', ' + str(y)) DOM.eventCancelBubble(event, True) DOM.eventPreventDefault(event)
def onDrop(self, event): dt = event.dataTransfer #'text', 'text/plain', and 'Text' are equivalent. try: item = dt.getData("text/plain") self.addMessage(item) except: self.addMessage('unsupported data type') DOM.eventPreventDefault(event)
def onDragEnter(self, event): target = DOM.eventGetTarget(event) t = Widget(Element=target) try: class_names = t.getStyleName() except: class_names = None if class_names is not None: if 'drophere' in class_names: t.addStyleName('dragover') DOM.eventPreventDefault(event)
def onKeyDown(self, sender, keycode, modifiers): if keycode == KeyboardListener.KEY_UP: DOM.eventPreventDefault(DOM.eventGetCurrentEvent()); new_value = self.processValue(self.value + self.step) self.setControlPos(new_value) self.setValue(new_value) elif keycode == KeyboardListener.KEY_DOWN: DOM.eventPreventDefault(DOM.eventGetCurrentEvent()); new_value = self.processValue(self.value - self.step) self.setControlPos(new_value) self.setValue(new_value)
def onEventPreview(self, event): # preventDefault on mousedown events, outside of the # dialog, to stop text-selection on dragging type = DOM.eventGetType(event) if type == "mousedown": target = DOM.eventGetTarget(event) elem = self.caption.getElement() event_targets_popup = target and DOM.isOrHasChild(elem, target) if event_targets_popup: DOM.eventPreventDefault(event) return PopupPanel.onEventPreview(self, event)
def onDragOver(self, event): target = DOM.eventGetTarget(event) t = Widget(Element=target) class_names = t.getStyleName() if class_names is not None: if 'drophere' in class_names: dt = event.dataTransfer id = Widget(Element=target).getID() drop_effect = self.data[int(id[-1])] dt.dropEffect = drop_effect DOM.eventPreventDefault(event)
def onDrop(self, event): dt = event.dataTransfer text = dt.getData('Text') target = DOM.eventGetTarget(event) t = Widget(Element=target) class_names = t.getStyleName() if class_names is not None: if 'drophere' in class_names: self.addMessage('%s onto %s<br>effectAllowed=%s, dropEffect=%s' % (text, target.id, dt.effectAllowed, dt.dropEffect)) DOM.eventPreventDefault(event)
def onKeyDown(self, sender, keycode, modifiers): if keycode == KeyboardListener.KEY_UP: DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) new_value = self.processValue(self.value + self.step) self.setControlPos(new_value) self.setValue(new_value) elif keycode == KeyboardListener.KEY_DOWN: DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) new_value = self.processValue(self.value - self.step) self.setControlPos(new_value) self.setValue(new_value)
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 onEventPreview(self, event): # preventDefault on mousedown events, outside of the # dialog, to stop text-selection on dragging type = DOM.eventGetType(event) if type == 'mousedown': target = DOM.eventGetTarget(event) elem = self.caption.getElement() event_targets_popup = target and DOM.isOrHasChild(elem, target) if event_targets_popup: DOM.eventPreventDefault(event) return PopupPanel.onEventPreview(self, event)
def onDrop(self, event): dt = event.dataTransfer text = dt.getData('Text') target = DOM.eventGetTarget(event) t = Widget(Element=target) class_names = t.getStyleName() DOM.eventPreventDefault(event) if class_names is not None: if 'drophere' in class_names: self.addMessage('%s onto %s' % (text, target.id)) return
def onEventPreview(self, event): # preventDefault on mousedown events, outside of the # dialog, to stop text-selection on dragging type = DOM.eventGetType(event) print "onEventPreview", event, type if type == 'mousedown': target = DOM.eventGetTarget(event) event_targets_control = target and DOM.isOrHasChild(self.getElement(), target) print "onEventPreview", target, event_targets_control if event_targets_control: DOM.eventPreventDefault(event) return VerticalSliderDemo.onEventPreview(self, event)
def setKey(self, k, set): DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) if k == KeyboardListener.KEY_UP: self.key_up = set elif k == KeyboardListener.KEY_DOWN: self.key_down = set elif k == KeyboardListener.KEY_LEFT: self.key_left = set elif k == KeyboardListener.KEY_RIGHT: self.key_right = set elif k == 32: self.key_fire = set
def setKey(self, k, set): DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) if k == 38: self.controller.key_up = set elif k == 40: self.controller.key_down = set elif k == 37: self.controller.key_left = set elif k == 39: self.controller.key_right = set elif k == 32: self.controller.key_fire = set
def onKeyPress(self, sender, keycode, modifiers): if keycode == KeyboardListener.KEY_ENTER: DOM.eventPreventDefault(DOM.eventGetCurrentEvent()); txt = self.input.getText() if not txt: return new_value = float(txt) new_value = self.processValue(new_value) self.setControlPos(new_value) self.setValue(new_value) else: Control.onKeyPress(self, sender, keycode, modifiers)
def onKeyPress(self, sender, keycode, modifiers): if keycode == KeyboardListener.KEY_ENTER: DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) txt = self.input.getText() if not txt: return new_value = float(txt) new_value = self.processValue(new_value) self.setControlPos(new_value) self.setValue(new_value) else: Control.onKeyPress(self, sender, keycode, modifiers)
def onDrop(self, event): if getWorkspace().getMovingBlock() is None: return self.removeStyleName('dragover') if hasattr(getWorkspace().getMovingBlock(), 'original'): if not getWorkspace().getMovingBlock().original: getWorkspace().getMovingBlock().removeFromParent() del hardwares[getWorkspace().getMovingBlock().getCompleteText( )] # remove da lista de componentes getWorkspace().setMovingBlock(None) from edu.uca.util.Serializable import stateChange stateChange() self.trashCan.setStyleName("trashCanClose") DOM.eventPreventDefault(event)