Example #1
0
 def mimeData(self, indexlist):
     if len(indexlist) != 1:
         return None
     mime = QMimeData()
     mime.setData(self.MIME_TYPE, b'see properties: item_index')
     mime.setProperty('item_index', indexlist[0])
     return mime
Example #2
0
 def mimeData(self, indexlist):
     if len(indexlist) != 1:
         return None
     mime = QMimeData()
     mime.setData(self.MIME_TYPE, b'see properties: item_index')
     mime.setProperty('item_index', indexlist[0])
     return mime
Example #3
0
    def __onDragStarted(self, index):
        desc = qunwrap(index.data(QtWidgetRegistry.WIDGET_DESC_ROLE))
        icon = qunwrap(index.data(Qt.DecorationRole))

        drag_data = QMimeData()
        drag_data.setData(
            "application/vnv.orange-canvas.registry.qualified-name",
            desc.qualified_name.encode('utf-8'))
        drag = QDrag(self)
        drag.setPixmap(icon.pixmap(38))
        drag.setMimeData(drag_data)

        # TODO: Should animate (accept) hide.
        self.hide()

        # When a drag is started and the menu hidden the item's tool tip
        # can still show for a short time UNDER the cursor preventing a
        # drop.
        viewport = self.__menu.view().viewport()
        filter = ToolTipEventFilter()
        viewport.installEventFilter(filter)

        drag.exec_(Qt.CopyAction)

        viewport.removeEventFilter(filter)
    def __onDragStarted(self, index):
        desc = index.data(QtWidgetRegistry.WIDGET_DESC_ROLE)
        icon = index.data(Qt.DecorationRole)

        drag_data = QMimeData()
        drag_data.setData(
            "application/vnv.orange-canvas.registry.qualified-name",
            desc.qualified_name.encode('utf-8')
        )
        drag = QDrag(self)
        drag.setPixmap(icon.pixmap(38))
        drag.setMimeData(drag_data)

        # TODO: Should animate (accept) hide.
        self.hide()

        # When a drag is started and the menu hidden the item's tool tip
        # can still show for a short time UNDER the cursor preventing a
        # drop.
        viewport = self.__menu.view().viewport()
        filter = ToolTipEventFilter()
        viewport.installEventFilter(filter)

        drag.exec_(Qt.CopyAction)

        viewport.removeEventFilter(filter)
Example #5
0
 def mimeData(indexlist):
     assert len(indexlist) == 1
     index = indexlist[0]
     qname = index.data(DescriptionRole).qualname
     m = QMimeData()
     m.setData("application/x-qwidget-ref", qname.encode("utf-8"))
     return m
Example #6
0
 def mimeData(indexlist):
     assert len(indexlist) == 1
     index = indexlist[0]
     qname = index.data(DescriptionRole).qualname
     m = QMimeData()
     m.setData("application/x-qwidget-ref", qname.encode("utf-8"))
     return m
 def copy(self):
     """Copy to the clipboard"""
     data = QMimeData()
     text = '\n'.join([cursor.selectedText() \
                         for cursor in self.cursors()])
     data.setText(text)
     data.setData(self.MIME_TYPE, text.encode('utf8'))
     QApplication.clipboard().setMimeData(data)
 def mimeData(self, index_list: List[QModelIndex]) -> QMimeData:  # noqa: N802
     """
     This function packs data in QMimeData in order to move them to other view with drag and drop functionality.
     """
     items = [self.node_from_index(index) for index in index_list]
     mime = QMimeData()
     # the encoded 'data' is empty, variables are passed by properties
     mime.setData(self.MIME_TYPE, b'')
     mime.setProperty("_items", items)
     mime.setProperty("_source_id", id(self))
     return mime
Example #9
0
 def mimeData(self, indexlist):
     descriptors = []
     vars = []
     for index in indexlist:
         var = self[index.row()]
         descriptors.append((var.name, vartype(var)))
         vars.append(var)
     mime = QMimeData()
     mime.setData(self.MIME_TYPE,
                  QByteArray(str(descriptors).encode("utf-8")))
     mime._vars = vars
     return mime
Example #10
0
 def mimeData(self, indexlist):
     descriptors = []
     vars = []
     for index in indexlist:
         var = self[index.row()]
         descriptors.append((var.name, vartype(var)))
         vars.append(var)
     mime = QMimeData()
     mime.setData(self.MIME_TYPE,
                  QByteArray(str(descriptors).encode("utf-8")))
     mime._vars = vars
     return mime
