def createMimeDataFromSelection(self): result = QMimeData() cursor = self.textCursor() selection = cursor.selectedText() selection = selection.replace('\u2029', '\n') selection = selection.replace('\u2028', '\n') result.setText(selection) # create an xml representation of the selected document structure traversal = TextDocumentSelectionTraversal() frame = traversal.traverse(self.textCursor(), self.document()) print('\n-----------------------------------------------') printer = StructurePrinter(frame, self.outPut) printer.traverse() print('-----------------------------------------------') return sp = AppXmlPrinter(frame, None) sp.traverse() blafasel = '''<?xml version="1.0" encoding="utf-8"?> <article version="5.0" xml:lang="en" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title></title></article>''' result.setData("application/xml", blafasel) return result
def createMimeDataFromSelection(self): result = QMimeData() cursor = self.textCursor() selection = cursor.selectedText() selection = selection.replace('\u2029', '\n') selection = selection.replace('\u2028', '\n') result.setText(selection) # create an xml representation of the selected document structure traversal = TextDocumentSelectionTraversal() frame = traversal.traverse(self.textCursor(), self.document()) print('\n-----------------------------------------------') printer = StructurePrinter(frame, self.outPut) printer.traverse() print('-----------------------------------------------') return sp = AppXmlPrinter(frame, None) sp.traverse() blafasel = '''<?xml version="1.0" encoding="utf-8"?> <article version="5.0" xml:lang="en" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title></title></article>''' result.setData("application/xml", blafasel) return result
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(unicode_type(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 set_clipboard(**kwargs): text = kwargs.get('text', None) html = kwargs.get('html', None) internal = kwargs.get('internal', False) kwargs['internal'] = True # set internal for nested invocations if text is not None and html is not None: raise ValueError() if internal: if not os.fork(): os.close(sys.stdin.fileno()) os.close(sys.stdout.fileno()) os.close(sys.stderr.fileno()) mime = QMimeData() mime.setData('text/application', b'queso') if text is not None: mime.setText(text) if html is not None: mime.setHtml(html) clip = get_application().clipboard() clip.setMimeData(mime) clip.dataChanged.connect(get_application().exit) sys.exit(get_application().exec_()) else: p = multiprocessing.get_context('spawn').Process(target=set_clipboard, kwargs=kwargs, daemon=True) p.start()
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 mimeData(self, indexes): result = QMimeData() node = self.qt_index_to_node(indexes[0]) if node is not None: path_data = encode_seq_component_tree_node_path( self._project_tree_controller.active_node.abs_name_path, node.abs_name_path) result.setData(SEQUENCE_COMPONENT_TREE_NODE_PATH_MEDIA_TYPE, path_data) return result
def mimeData(self, indices): mimeData = QMimeData() encodedData = QByteArray() stream = QDataStream(encodedData, QIODevice.WriteOnly) for index in indices: if index.column() == 1: d = QVariant(self.data(index, Qt.DecorationRole)) else: d = QVariant(self.data(index, Qt.DisplayRole).toString()) stream << d mimeData.setData('application/target.tableitem.creepy', encodedData) return mimeData
def drag_data(self): m = self.model() rows = self.selectionModel().selectedRows() paths = [force_unicode(p, enc=filesystem_encoding) for p in m.paths(rows) if p] md = QMimeData() md.setData("application/calibre+from_device", b"dummy") md.setUrls([QUrl.fromLocalFile(p) for p in paths]) drag = QDrag(self) drag.setMimeData(md) cover = self.drag_icon(m.cover(self.currentIndex().row()), len(paths) > 1) drag.setHotSpot(QPoint(-15, -15)) drag.setPixmap(cover) return drag
def drag_data(self): m = self.model() rows = self.selectionModel().selectedRows() paths = [force_unicode(p, enc=filesystem_encoding) for p in m.paths(rows) if p] md = QMimeData() md.setData('application/calibre+from_device', 'dummy') md.setUrls([QUrl.fromLocalFile(p) for p in paths]) drag = QDrag(self) drag.setMimeData(md) cover = self.drag_icon(m.cover(self.currentIndex().row()), len(paths) > 1) drag.setHotSpot(QPoint(-15, -15)) drag.setPixmap(cover) return drag
def mimeData(self, indexes): ''' @param: indexes QModelIndexList @return: QMimeData ''' mimeData = QMimeData() self._tmpMimeItems = [] for index in indexes: # If item's parent (=folder) is also selected, we will just move the # whole folder if index.isValid() and index.column() == 0 and index.parent() not in indexes: item = index.internalPointer() assert(isinstance(item, BookmarkItem)) self._tmpMimeItems.append(item) mimeData.setData(self.MIMETYPE, b'') return mimeData
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(unicode(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 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 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 mouseMoveEvent(self, event): ''' @param: event QMouseEvent ''' super().mouseMoveEvent(event) if gVar.app.plugins().processMouseMove(const.ON_TabBar, self, event): return if self.count() == 1 and gVar.app.windowCount() == 1: return if not self._dragStartPosition.isNull(): offset = 0 eventY = event.pos().y() if eventY < 0: offset = abs(eventY) elif eventY > self.height(): offset = eventY - self.height() if offset > QApplication.startDragDistance() * 3: global_ = self.mapToGlobal(self._dragStartPosition) w = QApplication.widgetAt(global_) if w: mouse = QMouseEvent(QEvent.MouseButtonRelease, w.mapFromGlobal(global_), Qt.LeftButton, Qt.LeftButton, event.modifiers()) QApplication.sendEvent(w, mouse) drag = QDrag(self) mime = QMimeData() mime.setData(self.MIMETYPE, b'') drag.setMimeData(mime) drag.setPixmap(self.tabPixmap(self.currentIndex())) if drag.exec_() == Qt.IgnoreAction: self._tabWidget.detachTabByIndex(self.currentIndex()) return
def mimeData(self, indexes): data = ','.join(str(i.row()) for i in indexes) md = QMimeData() md.setData('application/calibre_charcode_indices', data.encode('utf-8')) return md
def mimeData(self, indexes): data = ",".join(str(i.row()) for i in indexes) md = QMimeData() md.setData("application/calibre_charcode_indices", data.encode("utf-8")) return md
def mimeData(self, indexes): data = ','.join(str(i.row()) for i in indexes) md = QMimeData() md.setData('application/calibre_charcode_indices', data.encode('utf-8')) return md
def mimeData(self, indexes): result = QMimeData() node = self.qt_index_to_node(indexes[0]) path_data = encode_project_tree_node_path(node.abs_name_path) result.setData(PROJECT_TREE_NODE_PATH_MEDIA_TYPE, path_data) return result
def date_time_copied(self, text): md = QMimeData() md.setText(text or self.dateTime().toString()) md.setData(LineEditForDateTimeEdit.MIME_TYPE, self.dateTime().toString(Qt.ISODate).encode('ascii')) QApplication.instance().clipboard().setMimeData(md)