def new_processUrls(self, mime, _old): urls = mime.urls() size = len(urls) if size == 1: return _old(self, mime) # LOG.debug("import %d urls" % size) newmime = QMimeData() newlink = "" for url in urls: url = url.toString() url = url.splitlines()[0] # LOG.debug("import %s" % url) newmime = QMimeData() link = self.editor.urlToLink(url) if link: newlink += link elif mime.hasImage(): # if we couldn't convert the url to a link and there's an # image on the clipboard (such as copy&paste from # google images in safari), use that instead return self._processImage(mime) else: newmime.setText(url) return newmime if newlink != "": newmime.setHtml(newlink) return newmime
def _copy(self, index): doc = QTextDocument() doc.setHtml(index.data(Qt.DisplayRole).toString()) clipboard = QApplication.clipboard() richTextData = QMimeData() richTextData.setHtml(index.data(Qt.DisplayRole).toString()) richTextData.setText(doc.toPlainText()) clipboard.setMimeData(richTextData)
def copyColoredHtml(self): cursor = self.textCursor() if not cursor.hasSelection(): return number_lines = QSettings().value("source_export/number_lines", False, bool) inline_style = QSettings().value("source_export/inline_copy", True, bool) as_plain_text = QSettings().value("source_export/copy_html_as_plain_text", False, bool) document_body_only = QSettings().value("source_export/copy_document_body_only", False, bool) import highlight2html html = highlight2html.html_inline(cursor, inline=inline_style, number_lines=number_lines, full_html=not document_body_only) data = QMimeData() data.setText(html) if as_plain_text else data.setHtml(html) QApplication.clipboard().setMimeData(data)
def copyColoredHtml(self): cursor = self.textCursor() if not cursor.hasSelection(): return number_lines = QSettings().value("source_export/number_lines", False, bool) inline_style = QSettings().value("source_export/inline_copy", True, bool) as_plain_text = QSettings().value( "source_export/copy_html_as_plain_text", False, bool) document_body_only = QSettings().value( "source_export/copy_document_body_only", False, bool) import highlight2html html = highlight2html.html_inline(cursor, inline=inline_style, number_lines=number_lines, full_html=not document_body_only) data = QMimeData() data.setText(html) if as_plain_text else data.setHtml(html) QApplication.clipboard().setMimeData(data)
def copyColoredHtml(self): cursor = self.textCursor() if not cursor.hasSelection(): return s = QSettings() s.beginGroup("source_export") number_lines = s.value("number_lines", False, bool) inline_style = s.value("inline_copy", True, bool) as_plain_text = s.value("copy_html_as_plain_text", False, bool) wrap_tag = s.value("wrap_tag", "pre", str) wrap_attrib = s.value("wrap_attrib", "id", str) wrap_attrib_name = s.value("wrap_attrib_name", "document", str) document_body_only = s.value("copy_document_body_only", False, bool) import highlight2html html = highlight2html.html_inline(cursor, inline=inline_style, number_lines=number_lines, full_html=not document_body_only, wrap_tag=wrap_tag, wrap_attrib=wrap_attrib, wrap_attrib_name=wrap_attrib_name) data = QMimeData() data.setText(html) if as_plain_text else data.setHtml(html) QApplication.clipboard().setMimeData(data)
def _drag_hmtl ( self, html ): mime_data = QMimeData() mime_data.setHtml( html ) return mime_data