Example #11
0
    def mimeData(self, indexlist):
        """
        Reimplemented.

        For efficiency reasons only the variable instances are set on the
        mime data (under `'_items'` property)
        """
        items = [self[index.row()] for index in indexlist]
        mime = QMimeData()
        # the encoded 'data' is empty, variables are passed by properties
        mime.setData(self.MIME_TYPE, b'')
        mime.setProperty("_items", items)
        return mime
Example #12
0
    def mimeData(self, indexlist):
        """
        Reimplemented.

        For efficiency reasons only the variable instances are set on the
        mime data (under `'_items'` property)
        """
        items = [self[index.row()] for index in indexlist]
        mime = QMimeData()
        # the encoded 'data' is empty, variables are passed by properties
        mime.setData(self.MIME_TYPE, b'')
        mime.setProperty("_items", items)
        return mime
Example #13
0
 def __startDrag(self, button):
     """
     Start a drag from button
     """
     action = button.defaultAction()
     desc = action.data()  # Widget Description
     icon = action.icon()
     drag_data = QMimeData()
     drag_data.setData(
         "application/vnv.orange-canvas.registry.qualified-name",
         desc.qualified_name.encode("utf-8"))
     drag = QDrag(button)
     drag.setPixmap(icon.pixmap(self.iconSize()))
     drag.setMimeData(drag_data)
     drag.exec_(Qt.CopyAction)
Example #14
0
 def __startDrag(self, button):
     """
     Start a drag from button
     """
     action = button.defaultAction()
     desc = action.data()  # Widget Description
     icon = action.icon()
     drag_data = QMimeData()
     drag_data.setData(
         "application/vnv.orange-canvas.registry.qualified-name",
         desc.qualified_name.encode("utf-8")
     )
     drag = QDrag(button)
     drag.setPixmap(icon.pixmap(self.iconSize()))
     drag.setMimeData(drag_data)
     drag.exec_(Qt.CopyAction)
Example #15
0
    def __startInternalDrag(self, frame, hotSpot=None):
        drag = QDrag(self)
        pixmap = QPixmap(frame.size())
        frame.render(pixmap)

        transparent = QPixmap(pixmap.size())
        transparent.fill(Qt.transparent)
        painter = QPainter(transparent)
        painter.setOpacity(0.35)
        painter.drawPixmap(0, 0, pixmap.width(), pixmap.height(), pixmap)
        painter.end()

        drag.setPixmap(transparent)
        if hotSpot is not None:
            drag.setHotSpot(hotSpot)
        mime = QMimeData()
        mime.setData("application/x-internal-move", b"")
        drag.setMimeData(mime)
        return drag.exec(Qt.MoveAction)
Example #16
0
    def __startInternalDrag(self, frame, hotSpot=None):
        drag = QDrag(self)
        pixmap = QPixmap(frame.size())
        frame.render(pixmap)

        transparent = QPixmap(pixmap.size())
        transparent.fill(Qt.transparent)
        painter = QPainter(transparent)
        painter.setOpacity(0.35)
        painter.drawPixmap(0, 0, pixmap.width(), pixmap.height(), pixmap)
        painter.end()

        drag.setPixmap(transparent)
        if hotSpot is not None:
            drag.setHotSpot(hotSpot)
        mime = QMimeData()
        mime.setData("application/x-internal-move", b"")
        drag.setMimeData(mime)
        return drag.exec_(Qt.MoveAction)
Example #17
0
    def mimeData(self, indexlist):
        if len(indexlist) <= 0:
            return None

        def itemData(row):
            # type: (int) -> Dict[int, Any]
            if row < len(self._other_data):
                return {key: val for key, val in self._other_data[row].items()
                        if isinstance(key, int)}
            else:
                return {}  # pragma: no cover

        items = [self[i.row()] for i in indexlist]
        itemdata = [itemData(i.row()) for i in indexlist]
        mime = QMimeData()
        mime.setData(self.MIME_TYPE, b'see properties: _items, _itemdata')
        mime.setProperty('_items', items)
        mime.setProperty('_itemdata', itemdata)
        return mime
