Example #1
0
    def test_pasteImage_Markdown(self, _mock_image, _mock_editor):
        mimeData = QMimeData()
        mimeData.setImageData(self._create_image())
        self.dummytab.markupClass = MarkdownMarkup

        self.editor.insertFromMimeData(mimeData)
        self.assertTrue('![myimage](myimage.jpg)' in self.editor.toPlainText())
Example #2
0
	def test_pasteImage_Markdown(self, _mock_image, _mock_editor):
		mimeData = QMimeData()
		mimeData.setImageData(self._create_image())
		self.dummytab.markupClass = MarkdownMarkup

		self.editor.insertFromMimeData(mimeData)
		self.assertTrue('![myimage](myimage.jpg)' in self.editor.toPlainText())
Example #3
0
	def test_pasteImage_RestructuredText(self, _mock_image, _mock_editor):
		mimeData = QMimeData()
		mimeData.setImageData(self._create_image())
		self.dummytab.markupClass = ReStructuredTextMarkup

		self.editor.insertFromMimeData(mimeData)
		self.assertTrue('.. image:: myimage.jpg' in self.editor.toPlainText())
Example #4
0
    def mouseMoveEvent(self, event):
        if self.dialog.removable:
            return

        if not (event.buttons() & Qt.LeftButton):
            return

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

        drag = QDrag(self)
        mimedata = QMimeData()
        mimedata.setText(self.text())

        if self.pixmap() is None:
            return

        mimedata.setImageData(self.pixmap().toImage())

        drag.setMimeData(mimedata)
        pixmap = QPixmap(self.size())
        self.image = pixmap
        painter = QPainter(pixmap)
        painter.drawPixmap(self.rect(), self.grab())
        painter.end()
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos())
        print("Moving")
        drag.exec_(Qt.MoveAction)
Example #5
0
    def test_pasteImage_RestructuredText(self, _mock_image, _mock_editor):
        mimeData = QMimeData()
        mimeData.setImageData(self._create_image())
        self.dummytab.markupClass = ReStructuredTextMarkup

        self.editor.insertFromMimeData(mimeData)
        self.assertTrue('.. image:: myimage.jpg' in self.editor.toPlainText())
Example #6
0
    def on_copy_to_clipboard(self):
        pixmap = self.web_view.grab()
        clipboard = QGuiApplication.clipboard()

        data = QMimeData()
        data.setImageData(pixmap)
        clipboard.setMimeData(data, QClipboard.Clipboard)
 def updateMimeData(
     self,
     hasColor,
     color,
     hasHtml,
     html,
     hasImage,
     image,
     hasText,
     text,
     hasUrls,
     urls,
     hasFiles,
     files,
 ):
     # 客户端剪切板同步到服务端
     self.append('收到客户端发送的剪贴板')
     clipboard = QApplication.clipboard()
     clipboard.blockSignals(True)
     data = QMimeData()
     if hasColor:
         data.setColorData(color)
     if hasHtml:
         data.setHtml(html)
     if hasImage:
         data.setImageData(image)
     if hasText:
         data.setText(text)
     # if hasUrls:
     #     data.setUrls(urls)
     if hasFiles:
         data.setData('')
     clipboard.setMimeData(data)
     clipboard.blockSignals(False)
Example #8
0
    def mouseMoveEvent(self, event):
        # перетягивание на левую кнопку мыши + установка минимальной длины для начала перетягивания (4 пикселя)
        if not (event.buttons() & Qt.LeftButton):
            return
        if (event.pos() - self.drag_start_position).manhattanLength() < 2:
            global correction
            correction = event.pos() - self.drag_start_position
        drag = QDrag(self)

        # QMimeData() - класс для хранения данных любого типа во время перетягивания
        mimedata = QMimeData()

        mimedata.setImageData(self.pixmap().toImage())  # изображение в качестве данных, которое потом можно будет дропнуть

        drag.setMimeData(mimedata)

        t = QTransform().rotate(ui.angle)
        pixmap = QPixmap(ui.image_raw_main.transformed(t))  #Все исправление в 3 строчки
        pixmap = pixmap.scaled(self.size())


        painter = QPainter(pixmap)

        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.setStyleSheet("background:transparent;")

        painter.drawPixmap(self.rect(), self.grab())
        painter.end()

        drag.setPixmap(pixmap)  #именно здесь происходит прорисовка изображения, работает и без QPainter, но
        #Но он помогает восстановить качество картинки, по сути перерисовывая новую картинку поверх старой,
        #повреждено из за метода scaled. Картинка из этой строчки по сути является фоном, и именно в ней и была проблема
        drag.setHotSpot(event.pos() - self.rect().topLeft())
        drag.exec_(Qt.CopyAction | Qt.MoveAction)
