Ejemplo n.º 1
0
def fireMouseEvent(listeners, sender, event):
    x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(sender.getElement())
    y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(sender.getElement())

    etype = DOM.eventGetType(event)
    if etype == "mousedown":
        for listener in listeners:
            listener.onMouseDown(sender, x, y)
        return True
    elif etype == "mouseup":
        for listener in listeners:
            listener.onMouseUp(sender, x, y)
        return True
    elif etype == "mousemove":
        for listener in listeners:
            listener.onMouseMove(sender, x, y)
        return True
    elif etype == "mouseover":
        to_element = DOM.eventGetToElement(event)
        if to_element and not DOM.isOrHasChild(sender.getElement(),
                                               to_element):
            for listener in listeners:
                listener.onMouseEnter(sender)
        return True
    elif etype == "mouseout":
        to_element = DOM.eventGetToElement(event)
        if to_element and not DOM.isOrHasChild(sender.getElement(),
                                               to_element):
            for listener in listeners:
                listener.onMouseLeave(sender)
        return True
    return False
Ejemplo n.º 2
0
def fireMouseEvent(listeners, sender, event):
    x = DOM.eventGetClientX(event) - DOM.getAbsoluteLeft(sender.getElement())
    y = DOM.eventGetClientY(event) - DOM.getAbsoluteTop(sender.getElement())

    etype = DOM.eventGetType(event)
    if etype == "mousedown":
        for listener in listeners:
            listener.onMouseDown(sender, x, y)
        return True
    elif etype == "mouseup":
        for listener in listeners:
            listener.onMouseUp(sender, x, y)
        return True
    elif etype == "mousemove":
        for listener in listeners:
            listener.onMouseMove(sender, x, y)
        return True
    elif etype == "mouseover":
        to_element = DOM.eventGetToElement(event)
        if to_element and not DOM.isOrHasChild(sender.getElement(), to_element):
            for listener in listeners:
                listener.onMouseEnter(sender)
        return True
    elif etype == "mouseout":
        to_element = DOM.eventGetToElement(event)
        if to_element and not DOM.isOrHasChild(sender.getElement(), to_element):
            for listener in listeners:
                listener.onMouseLeave(sender)
        return True
    return False
Ejemplo n.º 3
0
    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()
Ejemplo n.º 4
0
    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()