Python PyQt5.QtGui.QDropEvent() Examples

The following are 14 code examples for showing how to use PyQt5.QtGui.QDropEvent(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .

Example 1
Project: track   Author: frans-fuerst   File: qreordertableview.py    License: Apache License 2.0 6 votes vote down vote up
def dropEvent(self, event: QtGui.QDropEvent) -> None:
        """Identifies source/target row of a finished drag&drop and runs moveRow() on the model"""
        if (event.source() is not self or
                (event.dropAction() != QtCore.Qt.MoveAction and
                 self.dragDropMode() != QtWidgets.QAbstractItemView.InternalMove)):
            super().dropEvent(event)

        selection = self.selectedIndexes()
        from_index = selection[0].row() if selection else -1
        to_index = self.indexAt(event.pos()).row()
        if (0 <= from_index < self.model().rowCount() and
                0 <= to_index < self.model().rowCount() and
                from_index != to_index):
            self.model().moveRow(QtCore.QModelIndex(), from_index, QtCore.QModelIndex(), to_index)
            event.accept()
        super().dropEvent(event) 
Example 2
Project: mu   Author: mu-editor   File: test_editor.py    License: GNU General Public License v3.0 6 votes vote down vote up
def test_EditorPane_drop_event(qtapp):
    """
    If there's a drop event associated with files, cause them to be passed into
    Mu's existing file loading code.
    """
    ep = mu.interface.editor.EditorPane(None, "baz")
    m = mock.MagicMock()
    ep.open_file = mock.MagicMock()
    ep.open_file.emit = m
    data = QMimeData()
    data.setUrls(
        [
            QUrl("file://test/path.py"),
            QUrl("file://test/path.hex"),
            QUrl("file://test/path.txt"),
        ]
    )
    evt = QDropEvent(
        QPointF(0, 0), Qt.CopyAction, data, Qt.LeftButton, Qt.NoModifier
    )
    ep.dropEvent(evt)
    # Upstream _load will handle invalid file type (.txt).
    assert m.call_count == 3 
Example 3
Project: CvStudio   Author: haruiz   File: gallery.py    License: MIT License 5 votes vote down vote up
def dropEvent(self, event: QtGui.QDropEvent) -> None:
        valid_files = []
        files = [u.toLocalFile() for u in event.mimeData().urls()]
        for f in files:
            if os.path.isfile(f):
                mime_type, encoding = mimetypes.guess_type(f)  # magic.from_file(f,mime=True)
                if mime_type.find("video") != -1 and self.content_type == "Videos":
                    valid_files.append(f)
                elif mime_type.find("image") != -1 and self.content_type == "Images":
                    valid_files.append(f)
        valid_files = sorted(valid_files, key=lambda v: os.path.basename(v))
        self.filesDropped.emit(valid_files) 
Example 4
Project: autokey   Author: autokey   File: autokey_treewidget.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, event: QDropEvent):
        target = self.itemAt(event.pos())
        sources = self.selectedItems()
        self.window().central_widget.move_items(sources, target) 
Example 5
Project: urh   Author: jopohl   File: DecoderDialog.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, event: QDropEvent):
        # if not self.ui.decoderchain.geometry().contains(self.mapToGlobal(event.pos())):
        if self.ui.decoderchain.currentItem() is not None:
            self.chainoptions.pop(self.ui.decoderchain.currentItem().text(), None)
            self.ui.decoderchain.takeItem(self.ui.decoderchain.currentRow())
            self.decoderchainUpdate() 
Example 6
Project: urh   Author: jopohl   File: ZoomAndDropableGraphicView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, event: QDropEvent):
        mime_data = event.mimeData()
        data_str = str(mime_data.text())
        indexes = list(data_str.split("/")[:-1])

        signal = None
        proto_analyzer = None
        for index in indexes:
            row, column, parent = map(int, index.split(","))
            if parent == -1:
                parent = self.signal_tree_root
            else:
                parent = self.signal_tree_root.child(parent)
            node = parent.child(row)
            if node.protocol is not None and node.protocol.signal is not None:
                signal = node.protocol.signal
                proto_analyzer = node.protocol
                break

        if signal is None:
            return

        if signal is None:
            return

        self.signal = signal  # type: Signal
        self.proto_analyzer = proto_analyzer  # type: ProtocolAnalyzer

        self.scene_manager = SignalSceneManager(signal, self)
        self.plot_data(self.signal.real_plot_data)
        self.show_full_scene()
        self.auto_fit_view()

        self.signal_loaded.emit(self.proto_analyzer) 
Example 7
Project: urh   Author: jopohl   File: ProtocolTreeView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, event: QDropEvent):
        if len(event.mimeData().urls()) > 0:
            group_id = self.model().get_group_id_for_index(self.indexAt(event.pos()))
            self.files_dropped_on_group.emit(event.mimeData().urls(), group_id)
        else:
            super().dropEvent(event) 
Example 8
Project: urh   Author: jopohl   File: ProtocolTableView.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, event: QDropEvent):
        if len(event.mimeData().urls()) > 0:
            self.files_dropped.emit(event.mimeData().urls()) 