Example #9
0
    def mouseMoveEvent(self, event):
        if QLineF(QPointF(event.screenPos()), QPointF(event.buttonDownScreenPos(Qt.LeftButton))).length() < QApplication.startDragDistance():
            return

        drag = QDrag(event.widget())
        mime = QMimeData()
        drag.setMimeData(mime)

        ColorItem.n += 1
        if ColorItem.n > 2 and qrand() % 3 == 0:
            image = QImage(':/images/head.png')
            mime.setImageData(image)
            drag.setPixmap(QPixmap.fromImage(image).scaled(30,40))
            drag.setHotSpot(QPoint(15, 30))
        else:
            mime.setColorData(self.color)
            mime.setText("#%02x%02x%02x" % (self.color.red(), self.color.green(), self.color.blue()))

            pixmap = QPixmap(34, 34)
            pixmap.fill(Qt.white)

            painter = QPainter(pixmap)
            painter.translate(15, 15)
            painter.setRenderHint(QPainter.Antialiasing)
            self.paint(painter, None, None)
            painter.end()

            pixmap.setMask(pixmap.createHeuristicMask())

            drag.setPixmap(pixmap)
            drag.setHotSpot(QPoint(15, 20))

        drag.exec_()
        self.setCursor(Qt.OpenHandCursor)
Example #10
0
    def mouseMoveEvent(self, event):
        if not (event.buttons() & Qt.LeftButton):
            return
        if (event.pos() - self.drag_start_position).manhattanLength() < 2:
            global correction
            correction = event.pos() - self.drag_start_position
        drag = QDrag(self)
        mimedata = QMimeData()
        mimedata.setImageData(self.pixmap().toImage())  # изображение в качестве данных, которое потом можно будет дропнуть

        drag.setMimeData(mimedata)
        #t = QTransform().rotate(ui.angle)
        pixmap = QPixmap(drag.mimeData().imageData())  # POGU
        pixmap = pixmap.scaled(self.size())

        painter = QPainter(pixmap)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.setStyleSheet("background:transparent;")
        painter.drawPixmap(self.rect(), self.grab())
        painter.end()

        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - self.rect().topLeft())
        drag.exec_(Qt.CopyAction | Qt.MoveAction)
Example #11
0
def copy_image():
    img = QImage()
    img.loadFromData(f.read())

    data = QMimeData()
    data.setImageData(img)

    clipboard.setMimeData(data)
    print("ok")
Example #12
0
def copy_image():
    img = QImage()
    img.loadFromData(f.read())

    data = QMimeData()
    data.setImageData(img)

    clipboard.setMimeData(data)
    print("ok")
Example #13
0
	def test_pasteImage_Markdown(self, _mock_image, _mock_editor):
		mimeData = QMimeData()
		mimeData.setImageData(self._create_image())
		app.clipboard().setMimeData(mimeData)
		self.dummytab.markupClass = MarkdownMarkup
		self.dummytab.fileName = '/tmp/foo.md'

		self.editor.pasteImage()
		self.assertTrue('![myimage](myimage.jpg)' in self.editor.toPlainText())
Example #14
0
	def test_pasteImage_RestructuredText(self, _mock_image, _mock_editor):
		mimeData = QMimeData()
		mimeData.setImageData(self._create_image())
		app.clipboard().setMimeData(mimeData)
		self.dummytab.markupClass = ReStructuredTextMarkup
		self.dummytab.fileName = '/tmp/foo.rst'

		self.editor.pasteImage()
		self.assertTrue('.. image:: myimage.jpg' in self.editor.toPlainText())
 def copyPushButtonClicked(self):
     #setting clipboard contents to thumb if it exists
     if (self.imageUrl != None):
         clipboard = QGuiApplication.clipboard()
         data = QMimeData()
         data.setImageData(self.thumbnailImage)
         clipboard.setMimeData(data)
         self.statusbar.showMessage("Thumbnail copied", 4000)
     else:
         self.statusbar.showMessage("No thumbnail to copy", 4000)
