File: events.py

package info (click to toggle)
python-vispy 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,868 kB
  • sloc: python: 59,799; javascript: 6,800; makefile: 69; sh: 6
file content (85 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.

from __future__ import division

from ..util.event import Event


class SceneMouseEvent(Event):
    """Represents a mouse event that occurred on a SceneCanvas. This event is
    delivered to all entities whose mouse interaction area is under the event.
    """

    def __init__(self, event, visual):
        self.mouse_event = event
        self.visual = visual
        Event.__init__(self, type=event.type)

    @property
    def visual(self):
        return self._visual

    @visual.setter
    def visual(self, v):
        self._visual = v
        self._pos = None

    @property
    def pos(self):
        """The position of this event in the local coordinate system of the
        visual.
        """
        if self._pos is None:
            tr = self.visual.get_transform('canvas', 'visual')
            self._pos = tr.map(self.mouse_event.pos)
        return self._pos

    @property
    def last_event(self):
        """The mouse event immediately prior to this one. This
        property is None when no mouse buttons are pressed.
        """
        if self.mouse_event.last_event is None:
            return None
        ev = self.copy()
        ev.mouse_event = self.mouse_event.last_event
        return ev

    @property
    def press_event(self):
        """The mouse press event that initiated a mouse drag, if any."""
        if self.mouse_event.press_event is None:
            return None
        ev = self.copy()
        ev.mouse_event = self.mouse_event.press_event
        return ev

    @property
    def button(self):
        """The button pressed or released on this event."""
        return self.mouse_event.button

    @property
    def buttons(self):
        """A list of all buttons currently pressed on the mouse."""
        return self.mouse_event.buttons

    @property
    def delta(self):
        """The increment by which the mouse wheel has moved."""
        return self.mouse_event.delta

    @property
    def scale(self):
        """The scale of a gesture_zoom event"""
        try:
            return self.mouse_event.scale
        except AttributeError:
            errmsg = f"SceneMouseEvent type '{self.type}' has no scale"
            raise TypeError(errmsg)

    def copy(self):
        ev = self.__class__(self.mouse_event, self.visual)
        return ev