Example 9
Project: urh   Author: jopohl   File: ListWidget.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, event: QDropEvent):
        super().dropEvent(event)
        if self.count() > 0:
            item = self.itemAt(event.pos())
            if item is not None:
                index = self.indexFromItem(item).row()
                self.setCurrentRow(index)
            else:
                self.setCurrentRow(self.count()-1) 
Example 10
Project: urh   Author: jopohl   File: SimulatorScene.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, event: QDropEvent):
        items = [item for item in self.items(event.scenePos()) if isinstance(item, GraphicsItem) and item.acceptDrops()]
        item = None if len(items) == 0 else items[0]
        if len(event.mimeData().urls()) > 0:
            self.files_dropped.emit(event.mimeData().urls())

        indexes = list(event.mimeData().text().split("/")[:-1])

        group_nodes = []
        file_nodes = []
        for index in indexes:
            try:
                row, column, parent = map(int, index.split(","))
                if parent == -1:
                    parent = self.tree_root_item
                else:
                    parent = self.tree_root_item.child(parent)
                node = parent.child(row)
                if node.is_group:
                    group_nodes.append(node)
                else:
                    file_nodes.append(node)
            except ValueError:
                continue

        # Which Nodes to add?
        nodes_to_add = []
        """:type: list of ProtocolTreeItem """
        for group_node in group_nodes:
            nodes_to_add.extend(group_node.children)
        nodes_to_add.extend([file_node for file_node in file_nodes if file_node not in nodes_to_add])
        protocols_to_add = [node.protocol for node in nodes_to_add]

        ref_item = item
        position = None if ref_item is None else item.drop_indicator_position
        self.add_protocols(ref_item, position, protocols_to_add)
        super().dropEvent(event) 
Example 11
Project: urh   Author: jopohl   File: GraphicsItem.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, event: QDropEvent):
        self.drag_over = False
        self.update() 
Example 12
Project: urh   Author: jopohl   File: GraphicsItem.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dragMoveEvent(self, event: QDropEvent):
        self.update_drop_indicator(event.pos()) 
Example 13
Project: urh   Author: jopohl   File: QtTestCase.py    License: GNU General Public License v3.0 5 votes vote down vote up
def add_all_signals_to_simulator(self):
        assert isinstance(self.form, MainController)
        sim_frame = self.form.simulator_tab_controller
        sim_frame.ui.treeProtocols.selectAll()
        self.assertGreater(len(sim_frame.ui.treeProtocols.selectedIndexes()), 0)
        mimedata = sim_frame.tree_model.mimeData(sim_frame.ui.treeProtocols.selectedIndexes())
        drop_event = QDropEvent(sim_frame.ui.gvSimulator.rect().center(), Qt.CopyAction | Qt.MoveAction,
                                mimedata, Qt.LeftButton, Qt.NoModifier)
        drop_event.acceptProposedAction()
        sim_frame.ui.gvSimulator.dropEvent(drop_event) 
Example 14
Project: urh   Author: jopohl   File: test_modulator_gui.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_signal_view(self):
        self.add_signal_to_form("esaver.complex16s")
        signal = self.form.signal_tab_controller.signal_frames[0].signal

        tree_view = self.dialog.ui.treeViewSignals
        tree_model = tree_view.model()
        item = tree_model.rootItem.children[0].children[0]
        index = tree_model.createIndex(0, 0, item)
        rect = tree_view.visualRect(index)
        QTest.mousePress(tree_view.viewport(), Qt.LeftButton, pos=rect.center())
        mime_data = tree_model.mimeData([index])
        drag_drop = QDropEvent(rect.center(), Qt.CopyAction | Qt.MoveAction, mime_data, Qt.LeftButton, Qt.NoModifier)
        drag_drop.acceptProposedAction()
        self.dialog.ui.gVOriginalSignal.dropEvent(drag_drop)
        self.assertEqual(self.dialog.ui.gVOriginalSignal.sceneRect().width(), signal.num_samples)

        self.dialog.ui.cbShowDataBitsOnly.click()
        self.dialog.ui.chkBoxLockSIV.click()

        self.assertEqual(int(self.dialog.ui.gVOriginalSignal.view_rect().width()),
                         int(self.dialog.ui.gVModulated.view_rect().width()))

        freq = self.dialog.ui.doubleSpinBoxCarrierFreq.value()
        self.dialog.ui.btnAutoDetect.click()
        self.assertNotEqual(freq, self.dialog.ui.doubleSpinBoxCarrierFreq.value())

        self.dialog.ui.comboBoxModulationType.setCurrentText("Frequency Shift Keying (FSK)")
        self.dialog.ui.btnAutoDetect.click()

        self.assertEqual(self.dialog.ui.lCurrentSearchResult.text(), "1")
        self.dialog.ui.btnSearchNext.click()
        self.assertEqual(self.dialog.ui.lCurrentSearchResult.text(), "2")
        self.dialog.ui.btnSearchPrev.click()
        self.assertEqual(self.dialog.ui.lCurrentSearchResult.text(), "1")