def _copy_links(self, lines): urls = QUrl.fromStringList(lines) cb = QApplication.instance().clipboard() md = QMimeData() md.setText('\n'.join(lines)) md.setUrls(urls) cb.setMimeData(md)
def copy_metadata(self): rows = self.gui.library_view.selectionModel().selectedRows() if not rows or len(rows) == 0: return error_dialog(self.gui, _('Cannot copy metadata'), _('No books selected'), show=True) if len(rows) > 1: return error_dialog( self.gui, _('Cannot copy metadata'), _('Multiple books selected, can only copy from one book at a time.' ), show=True) db = self.gui.current_db book_id = db.id(rows[0].row()) mi = db.new_api.get_metadata(book_id) md = QMimeData() md.setText(str(mi)) md.setData('application/calibre-book-metadata', bytearray(metadata_to_opf(mi, default_lang='und'))) img = db.new_api.cover(book_id, as_image=True) if img: md.setImageData(img) c = QApplication.clipboard() c.setMimeData(md)
def copy_all(text_browser): mf = getattr(text_browser, 'details', text_browser) c = QApplication.clipboard() md = QMimeData() md.setText(mf.toPlainText()) md.setHtml(mf.toHtml()) c.setMimeData(md)
def trigger_copy(self, text, html): if text: md = QMimeData() md.setText(text) if html: md.setHtml(html) QApplication.instance().clipboard().setMimeData(md)
def mime_data_for_copy(self): md = QMimeData() text = self.lineEdit().selectedText() md.setText(text or self.dateTime().toString()) md.setData( self.MIME_TYPE, self.dateTime().toString(Qt.DateFormat.ISODate).encode('ascii')) return md
def copy_image(self, name): path = get_path_for_name(name) if not path: return error_dialog(self, _('Image not found'), _( "Failed to find the image {}").format(name), show=True) try: img = image_from_path(path) except Exception: return error_dialog(self, _('Invalid image'), _( "Failed to load the image {}").format(name), show=True) url = QUrl.fromLocalFile(path) md = QMimeData() md.setImageData(img) md.setUrls([url]) QApplication.instance().clipboard().setMimeData(md)
def drag_data(self): m = self.model() db = m.db selected = self.get_selected_ids() ids = ' '.join(map(str, selected)) md = QMimeData() md.setData('application/calibre+from_library', ids.encode('utf-8')) fmt = prefs['output_format'] def url_for_id(i): try: ans = db.format_path(i, fmt, index_is_id=True) except: ans = None if ans is None: fmts = db.formats(i, index_is_id=True) if fmts: fmts = fmts.split(',') else: fmts = [] for f in fmts: try: ans = db.format_path(i, f, index_is_id=True) except: ans = None if ans is None: ans = db.abspath(i, index_is_id=True) return QUrl.fromLocalFile(ans) md.setUrls([url_for_id(i) for i in selected]) drag = QDrag(self) col = self.selectionModel().currentIndex().column() try: md.column_name = self.column_map[col] except AttributeError: md.column_name = 'title' drag.setMimeData(md) cover = self.drag_icon(m.cover(self.currentIndex().row()), len(selected) > 1) drag.setHotSpot(QPoint(-15, -15)) drag.setPixmap(cover) return drag
def mimeData(self, indexes): data = ','.join(unicode_type(i.row()) for i in indexes) md = QMimeData() md.setData('application/calibre_charcode_indices', data.encode('utf-8')) return md
def createMimeDataFromSelection(self): ans = QMimeData() ans.setText(self.selected_text) return ans