def _create_drag_event(self, event):

        # If the control no longer exists, don't send mouse event
        if self.control is None:
            return None
        # If the event (if there is one) doesn't contain the mouse position,
        # modifiers and buttons then get sensible defaults.
        try:
            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
                        from apptools.io.api import File
                        obj = [File(path=path) for path in files]
                    except ImportError:
                        pass

        return DragEvent(x=x,
                         y=self._flip_y(y),
                         obj=obj,
                         copy=copy,
                         window=self,
                         mimedata=mimedata)
示例#2
0
 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
示例#3
0
    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
示例#4
0
    def wx_drag_over(self, x, y, drag_object, drag_result):
        y = self._flip_y(y)
        drag_over_event = DragEvent(x=x,
                                    y=y,
                                    x0=0.0,
                                    y0=0.0,
                                    copy=drag_result != wx.DragMove,
                                    obj=drag_object,
                                    start_event=default_start_event,
                                    window=self)

        # By default, don't indicate that we can be dropped on.  It is up
        # to the component to set this correctly.
        self._drag_result = wx.DragNone
        if self.component.is_in(x, y):
            self.component.dispatch(drag_over_event, "drag_over")

        return self._drag_result
    def create_drag_event(self, **kwargs):
        """ Creates a DragEvent() with the specified attributes.

        """
        event = DragEvent(**kwargs)
        return event