コード例 #1
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     drag = QDrag(event.widget())
     mime = QMimeData()
     mime.setText(str(self.id))
     drag.setMimeData(mime)
     # self.setCursor(Qt.ClosedHandCursor)
     drag.exec_()
コード例 #2
0
    def mouseMoveEvent(self, event):
        if (self._clickPos is None
                or (event.pos() - self._clickPos).manhattanLength() <
                QApplication.startDragDistance()):
            return

        # _log.debug("Drag move")
        # render before detachment otherwise it might look ugly
        pixmap = QPixmap(self.size())
        self.render(pixmap)

        self.setVisible(False)
        if len(self._dock.parentContainer.flatDockList) == 1:
            self._dock.parentContainer.setVisible(False)

        # Build drag object
        event.accept()
        drag = QDrag(self)
        mimeData = QMimeData()
        encodedData = QByteArray(pickle.dumps(self._dock.uid))
        mimeData.setData(MIME_TYPE, encodedData)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        action = drag.exec_(Qt.MoveAction)

        _log.debug("After drag. Action: {}".format(action))
        if Qt.IgnoreAction == action:
            _log.debug("D'n'D canceled")
            self.setVisible(True)
            self._dock.parentContainer.setVisible(True)
コード例 #3
0
 def startDrag(self, dropActions):
     """Reimplement Qt Method - handle drag event"""
     data = QMimeData()
     data.setUrls([QUrl(fname) for fname in self.get_selected_filenames()])
     drag = QDrag(self)
     drag.setMimeData(data)
     drag.exec_()
コード例 #4
0
ファイル: explorer.py プロジェクト: ShenggaoZhu/spyder
 def startDrag(self, dropActions):
     """Reimplement Qt Method - handle drag event"""
     data = QMimeData()
     data.setUrls([QUrl(fname) for fname in self.get_selected_filenames()])
     drag = QDrag(self)
     drag.setMimeData(data)
     drag.exec_()
コード例 #5
0
 def mouseMoveEvent(self, event):
     """Override Qt method"""
     if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \
        (event.pos() - self.__drag_start_pos).manhattanLength() > \
             QApplication.startDragDistance():
         drag = QDrag(self)
         mimeData = QMimeData()
         # Converting id's to long to avoid an OverflowError with PySide
         if PY2:
             ancestor_id = long(id(self.ancestor))
             parent_widget_id = long(id(self.parentWidget()))
             self_id = long(id(self))
         else:
             ancestor_id = id(self.ancestor)
             parent_widget_id = id(self.parentWidget())
             self_id = id(self)
         mimeData.setData("parent-id", QByteArray.number(ancestor_id))
         mimeData.setData("tabwidget-id",
                          QByteArray.number(parent_widget_id))
         mimeData.setData("tabbar-id", QByteArray.number(self_id))
         mimeData.setData(
             "source-index",
             QByteArray.number(self.tabAt(self.__drag_start_pos)))
         drag.setMimeData(mimeData)
         drag.exec_()
     QTabBar.mouseMoveEvent(self, event)
コード例 #6
0
ファイル: qt_layerlist.py プロジェクト: samuelorion/napari
    def mouseMoveEvent(self, event):
        """Drag and drop layer with mouse movement.

        Parameters
        ----------
        event : qtpy.QtCore.QEvent
            Event from the Qt context.
        """
        position = np.array([event.pos().x(), event.pos().y()])
        distance = np.linalg.norm(position - self._drag_start_position)
        if (distance < QApplication.startDragDistance()
                or self._drag_name is None):
            return
        mimeData = QMimeData()
        mimeData.setText(self._drag_name)
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(event.pos() - self.rect().topLeft())
        drag.exec_()
        # Check if dragged layer still exists or was deleted during drag
        names = [layer.name for layer in self.layers]
        dragged_layer_exists = self._drag_name in names
        if self._drag_name is not None and dragged_layer_exists:
            index = self.layers.index(self._drag_name)
            layer = self.layers[index]
            self._ensure_visible(layer)
コード例 #7
0
    def mouseMoveEvent(self, event):
        distance = (event.pos() - self.dragStartPosition).manhattanLength()
        if distance < QApplication.startDragDistance():
            return
        mimeData = QMimeData()
        if not self.layer.selected:
            name = self.layer.name
        else:
            name = ''
            for layer in self.layer.viewer.layers:
                if layer.selected:
                    name = layer.name + '; ' + name
            name = name[:-2]
        mimeData.setText(name)
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(event.pos() - self.rect().topLeft())
        dropAction = drag.exec_(Qt.MoveAction | Qt.CopyAction)

        if dropAction == Qt.CopyAction:
            if not self.layer.selected:
                index = self.layer.viewer.layers.index(self.layer)
                self.layer.viewer.layers.pop(index)
            else:
                self.layer.viewer.layers.remove_selected()