Example #16
0
 def __dragSnapshot(self):
     """
     Private slot handling the dragging of the preview picture.
     """
     drag = QDrag(self)
     mimeData = QMimeData()
     mimeData.setImageData(self.__snapshot)
     drag.setMimeData(mimeData)
     drag.setPixmap(self.preview.pixmap())
     drag.exec_(Qt.CopyAction)
Example #17
0
 def __dragSnapshot(self):
     """
     Private slot handling the dragging of the preview picture.
     """
     drag = QDrag(self)
     mimeData = QMimeData()
     mimeData.setImageData(self.__snapshot)
     drag.setMimeData(mimeData)
     drag.setPixmap(self.preview.pixmap())
     drag.exec_(Qt.CopyAction)
Example #18
0
    def _copy_results_current(self, grid):
        """Copy cell results for the current cell"""

        current = grid.current
        data = grid.model.code_array[current]
        if data is None:
            return

        clipboard = QApplication.clipboard()

        # Get renderer for current cell
        renderer = grid.model.code_array.cell_attributes[current]["renderer"]

        if renderer == "text":
            clipboard.setText(repr(data))

        elif renderer == "image":
            if isinstance(data, BasicQImage):
                clipboard.setImage(data)
            else:
                # We may have an svg image here
                try:
                    svg_bytes = bytes(data)
                except TypeError:
                    svg_bytes = bytes(data, encoding='utf-8')
                if is_svg(svg_bytes):
                    mime_data = QMimeData()
                    mime_data.setData("image/svg+xml", svg_bytes)
                    clipboard.setMimeData(mime_data)

        elif renderer == "markup":
            mime_data = QMimeData()
            mime_data.setHtml(str(data))

            # Also copy data as plain text
            doc = QTextDocument()
            doc.setHtml(str(data))
            mime_data.setText(doc.toPlainText())

            clipboard.setMimeData(mime_data)

        elif renderer == "matplotlib" and isinstance(data,
                                                     matplotlib_figure.Figure):
            # We copy and svg to the clipboard
            svg_filelike = io.BytesIO()
            png_filelike = io.BytesIO()
            data.savefig(svg_filelike, format="svg")
            data.savefig(png_filelike, format="png")
            svg_bytes = (svg_filelike.getvalue())
            png_image = QImage().fromData(png_filelike.getvalue())
            mime_data = QMimeData()
            mime_data.setData("image/svg+xml", svg_bytes)
            mime_data.setImageData(png_image)
            clipboard.setMimeData(mime_data)
 def mouseMoveEvent(self, event):
     if event.buttons(
     ) & Qt.LeftButton and self.target is not None and self.target in self.lineup:
         drag = QDrag(self.ly_players.itemAt(self.target))
         pix = self.ly_players.itemAt(self.target).itemAt(0).widget().grab()
         mimedata = QMimeData()
         mimedata.setImageData(pix)
         drag.setMimeData(mimedata)
         drag.setPixmap(pix)
         to_middle = (pix.height() // 2)
         drag.setHotSpot(QPoint(to_middle, to_middle))
         drag.exec_()
Example #20
0
    def mouseMoveEvent(self, e):
        if e.buttons() != Qt.LeftButton:
            return
#             position = e.pos()
#             self.move(position)

        mimeData = QMimeData()
        mimeData.setImageData(self)
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(e.pos() - self.rect().topLeft())

        dropAcion = drag.exec_(Qt.MoveAction)
Example #21
0
def mouseMoveEvent(self, event):
    if event.buttons() != Qt.LeftButton or self.window().img is None:
        return

    img_transparent = to_transparent_image(self.window().img)

    mime = QMimeData()
    mime.setImageData(img_transparent)

    drag = QDrag(self)
    drag.setMimeData(mime)
    drag.setPixmap(self.pixmap())

    drag.exec(Qt.MoveAction)
 def mouseMoveEvent(self, event):
     if not (event.buttons() & Qt.LeftButton):
         return
     if ((event.pos() - self.drag_start_position).manhattanLength() <
             QApplication.startDragDistance()):
         return
     drag = QDrag(self)
     mimedata = QMimeData()
     mimedata.valor = self.valor
     mimedata.posicion = self.posicion
     mimedata.setImageData(self.pixmap().toImage())
     drag.setMimeData(mimedata)
     drag.setPixmap(self.fondo_item)
     drag.setHotSpot(event.pos())
     drag.exec_(Qt.CopyAction | Qt.MoveAction)
Example #23
0
 def startDrag(self):
     image = self.image()
     data = QMimeData()
     data.setImageData(image)
     drag = QDrag(self)
     drag.setMimeData(data)
     if max(image.width(), image.height()) > 256:
         image = image.scaled(QSize(256, 256), Qt.KeepAspectRatio, Qt.SmoothTransformation)
     p = QPainter()
     p.begin(image)
     p.setCompositionMode(QPainter.CompositionMode_DestinationIn)
     p.fillRect(image.rect(), QColor(0, 0, 0, 160))
     p.end()
     pixmap = QPixmap.fromImage(image)
     drag.setPixmap(pixmap)
     drag.setHotSpot(pixmap.rect().center())
     drag.exec_(Qt.CopyAction)
Example #24
0
    def mouseMoveEvent(self, event):
        if QLineF(event.screenPos(),
                event.buttonDownScreenPos(Qt.LeftButton)).length() < \
                        QApplication.startDragDistance():
            return

        drag = QDrag(event.widget())
        mime = QMimeData()
        drag.setMimeData(mime)

        mime.setImageData(REDDISK)
        dragImg = REDDISK.scaled(40, 40, Qt.KeepAspectRatio)
        drag.setPixmap(QPixmap.fromImage(dragImg))
        drag.setHotSpot(QPoint(dragImg.width() / 2, dragImg.height()/ 2))

        drag.exec()
        self.setCursor(Qt.OpenHandCursor)
Example #25
0
    def mouseMoveEvent(self, event):
        if (
            QLineF(
                QPointF(event.screenPos()),
                QPointF(event.buttonDownScreenPos(Qt.LeftButton)),
            ).length()
            < QApplication.startDragDistance()
        ):
            return

        drag = QDrag(event.widget())
        mime = QMimeData()
        drag.setMimeData(mime)

        ColorItem.n += 1
        if ColorItem.n > 2 and qrand() % 3 == 0:
            root = QFileInfo(__file__).absolutePath()

            image = QImage(root + "/images/head.png")
            mime.setImageData(image)
            drag.setPixmap(QPixmap.fromImage(image).scaled(30, 40))
            drag.setHotSpot(QPoint(15, 30))
        else:
            mime.setColorData(self.color)
            mime.setText(
                "#%02x%02x%02x"
                % (self.color.red(), self.color.green(), self.color.blue())
            )

            pixmap = QPixmap(34, 34)
            pixmap.fill(Qt.white)

            painter = QPainter(pixmap)
            painter.translate(15, 15)
            painter.setRenderHint(QPainter.Antialiasing)
            self.paint(painter, None, None)
            painter.end()

            pixmap.setMask(pixmap.createHeuristicMask())

            drag.setPixmap(pixmap)
            drag.setHotSpot(QPoint(15, 20))

        drag.exec_()
        self.setCursor(Qt.OpenHandCursor)
Example #26
0
 def updateMimeData(self, hasColor, color, hasHtml, html, hasImage, image,
                    hasText, text, hasUrls, urls):
     # 远程的剪贴板同步到客户端
     clipboard = QApplication.clipboard()
     clipboard.blockSignals(True)
     data = QMimeData()
     if hasColor:
         data.setColorData(color)
     if hasHtml:
         data.setHtml(html)
     if hasImage:
         data.setImageData(image)
     if hasText:
         data.setText(text)
     if hasUrls:
         data.setUrls(urls)
     clipboard.setMimeData(data)
     clipboard.blockSignals(False)
Example #27
0
 def mouseMoveEvent(self, e):
     if not (e.buttons() & Qt.LeftButton):
         return
     if (e.pos() - self.drag_start_position
         ).manhattanLength() < QApplication.startDragDistance():
         return
     drag = QDrag(self)
     mimedata = QMimeData()
     mimedata.setText(self.text())
     mimedata.setImageData(self.pixmap().toImage())
     drag.setMimeData(mimedata)
     pixmap = QPixmap(self.size())
     painter = QPainter(pixmap)
     painter.drawPixmap(self.rect(), self.grab())
     painter.end()
     drag.setPixmap(pixmap)
     drag.setHotSpot(e.pos())
     drag.exec_(Qt.CopyAction | Qt.MoveAction)
Example #28
0
    def export_to_clipboard(self):
        bounds = self.__get_bounds()
        size = self.get_size(bounds)

        output = QPixmap(size)
        output.fill(Qt.transparent)

        self.__draw(bounds, output)

        clipboard_data = QMimeData()
        clipboard_data.setImageData(output)
        if self.__transparent:
            image_data = QByteArray()
            image_buffer = QBuffer(image_data)
            output.save(image_buffer, 'PNG')
            image_base64 = base64.b64encode(bytes(image_data)).decode('ascii')
            clipboard_data.setHtml(
                '<img src="data:image/png;base64,{0}">'.format(image_base64))
        QApplication.clipboard().setMimeData(clipboard_data)
Example #29
0
    def mouseMoveEvent(self, event):
        '''
        拖动中我们所要显示的图形、鼠标样式
        '''

        drag = QDrag(event.widget())
        mime = QMimeData()
        drag.setMimeData(mime)

        root = QFileInfo(__file__).absolutePath()#绝对路径

        image = QImage(root + '/res/{}.png'.format(self.type))
        mime.setImageData(image)
        drag.setPixmap(QPixmap.fromImage(image).scaled(50, 50))
        drag.setHotSpot(QPoint(25, 25))

        drag.exec_()
        # 设置拖动中图像以及HotSpot

        self.setCursor(Qt.OpenHandCursor)
Example #30
0
    def load_image(self, img: QImage):
        if not (img is None):
            multiplier = config_handler.multipliers[config_handler.get_config_parser().get('DEFAULT', 'Render')]
            img = img.scaledToHeight(img.size().height() * multiplier, Qt.SmoothTransformation)
            if img.size().width() > self.imgLabel.size().width() \
                    or img.size().height() > self.imgLabel.size().height():
                img = MainWindow.scale_image_to_label(img, self.imgLabel)
            self.img = img
            pixmap = QPixmap.fromImage(img)
            self.imgLabel.setPixmap(pixmap)
            self.statusBar().showMessage('Connected.')
        else:
            self.img = None
            self.statusBar().showMessage('Disconnected.')

        if config_handler.get_config_parser().getboolean('DEFAULT', 'ListenToClip'):
            img_transparent = to_transparent_image(img)

            mime = QMimeData()
            mime.setImageData(img_transparent)

            QApplication.clipboard().setMimeData(mime)

        self.waiting = False
Example #31
0
 def copy_image_to_clipboard(self):
     data = QMimeData()
     data.setImageData(self.imageView.image.pixmap())
     app = QApplication.instance()
     app.clipboard().setMimeData(data)
Example #32
0
 def setDataToMime(self, mime: QMimeData) -> None:
     super().setDataToMime(mime)
     mime.setImageData(self.pixmap())
Example #33
0
 def sendToHost(self, img):
     mimeData = QMimeData()
     mimeData.setImageData(img)
     self.host.store(mimeData, pngType)
Example #34
0
 def mimeData(self):
     data = QMimeData()
     data.setImageData(self.image())
     return data
Example #35
0
 def test_allowImageOnClipboard(self):
     mimeData = QMimeData()
     mimeData.setImageData(self._create_image())
     self.assertTrue(self.editor.canInsertFromMimeData(mimeData))
Example #36
0
	def test_allowImageOnClipboard(self):
		mimeData = QMimeData()
		mimeData.setImageData(self._create_image())
		self.assertTrue(self.editor.canInsertFromMimeData(mimeData))