How to use the enable.events.DragEvent function in enable

To help you get started, we’ve selected a few enable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / enable / enable / testing.py View on Github external
def create_drag_event(self, **kwargs):
        """ Creates a DragEvent() with the specified attributes.

        """
        event = DragEvent(**kwargs)
        return event
github enthought / enable / enable / container.py View on Github external
caller=self)

            try:
                new_component_set = set(components)

                # For "real" mouse events (i.e., not pre_mouse_* events),
                # notify the previous listening components of a mouse or
                # drag leave
                if not suffix.startswith("pre_"):
                    components_left = self._prev_event_handlers - new_component_set
                    if components_left:
                        leave_event = None
                        if isinstance(event, MouseEvent):
                            leave_event = event
                            leave_suffix = "mouse_leave"
                        elif isinstance(event, DragEvent):
                            leave_event = event
                            leave_suffix = "drag_leave"
                        elif isinstance(event, (BlobEvent, BlobFrameEvent)):
                            # Do not generate a 'leave' event.
                            pass
                        else:
                            # TODO: think of a better way to handle this rare case?
                            leave_event = MouseEvent(x=event.x, y=event.y,
                                                     window=event.window)
                            leave_suffix = "mouse_leave"

                        if leave_event is not None:
                            for component in components_left:
                                component.dispatch(leave_event, "pre_" + leave_suffix)
                                component.dispatch(leave_event, leave_suffix)
                                event.handled = False
github enthought / enable / enable / qt4 / base_window.py View on Github external
x = event.x()
            y = event.y()
        except AttributeError:
            pos = self.control.mapFromGlobal(QtGui.QCursor.pos())
            x = pos.x()
            y = pos.y()

        self.control.handler.last_mouse_pos = (x, y)

        # extract an object from the event, if we can
        try:
            mimedata = event.mimeData()
            copy = event.proposedAction() == QtCore.Qt.CopyAction
        except AttributeError:
            # this is a DragLeave event
            return DragEvent(x=x, y=self._flip_y(y), obj=None, copy=False,
                        window=self, mimedata=None)

        try:
            from traitsui.qt4.clipboard import PyMimeData
        except ImportError:
            # traitsui isn't available, just make mimedata available on event
            obj = None
        else:
            mimedata = PyMimeData.coerce(mimedata)
            obj = mimedata.instance()
            if obj is None:
                files = mimedata.localPaths()
                if files:
                    try:
                        # try to extract file info from mimedata
                        # XXX this is for compatibility with what wx does
github enthought / enable / enable / container.py View on Github external
for component in components_left:
                                component.dispatch(leave_event, "pre_" + leave_suffix)
                                component.dispatch(leave_event, leave_suffix)
                                event.handled = False

                    # Notify new components of a mouse enter, if the event is
                    # not a mouse_leave or a drag_leave
                    if suffix not in ("mouse_leave", "drag_leave"):
                        components_entered = \
                            new_component_set - self._prev_event_handlers
                        if components_entered:
                            enter_event = None
                            if isinstance(event, MouseEvent):
                                enter_event = event
                                enter_suffix = "mouse_enter"
                            elif isinstance(event, DragEvent):
                                enter_event = event
                                enter_suffix = "drag_enter"
                            elif isinstance(event, (BlobEvent, BlobFrameEvent)):
                                # Do not generate an 'enter' event.
                                pass
                            if enter_event:
                                for component in components_entered:
                                    component.dispatch(enter_event, "pre_" + enter_suffix)
                                    component.dispatch(enter_event, enter_suffix)
                                    event.handled = False

                # Handle the actual event
                # Only add event handlers to the list of previous event handlers
                # if they actually receive the event (and the event is not a
                # pre_* event.
                if not suffix.startswith("pre_"):
