Пример #1
0
    def test_mouse_clock(self):
        x, y = 0, 0
        scroll_x, scroll_y = 1, 1
        dx, dy = 1, 1
        zeros = [0, 0, 0]
        for b in [
                pyglet.window.mouse.LEFT, pyglet.window.mouse.MIDDLE,
                pyglet.window.mouse.RIGHT
        ]:
            event.mouseButtons = copy.copy(zeros)
            event.mouseTimes = copy.copy(zeros)
            event._onPygletMousePress(x, y, b, None)
            assert event.mouseButtons != zeros
            assert event.mouseTimes != zeros
            event._onPygletMouseRelease(x, y, b, None)
            assert event.mouseButtons == zeros
        event._onPygletMouseWheel(x, y, scroll_x, scroll_y)
        event._onPygletMouseMotion(x, y, dx, dy)
        event.startMoveClock()
        event.stopMoveClock()
        event.resetMoveClock()

        m = event.Mouse()
        assert m.mouseMoveTime() >= 0
        t = 0.05
        core.wait(t)
        assert t - 0.01 < m.mouseMoveTime() < t + 0.01
Пример #2
0
    def onMouseButtonRelease(self, *args, **kwargs):
        """Event handler for mouse press events."""
        # don't process mouse events until ready
        mouseEventHandler = mouse.Mouse.getInstance()
        if mouseEventHandler is None:
            event._onPygletMouseRelease(*args, **kwargs)
            return

        x, y, button, _ = args
        absTime = core.getTime()
        absPos = self._windowCoordsToPix((x, y))
        mouseEventHandler.win = self.win
        mouseEventHandler.setMouseButtonState(_PYGLET_MOUSE_BUTTONS_[button],
                                              False, absPos, absTime)
Пример #3
0
    def test_emulated_mouse(self):
        mouse = event.Mouse()  # real mouse
        event.mouseButtons = [0,0,0]
        [c.reset() for c in event.mouseClick]  # mouse click RT clocks
        assert not any(event.mouseButtons)
        assert not any(event.mouseTimes)

        # fake clicks on all buttons:
        event._onPygletMousePress(0, 0, LEFT | MIDDLE | RIGHT, None, emulated=True)
        assert all(mouse.getPressed())
        assert all([RT < 0.01 for RT in event.mouseTimes])  # should be < .0001

        # fake release all buttons:
        event._onPygletMouseRelease(0, 0, LEFT | MIDDLE | RIGHT, None, emulated=True)
        assert not any(event.mouseButtons)
Пример #4
0
 def test_mouse_clock(self):
     x, y = 0, 0
     scroll_x, scroll_y = 1, 1
     dx, dy = 1, 1
     zeros = [0, 0, 0]
     for b in [pyglet.window.mouse.LEFT, pyglet.window.mouse.MIDDLE, pyglet.window.mouse.RIGHT]:
         event.mouseButtons = copy.copy(zeros)
         event.mouseTimes = copy.copy(zeros)
         event._onPygletMousePress(x,y, b, None)
         assert event.mouseButtons != zeros
         assert event.mouseTimes != zeros
         event._onPygletMouseRelease(x,y, b, None)
         assert event.mouseButtons == zeros
     event._onPygletMouseWheel(x,y,scroll_x, scroll_y)
     event._onPygletMouseMotion(x, y, dx, dy)
     event.startMoveClock()
     event.stopMoveClock()
     event.resetMoveClock()