コード例 #8
0
ファイル: test_codeeditor_1.py プロジェクト: impact27/spyder
def copy_files_clipboard(create_folders_files):
    """Fixture to copy files/folders into the clipboard"""
    file_paths = create_folders_files[0]
    file_content = QMimeData()
    file_content.setUrls([QUrl.fromLocalFile(fname) for fname in file_paths])
    cb = QApplication.clipboard()
    cb.setMimeData(file_content, mode=cb.Clipboard)
    return file_paths
コード例 #9
0
def copy_files_clipboard(create_folders_files):
    """Fixture to copy files/folders into the clipboard"""
    file_paths = create_folders_files[0]
    file_content = QMimeData()
    file_content.setUrls([QUrl.fromLocalFile(fname) for fname in file_paths])
    cb = QApplication.clipboard()
    cb.setMimeData(file_content, mode=cb.Clipboard)
    return file_paths
コード例 #10
0
ファイル: reactions_list.py プロジェクト: rmahadevan12/CNApy
 def mouseMoveEvent(self, _event):
     item = self.currentItem()
     if item is not None:
         reaction: cobra.Reaction = item.data(3, 0)
         mime_data = QMimeData()
         mime_data.setText(reaction.id)
         drag = QDrag(self)
         drag.setMimeData(mime_data)
         drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction)
コード例 #11
0
ファイル: scene.py プロジェクト: codecraftingtools/hildegard
def export_to_clipboard_as_svg(scene):
    print(f"exporting SVG to clipboard")
    buffer = QBuffer()
    svg_gen = QSvgGenerator()
    svg_gen.setOutputDevice(buffer)
    render_to_svggen(scene, svg_gen)
    data = QMimeData()
    data.setData("image/svg+xml", buffer.buffer())
    qApp.clipboard().setMimeData(data, QClipboard.Clipboard)
コード例 #12
0
ファイル: widgets.py プロジェクト: jmuhlich/ome-types
 def dropMimeData(self, parent: QTreeWidgetItem, index: int,
                  data: QMimeData, a) -> bool:
     if data.hasUrls():
         for url in data.urls():
             lf = url.toLocalFile()
             if lf.endswith((".xml", ".tiff", ".tif")):
                 self.update(lf)
                 return True
     return False
コード例 #13
0
ファイル: tabs.py プロジェクト: DLlearn/spyder
 def mouseMoveEvent(self, event):
     """Override Qt method"""
     if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \
        (event.pos() - self.__drag_start_pos).manhattanLength() > \
             QApplication.startDragDistance():
         drag = QDrag(self)
         mimeData = QMimeData()
         # Converting id's to long to avoid an OverflowError with PySide
         if PY2:
             ancestor_id = long(id(self.ancestor))
             parent_widget_id = long(id(self.parentWidget()))
             self_id = long(id(self))
         else:
             ancestor_id = id(self.ancestor)
             parent_widget_id = id(self.parentWidget())
             self_id = id(self)
         mimeData.setData("parent-id", QByteArray.number(ancestor_id))
         mimeData.setData("tabwidget-id",
                          QByteArray.number(parent_widget_id))
         mimeData.setData("tabbar-id", QByteArray.number(self_id))
         mimeData.setData("source-index", 
                      QByteArray.number(self.tabAt(self.__drag_start_pos)))
         drag.setMimeData(mimeData)
         drag.exec_()
     QTabBar.mouseMoveEvent(self, event)
コード例 #14
0
    def mimeData(self, indexes):
        self.indexes = [
            index.internalPointer() for index in indexes if index.column() == 0
        ]
        mimedata = QMimeData()
        mimedata.setData('application/x-qabstractitemmodeldatalist',
                         QByteArray())

        # run virtual function
        self.dragStartEvent(self.indexes)
        return mimedata
コード例 #15
0
 def mouseMoveEvent(self, event):
     position = np.array([event.pos().x(), event.pos().y()])
     distance = np.linalg.norm(position - self.drag_start_position)
     if (distance < QApplication.startDragDistance()
             or self.drag_name is None):
         return
     mimeData = QMimeData()
     mimeData.setText(self.drag_name)
     drag = QDrag(self)
     drag.setMimeData(mimeData)
     drag.setHotSpot(event.pos() - self.rect().topLeft())
     dropAction = drag.exec_()