Example #18
0
    def mimeData(self, indexlist):
        if len(indexlist) <= 0:
            return None

        def itemData(row):
            # type: (int) -> Dict[int, Any]
            if row < len(self._other_data):
                return {key: val for key, val in self._other_data[row].items()
                        if isinstance(key, int)}
            else:
                return {}  # pragma: no cover

        items = [self[i.row()] for i in indexlist]
        itemdata = [itemData(i.row()) for i in indexlist]
        mime = QMimeData()
        mime.setData(self.MIME_TYPE, b'see properties: _items, _itemdata')
        mime.setProperty('_items', items)
        mime.setProperty('_itemdata', itemdata)
        return mime
Example #19
0
    def test_drop_event(self):
        w = self.w
        w.setRegistry(self.reg)
        workflow = w.scheme()
        desc = self.reg.widget("one")
        viewport = w.view().viewport()
        mime = QMimeData()
        mime.setData(
            "application/vnd.orange-canvas.registry.qualified-name",
            desc.qualified_name.encode("utf-8")
        )

        self.assertTrue(dragDrop(viewport, mime, QPoint(10, 10)))

        self.assertEqual(len(workflow.nodes), 1)
        self.assertEqual(workflow.nodes[0].description, desc)

        dragEnterLeave(viewport, mime)

        self.assertEqual(len(workflow.nodes), 1)
Example #20
0
    def test_plugin_drag_drop(self):
        handler = PluginDropHandler()
        w = self.w
        w.setRegistry(self.reg)
        w.setDropHandlers([handler])
        workflow = w.scheme()
        viewport = w.view().viewport()
        # Test empty handler
        mime = QMimeData()
        mime.setData(TestDropHandler.format_, b'abc')

        dragDrop(viewport, mime, QPoint(10, 10))

        self.assertIsNone(w._userInteractionHandler())

        # test create node handler
        mime = QMimeData()
        mime.setData(TestNodeFromMimeData.format_, b'abc')

        dragDrop(viewport, mime, QPoint(10, 10))

        self.assertIsNone(w._userInteractionHandler())
        self.assertEqual(len(workflow.nodes), 1)
        self.assertEqual(workflow.nodes[0].description.name, "one")
        self.assertEqual(workflow.nodes[0].properties, {"a": "from drop"})

        workflow.clear()

        # Test both simultaneously (menu for selection)
        mime = QMimeData()
        mime.setData(TestDropHandler.format_, b'abc')
        mime.setData(TestNodeFromMimeData.format_, b'abc')

        def exec(self, *args):
            return action_by_name(self.actions(), "-pick-me")

        # intercept QMenu.exec, force select the TestNodeFromMimeData handler
        with mock.patch.object(QMenu, "exec", exec):
            dragDrop(viewport, mime, QPoint(10, 10))

        self.assertEqual(len(workflow.nodes), 1)
        self.assertEqual(workflow.nodes[0].description.name, "one")
        self.assertEqual(workflow.nodes[0].properties, {"a": "from drop"})
Example #21
0
def table_selection_to_mime_data(table):
    """Copy the current selection in a QTableView to the clipboard.
    """
    lines = table_selection_to_list(table)

    as_csv = lines_to_csv_string(lines, dialect="excel").encode("utf-8")
    as_tsv = lines_to_csv_string(lines, dialect="excel-tab").encode("utf-8")

    mime = QMimeData()
    mime.setData("text/csv", QByteArray(as_csv))
    mime.setData("text/tab-separated-values", QByteArray(as_tsv))
    mime.setData("text/plain", QByteArray(as_tsv))
    return mime
Example #22
0
def table_selection_to_mime_data(table):
    """Copy the current selection in a QTableView to the clipboard.
    """
    lines = table_selection_to_list(table)

    csv = lines_to_csv_string(lines, dialect="excel")
    tsv = lines_to_csv_string(lines, dialect="excel-tab")

    mime = QMimeData()
    mime.setData("text/csv", QByteArray(csv))
    mime.setData("text/tab-separated-values", QByteArray(tsv))
    mime.setData("text/plain", QByteArray(tsv))
    return mime
Example #23
0
File: io.py Project: acopar/orange3
 def _export(exporter, _):
     buffer = exporter.export(toBytes=True)
     mimedata = QMimeData()
     mimedata.setData("image/png", buffer)
     QApplication.clipboard().setMimeData(mimedata)
Example #24
0
 def _export(exporter, _):
     buffer = exporter.export(toBytes=True)
     mimedata = QMimeData()
     mimedata.setData("image/png", buffer)
     QApplication.clipboard().setMimeData(mimedata)