github enthought / enable / enable / drag.py View on Github external
dx = drag_bounds_rect[0] - self.drag_bounds_rect_start[0]
        dy = drag_bounds_rect[1] - self.drag_bounds_rect_start[1]
        for component in components:
            cx, cy = component.location()
            component.dropped = DragEvent( x  = cx + dx,
                                           y  = cy + dy,
                                           x0 = self.start_x,
                                           y0 = self.start_y,
                                           copy        = drag_copy,
                                           components  = components,
                                           start_event = start_event,
                                           window = event.window )

        # Process the 'dropped_on' event for the object(s) it was dropped on:
        components_at = self.drag_root.components_at( x, y )
        drag_event    = DragEvent( x           = self.start_x + dx,
                                   y           = self.start_y + dy,
                                   x0          = self.start_x,
                                   y0          = self.start_y,
                                   copy        = drag_copy,
                                   components  = components,
                                   start_event = start_event,
                                   window = event.window )
        index = send_event_to( components_at, 'dropped_on', drag_event )

        # Send all the runner-ups a 'drag_leave' consolation prize:
        drag_over = self.drag_over
        for component in components_at[ 0: index ]:
            if component in drag_over:
                component.drag_leave = drag_event

        # Make sure all of the dragged components are drawable again:
github enthought / enable / enable / wx / base_window.py View on Github external
def wx_dropped_on ( self, x, y, drag_object, drop_result ):
        "Handle wxPython drag and drop events"
        # Process the 'dropped_on' event for the object(s) it was dropped on:
        y = self._flip_y(y)
        drag_event = DragEvent(x=x, y=y, obj=drag_object, window=self)
        self._drag_result = wx.DragNone
        if self.component.is_in(x, y):
            self.component.dispatch(drag_event, "dropped_on")

        # If a downstream component wants to express that it handled the
        return self._drag_result
github enthought / enable / enable / drag.py View on Github external
# Notify each drag component of its new drag location:
        dx = drag_bounds_rect[0] - self.drag_bounds_rect_start[0]
        dy = drag_bounds_rect[1] - self.drag_bounds_rect_start[1]
        for component in self.components:
            cx, cy = component.location()
            component.dragged = DragEvent( x  = cx + dx,
                                           y  = cy + dy,
                                           x0 = self.start_x,
                                           y0 = self.start_y,
                                           copy        = self.drag_copy,
                                           components  = self.components,
                                           start_event = self.start_event,
                                           window = event.window )

        # Process the 'drag_over' events for any objects being dragged over:
        drag_over_event = DragEvent( x  = x,
                                     y  = y,
                                     x0 = self.start_x,
                                     y0 = self.start_y,
                                     copy        = self.drag_copy,
                                     components  = self.components,
                                     start_event = self.start_event,
                                     window = event.window )
        new_drag_over = []
        cur_drag_over = self.drag_over
        for component in self.drag_root.components_at( x, y ):
            new_drag_over.append( component )
            if component in cur_drag_over:
                cur_drag_over.remove( component )
                component.drag_over = drag_over_event
            else:
                component.drag_enter = drag_over_event
github enthought / enable / enable / wx / base_window.py View on Github external
def wx_drag_leave ( self, drag_object ):
        drag_leave_event = DragEvent( x    = 0.0,
                                     y    = 0.0,
                                     x0   = 0.0,
                                     y0   = 0.0,
                                     copy = False,
                                     obj = drag_object,
                                     start_event = default_start_event,
                                     window = self )
        self.component.dispatch(drag_leave_event, "drag_leave")
        return
github enthought / enable / enable / events.py View on Github external
""" A system UI drag-and-drop operation.  This is not the same as a
    DragTool event.
    """
    x0   = Float
    y0   = Float
    copy = ReadOnly
    obj  = ReadOnly
    start_event = ReadOnly

    def __repr__(self):
        s = ('%s(x=%r, y=%r, x0=%r, y0=%r, handled=%r)' %
            (self.__class__.__name__, self.x, self.y, self.x0, self.y0,
                self.handled))
        return s

drag_event_trait = Event(DragEvent)


class KeyEvent(BasicEvent):
    event_type   = ReadOnly    # one of 'key_pressed', 'key_released' or 'character'

    # 'character' is a single unicode character or is a string describing the
    # high-bit and control characters.  (See module enable.toolkit_constants)
    # depending on the event type, it may represent the physical key pressed,
    # or the text that was generated by a keystroke
    character    = ReadOnly

    alt_down     = ReadOnly
    control_down = ReadOnly
    shift_down   = ReadOnly

    event        = ReadOnly    # XXX the underlying toolkit's event object, remove?