コード例 #16
0
    def eventFilter(self, source, event):
        if isinstance(source, QListView):
            if event.type() == QEvent.KeyPress and event.key() == Qt.Key_C and event.modifiers() & Qt.ControlModifier:
                rows = sorted(source.selectionModel().selectedRows())
                data = QMimeData()
                data.setText("\n".join(str(source.model().data(row)) for row in rows))

                QApplication.instance().clipboard().setMimeData(data)

                return True

        return False
コード例 #17
0
    def _copy(self):
        '''
        Copies all of the selected items to the clipboard.
        '''
        # Copy the urls of the selected files to the clipboard.
        filePath = self._model.filePath
        urls = [QUrl.fromLocalFile(filePath(index)) for index in self._view.selectedIndexes()]

        mime_data = QMimeData()
        mime_data.setUrls(urls)

        clipboard = QApplication.clipboard()
        clipboard.setMimeData(mime_data)
コード例 #18
0
ファイル: filetree.py プロジェクト: hzyrc6011/pmgwidgets
    def on_copy(self):
        """
        copy file or dir , save path in pasteAction data.
        :return:
        """
        path = self.get_current_file_path()
        self.pasteAction.setEnabled(True)
        self.pasteAction.setData(path)

        data = QMimeData()
        data.setUrls([QUrl.fromLocalFile(path)])  # 复制到系统剪贴板

        clip = QApplication.clipboard()
        clip.setMimeData(data)
コード例 #19
0
    def mimeData(self, indexes):
        # type: (List[QModelIndex])
        """Function used for preparing tree data for drag+drop. Preserves the hierarchy of the dropped item.

        """
        mimedata = QMimeData()
        item = self.getItem(indexes[0])

        # track representations and hierarchal relationships
        hierarchy_builder = MimeHierarchyTool()
        hierarchy_rep = hierarchy_builder.build_config(item)

        data = json.dumps(hierarchy_rep)
        mimedata.setText(data)
        return mimedata
コード例 #20
0
    def dropMimeData(
        self,
        data: QMimeData,
        action: Qt.DropAction,
        destRow: int,
        col: int,
        parent: QModelIndex,
    ) -> bool:
        """Handles `data` from a drag and drop operation ending with `action`.

        The specified row, column and parent indicate the location of an item
        in the model where the operation ended. It is the responsibility of the
        model to complete the action at the correct location.

        Returns
        -------
        bool ``True`` if the `data` and `action` were handled by the model;
            otherwise returns ``False``.
        """
        if not data or action != Qt.MoveAction:
            return False
        if not data.hasFormat(self.mimeTypes()[0]):
            return False

        if isinstance(data, ItemMimeData):
            moving_indices = data.indices

            logger.debug(f"dropMimeData: indices {moving_indices} ➡ {destRow}")

            if len(moving_indices) == 1:
                return self._root.move(moving_indices[0], destRow)
            else:
                return bool(self._root.move_multiple(moving_indices, destRow))
        return False
コード例 #21
0
ファイル: qt_layerlist.py プロジェクト: xies/napari
 def mouseMoveEvent(self, event):
     position = np.array([event.pos().x(), event.pos().y()])
     distance = np.linalg.norm(position - self.drag_start_position)
     if (distance < QApplication.startDragDistance()
             or self.drag_name is None):
         return
     mimeData = QMimeData()
     mimeData.setText(self.drag_name)
     drag = QDrag(self)
     drag.setMimeData(mimeData)
     drag.setHotSpot(event.pos() - self.rect().topLeft())
     drag.exec_()
     if self.drag_name is not None:
         index = self.layers.index(self.drag_name)
         layer = self.layers[index]
         self._ensure_visible(layer)
コード例 #22
0
def test_add_drop(botlicense):
    qtbot, dialog = botlicense
    mime_no_data = QMimeData()
    mime_data = QMimeData()
    mime_data.setUrls([QUrl.fromLocalFile(EXPIRED_LICENSE_PATH)])

    event = create_event(dialog.table, mime_data, QDropEvent)
    dialog.table.dropEvent(event)

    assert bool(dialog.count())
    assert dialog.count() == 5

    event = create_event(dialog.table, mime_no_data, QDropEvent)
    dialog.table.dropEvent(event)

    assert bool(dialog.count())
    assert dialog.count() == 5
コード例 #23
0
ファイル: objectexplorer.py プロジェクト: MrLeeh/jsonwatchqt
    def mimeData(self, indexes):
        def path(x):
            return "/".join(x.path)

        def node(x):
            return self.node_from_index(x)

        mimedata = QMimeData()
        data = QByteArray()
        stream = QDataStream(data, QIODevice.WriteOnly)

        for path in set(path(node(index)) for index
                        in indexes if index.isValid()):
            stream.writeQString(path)

        mimedata.setData("application/x_nodepath.list", data)
        return mimedata
