def onEventPreview(self, event): type = DOM.eventGetType(event) if type == "keydown": return (self.onKeyDownPreview( DOM.eventGetKeyCode(event), KeyboardListener.getKeyboardModifiers(event)) and (not self.modal or self._event_targets_popup(event))) elif type == "keyup": return (self.onKeyUpPreview( DOM.eventGetKeyCode(event), KeyboardListener.getKeyboardModifiers(event)) and (not self.modal or self._event_targets_popup(event))) elif type == "keypress": return (self.onKeyPressPreview( DOM.eventGetKeyCode(event), KeyboardListener.getKeyboardModifiers(event)) and (not self.modal or self._event_targets_popup(event))) elif (type == "mousedown" or type == "blur"): if DOM.getCaptureElement() is not None: return True if self.autoHide and not self._event_targets_popup(event): self.hide(True) return True elif (type == "mouseup" or type == "click" or type == "mousemove" or type == "dblclick"): if DOM.getCaptureElement() is not None: return True return not self.modal or self._event_targets_popup(event)
def onBrowserEvent(self, event): etype = DOM.eventGetType(event) if etype == "click": e = DOM.eventGetTarget(event) if not self.shouldTreeDelegateFocusToElement(e) and \ self.curSelection is not None: self.setFocus(True) elif etype in MouseListener.MOUSE_EVENTS: if etype == "mousedown": self.elementClicked(self.root, DOM.eventGetTarget(event)) MouseListener.fireMouseEvent(self.mouseListeners, self, event) elif etype == "blur" or etype == "focus": FocusListener.fireFocusEvent(self.focusListeners, self, event) elif etype == "keydown": if self.curSelection is None: if self.root.getChildCount() > 0: self.onSelection(self.root.getChild(0), True) Widget.onBrowserEvent(self, event) return if self.lastEventType == "keydown": return keycode = DOM.eventGetKeyCode(event) if keycode == KeyboardListener.KEY_UP: self.moveSelectionUp(self.curSelection, True) DOM.eventPreventDefault(event) elif keycode == KeyboardListener.KEY_DOWN: self.moveSelectionDown(self.curSelection, True) DOM.eventPreventDefault(event) elif keycode == KeyboardListener.KEY_LEFT: if self.curSelection.getState(): self.curSelection.setState(False) DOM.eventPreventDefault(event) elif keycode == KeyboardListener.KEY_RIGHT: if not self.curSelection.getState(): self.curSelection.setState(True) DOM.eventPreventDefault(event) elif etype == "keyup": if DOM.eventGetKeyCode(event) == KeyboardListener.KEY_TAB: chain = [] self.collectElementChain(chain, self.getElement(), DOM.eventGetTarget(event)) item = self.findItemByChain(chain, 0, self.root) if item != self.getSelectedItem(): self.setSelectedItem(item, True) elif etype == "keypress": KeyboardListener.fireKeyboardEvent(self.keyboardListeners, self, event) Widget.onBrowserEvent(self, event) self.lastEventType = etype
def onBrowserEvent(self, event) : type = DOM.eventGetType(event) if type == "click": self.onClick(self) elif type == "keydown": modifiers = KeyboardListener.getKeyboardModifiers(event) if hasattr(self.keyDelegate, "onKeyDown"): self.keyDelegate.onKeyDown(self, DOM.eventGetKeyCode(event), modifiers)
def onEventPreview(self, event): type = DOM.eventGetType(event) if type == "keydown": return ( self.onKeyDownPreview( DOM.eventGetKeyCode(event), KeyboardListener.getKeyboardModifiers(event) ) and (not self.modal or self._event_targets_popup(event)) ) elif type == "keyup": return ( self.onKeyUpPreview( DOM.eventGetKeyCode(event), KeyboardListener.getKeyboardModifiers(event) ) and (not self.modal or self._event_targets_popup(event)) ) elif type == "keypress": return ( self.onKeyPressPreview( DOM.eventGetKeyCode(event), KeyboardListener.getKeyboardModifiers(event) ) and (not self.modal or self._event_targets_popup(event)) ) elif ( type == "mousedown" or type == "blur" ): if DOM.getCaptureElement() is not None: return True if self.autoHide and not self._event_targets_popup(event): self.hide(True) return True elif ( type == "mouseup" or type == "click" or type == "mousemove" or type == "dblclick" ): if DOM.getCaptureElement() is not None: return True return not self.modal or self._event_targets_popup(event)
def fireKeyboardEvent(listeners, sender, event): modifiers = getKeyboardModifiers(event) keycode = DOM.eventGetKeyCode(event) type = DOM.eventGetType(event) if type == "keydown": for listener in listeners: listener.onKeyDown(sender, keycode, modifiers) elif type == "keyup": for listener in listeners: listener.onKeyUp(sender, keycode, modifiers) elif type == "keypress": for listener in listeners: listener.onKeyPress(sender, keycode, modifiers)
def onBrowserEvent(self, event): # Should not act on button if disabled. if not self.isEnabled(): # This can happen when events are bubbled up from # non-disabled children return event_type = DOM.eventGetType(event) if event_type == "click": # If clicks are currently disallowed, keep it from bubbling or # being passed to the superclass. if not self.allowClick: DOM.eventStopPropagation(event) return elif event_type == "mousedown": if DOM.eventGetButton(event) == Event.BUTTON_LEFT: self.setFocus(True) self.onClickStart() DOM.setCapture(self.getElement()) self.isCapturing = True # Prevent dragging (on some browsers) DOM.eventPreventDefault(event) elif event_type == "mouseup": if self.isCapturing: self.isCapturing = False DOM.releaseCapture(self.getElement()) if self.isHovering() and \ DOM.eventGetButton(event) == Event.BUTTON_LEFT: self.onClick() elif event_type == "mousemove": if self.isCapturing: # Prevent dragging (on other browsers) DOM.eventPreventDefault(event) elif event_type == "mouseout": to = DOM.eventGetToElement(event) if (DOM.isOrHasChild(self.getElement(), DOM.eventGetTarget(event)) and (to is None or not DOM.isOrHasChild(self.getElement(), to))): if self.isCapturing: self.onClickCancel() self.setHovering(False) elif event_type == "mouseover": if DOM.isOrHasChild(self.getElement(), DOM.eventGetTarget(event)): self.setHovering(True) if self.isCapturing: self.onClickStart() elif event_type == "blur": if self.isFocusing: self.isFocusing = False self.onClickCancel() elif event_type == "losecapture": if self.isCapturing: self.isCapturing = False self.onClickCancel() ButtonBase.onBrowserEvent(self, event) # Synthesize clicks based on keyboard events AFTER the normal # key handling. if (DOM.eventGetTypeInt(event) & Event.KEYEVENTS) == 0: return keyCode = DOM.eventGetKeyCode(event) if event_type == "keydown": if keyCode == ' ': self.isFocusing = True self.onClickStart() elif event_type == "keyup": if self.isFocusing and keyCode == ' ': self.isFocusing = False self.onClick() elif event_type == "keypress": if keyCode == '\n' or keyCode == '\r': self.onClickStart() self.onClick()
def onBrowserEvent(self, event): # Should not act on button if disabled. if not self.getEnabled(): # This can happen when events are bubbled up from # non-disabled children return event_type = DOM.eventGetType(event) if event_type == "click": # If clicks are currently disallowed, keep it from bubbling or # being passed to the superclass. if not self.allowClick: DOM.eventStopPropagation(event) return elif event_type == "mousedown": if DOM.eventGetButton(event) == Event.BUTTON_LEFT: self.setFocus(True) self.onClickStart() DOM.setCapture(self.getElement()) self.isCapturing = True # Prevent dragging (on some browsers) DOM.eventPreventDefault(event) elif event_type == "mouseup": if self.isCapturing: self.isCapturing = False DOM.releaseCapture(self.getElement()) if self.isHovering() and \ DOM.eventGetButton(event) == Event.BUTTON_LEFT: self.onClick() elif event_type == "mousemove": if self.isCapturing: # Prevent dragging (on other browsers) DOM.eventPreventDefault(event) elif event_type == "mouseout": to = DOM.eventGetToElement(event) if (DOM.isOrHasChild(self.getElement(), DOM.eventGetTarget(event)) and (to is None or not DOM.isOrHasChild(self.getElement(), to))): if self.isCapturing: self.onClickCancel() self.setHovering(False) elif event_type == "mouseover": if DOM.isOrHasChild(self.getElement(), DOM.eventGetTarget(event)): self.setHovering(True) if self.isCapturing: self.onClickStart() elif event_type == "blur": if self.isFocusing: self.isFocusing = False self.onClickCancel() elif event_type == "losecapture": if self.isCapturing: self.isCapturing = False self.onClickCancel() ButtonBase.onBrowserEvent(self, event) # Synthesize clicks based on keyboard events AFTER the normal # key handling. if (DOM.eventGetTypeInt(event) & Event.KEYEVENTS) == 0: return keyCode = DOM.eventGetKeyCode(event) if event_type == "keydown": if keyCode == ' ': self.isFocusing = True self.onClickStart() elif event_type == "keyup": if self.isFocusing and keyCode == ' ': self.isFocusing = False self.onClick() elif event_type == "keypress": if keyCode == '\n' or keyCode == '\r': self.onClickStart() self.onClick()