コード例 #24
0
def test_drag_move_events(botlicense):
    qtbot, dialog = botlicense

    mime_data = QMimeData()
    mime_no_data = QMimeData()
    mime_data.setUrls([QUrl.fromLocalFile(EXPIRED_LICENSE_PATH)])

    event = create_event(dialog.table, mime_data, QDragEnterEvent)
    dialog.table.dragEnterEvent(event)

    event = create_event(dialog.table, mime_no_data, QDragEnterEvent)
    dialog.table.dragEnterEvent(event)

    event = create_event(dialog.table, mime_data, QDragMoveEvent)
    dialog.table.dragMoveEvent(event)

    event = create_event(dialog.table, mime_no_data, QDragMoveEvent)
    dialog.table.dragMoveEvent(event)

    event = QDragLeaveEvent()
    dialog.table.dragLeaveEvent(event)
コード例 #25
0
    def mouseMoveEvent(self, event):
        from qtpy.QtCore import QMimeData, QByteArray
        from qtpy.QtGui import QPixmap, QDrag

        if not (event.button() != Qt.LeftButton
                and isinstance(self.dragLabel, QLabel)):
            return

        if (event.pos() - self.dragStartPosition
            ).manhattanLength() < QApplication.startDragDistance():
            return

        axis_index = self.filters_layout.indexOf(self.dragLabel) // 2

        # prepare hotSpot, mimeData and pixmap objects
        mimeData = QMimeData()
        mimeData.setText(self.dragLabel.text())
        mimeData.setData("application/x-axis-index",
                         QByteArray.number(axis_index))
        pixmap = QPixmap(self.dragLabel.size())
        self.dragLabel.render(pixmap)

        # prepare drag object
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - self.dragStartPosition)

        drag.exec_(Qt.MoveAction | Qt.CopyAction, Qt.CopyAction)
コード例 #26
0
ファイル: table.py プロジェクト: my-pyqt-learning/vsvis
    def _parse_dropped_data(self, mime_data: QMimeData) -> pd.DataFrame:
        byte_data = mime_data.data('application/node')
        as_dict = pickle.loads(byte_data)

        as_dataframe = pd.DataFrame.from_dict(as_dict)
        # filter out rows containing any zero values
        # this avoids adding data associated with h5py.Group objects when
        # dragging from a DraggableTreeModel
        as_dataframe = as_dataframe.loc[as_dataframe.all(1), :]
        columns = np.isin(as_dataframe.columns, self._dataFrame.columns)
        as_dataframe = as_dataframe.loc[:, columns]
        as_dataframe.astype(self._dataFrame.dtypes.to_dict(), copy=False)
        return as_dataframe
コード例 #27
0
ファイル: tabs.py プロジェクト: Simonchengath/Spyder
    def mouseMoveEvent(self, event):
        """Override Qt method"""
        if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \
           (event.pos() - self.__drag_start_pos).manhattanLength() > \
                QApplication.startDragDistance():
            drag = QDrag(self)
            mimeData = QMimeData()

            ancestor_id = to_text_string(id(self.ancestor))
            parent_widget_id = to_text_string(id(self.parentWidget()))
            self_id = to_text_string(id(self))
            source_index = to_text_string(self.tabAt(self.__drag_start_pos))

            mimeData.setData("parent-id", to_binary_string(ancestor_id))
            mimeData.setData("tabwidget-id",
                             to_binary_string(parent_widget_id))
            mimeData.setData("tabbar-id", to_binary_string(self_id))
            mimeData.setData("source-index", to_binary_string(source_index))

            drag.setMimeData(mimeData)
            drag.exec_()
        QTabBar.mouseMoveEvent(self, event)
コード例 #28
0
 def mimeData(self, indexes):
     mimedata = QMimeData()
     mimedata.setText(str(indexes[0].row()))
     return mimedata
コード例 #29
0
ファイル: table.py プロジェクト: my-pyqt-learning/vsvis
 def canDropMimeData(self, data: QMimeData, *args):
     if any([data.hasFormat(typ) for typ in self.mimeTypes()]):
         return True
     else:
         return False
コード例 #30
0
 def mimeData(self, indices) -> QMimeData:
     data = dict(self.get_nodes_as_dict(indices))
     mime = QMimeData()
     mime.setData('application/node', pickle.dumps(data))
     return mime