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 startDrag(self, dropActions): """Reimplement Qt Method - handle drag event""" mimeData = QMimeData() mimeData.setText(self.get_filename()) drag = QDrag(self) drag.setMimeData(mimeData) drag.exec_()
def mousePressEvent( self, event ): # handle an internal move from PyQt4.QtCore import Qt # start a drag event if ( event.button() == Qt.LeftButton and self.dragDropRect().contains( event.pos() ) ): from PyQt4.QtCore import QMimeData from PyQt4.QtGui import QDrag, QPixmap # create the pixmap pixmap = QPixmap.grabWidget( self, self.rect() ) # create the mimedata mimeData = QMimeData() mimeData.setText( 'ItemTitle::%s' % (self.title()) ) # create the drag drag = QDrag(self) drag.setMimeData( mimeData ) drag.setPixmap( pixmap ) drag.setHotSpot( event.pos() ) if ( not drag.exec_() ): self._accordianWidget.emitItemDragFailed(self) event.accept() # determine if the expand/collapse should occur elif ( event.button() == Qt.LeftButton and self.expandCollapseRect().contains( event.pos() ) ): self._clicked = True event.accept() else: event.ignore()
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 copyCurrentCell(self): index = self.currentIndex() if index.isValid(): carrier = QMimeData() dataAsText = self.model().data(index, Qt.DisplayRole) carrier.setText(dataAsText.toString() if dataAsText else '') QtGui.qApp.clipboard().setMimeData(carrier)
def eventFilter( self, object, event ): if event.type() == event.MouseButtonPress: if self.isLocked(): return False if event.button() == Qt.MidButton or \ (event.button() == Qt.LeftButton and \ event.modifiers() == Qt.ShiftModifier): index = self.tabBar().tabAt(event.pos()) view = self.widget(index) pixmap = QPixmap.grabWidget(view) drag = QDrag(self) data = QMimeData() data.setText('move view:{}'.format(index)) drag.setMimeData(data) drag.setPixmap(pixmap) drag.exec_() return True return False elif event.type() == event.DragEnter: if ( str(event.mimeData().text()).startswith('move view:') and event.source() != self ): event.acceptProposedAction() return True elif event.type() == event.Drop: text = str(event.mimeData().text()) splt = text.split(':') self.snagViewFromPanel(event.source(), int(splt[1])) return True return False
def mousePressEvent(self, event): # handle an internal move # start a drag event if event.button() == Qt.LeftButton and self.dragDropRect().contains( event.pos()): # create the pixmap pixmap = QPixmap.grabWidget(self, self.rect()) # create the mimedata mimeData = QMimeData() mimeData.setText('ItemTitle::%s' % (self.title())) # create the drag drag = QDrag(self) drag.setMimeData(mimeData) drag.setPixmap(pixmap) drag.setHotSpot(event.pos()) if not drag.exec_(): self._accordianWidget.emitItemDragFailed(self) event.accept() # determine if the expand/collapse should occur elif event.button() == Qt.LeftButton and self.expandCollapseRect( ).contains(event.pos()): self._clicked = True event.accept() else: event.ignore()
def mimeData(self, indexes): idList = set() for index in indexes: idList.add(forceString(self.idList()[index.row()])) mimeData = QMimeData() mimeData.setText(u','.join(idList)) return mimeData
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 _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 on_menuSelections_mouseMoved(self, event): if event.buttons() & Qt.LeftButton and self.seldrag_start_pos: if ((event.pos() - self.seldrag_start_pos).manhattanLength() >= QApplication.startDragDistance()): drag = QDrag(self.menuSelections) data = QMimeData() data.setText(self.seldrag_selection.name) drag.setMimeData(data) drag.exec_() self.seldrag_start_pos = None self.seldrag_selection = None self.seldrag_target = None QMenu.mouseMoveEvent(self.menuSelections, event)
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 mouseMoveEvent(self, mouseEvent): # if mouseEvent.button() != Qt.LeftButton: # return if not self._selectedExperiment(): return if not self.dragStartPosition: return if (mouseEvent.pos() - self.dragStartPosition).manhattanLength() < QApplication.startDragDistance(): return drag = QDrag(self) mimeData = QMimeData() mimeData.setText(self._selectedExperiment().__name__) drag.setMimeData(mimeData) drag.exec_()
def mouseMoveEvent(self, event): # Chequear que se esté presionando el botón derecho if not (event.buttons() and Qt.LeftButton): return # Verificar que sea una posición válida if ((event.pos() - self.drag_start_position).manhattanLength() < QApplication.startDragDistance()): return drag = QDrag(self) mime_data = QMimeData() # Establecer el contenido del widget como dato drag.setMimeData(mime_data) mime_data.setText(self.label2.text()) # Ejecutar la acción self.drop_action = drag.exec_(Qt.CopyAction | Qt.MoveAction)
def mimeData(self, items): """ Creates the mime data for the different items. :param items | [<QListWidgetItem>, ..] :return <QMimeData> """ text = [] for item in items: text.append(str(item.text())) data = QMimeData() data.setText(','.join(text)) return data
def mouseMoveEvent(self, event): if not (event.buttons() and Qt.LeftButton): return if ((event.pos() - self.drag_start_position).manhattanLength() < QApplication.startDragDistance()): return drag = QDrag(self) pix = QPixmap.grabWidget(self) drag.setPixmap(pix) mime_data = QMimeData() mime_data.setText(self.map.text()) # mime_data.setImageData(self.currentmap) drag.setMimeData(mime_data) self.drop_action = drag.exec_(Qt.CopyAction | Qt.MoveAction)
def start_drag(self, info_id): _logger.info( "started dragging" ) mimeData = QMimeData() mimeData.data =("/" + info_id.partition("/")[2].partition("/")[0], moose.element(info_id)) mimeData.setText(info_id) drag = QDrag(self) drag.setMimeData(mimeData) pixmap = QPixmap("") drag.setPixmap(pixmap) # drag.setHotSpot(e.pos() - self.rect().topLeft()) dropAction = drag.start(QtCore.Qt.MoveAction) print((" => ", dropAction)) self.select_info.set_event_type(0) self._timer.start(0) return
def mouseMoveEvent(self, event): """ Protected method to handle mouse move events. @param event reference to the mouse move event (QMouseEvent) """ if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \ (event.pos() - self.__dragStartPos).manhattanLength() > \ QApplication.startDragDistance(): drag = QDrag(self) mimeData = QMimeData() index = self.tabAt(event.pos()) mimeData.setText(self.tabText(index)) mimeData.setData("action", "tab-reordering") mimeData.setData("tabbar-id", str(id(self))) drag.setMimeData(mimeData) drag.exec_() E4WheelTabBar.mouseMoveEvent(self, event)
def start_drag(self, info_id): # pixmap = QPixmap() # painter = QPainter( pixmap ) # painter.setFont( QFont("Arial") ); # painter.drawText( QPoint(100, 100), info_id ); mimeData = QMimeData() mimeData.data =("/" + info_id.partition("/")[2].partition("/")[0], moose.element(info_id)) mimeData.setText(info_id) drag = QDrag(self) drag.setMimeData(mimeData) pixmap = QPixmap("") drag.setPixmap(pixmap) # drag.setHotSpot(e.pos() - self.rect().topLeft()) dropAction = drag.start(QtCore.Qt.MoveAction) print(" => ", dropAction) self.select_info.set_event_type(0) self._timer.start(0) return
def mouseMoveEvent(self, e): if self.drag_start is None: pass x = e.x() - self.drag_start.x() y = e.y() - self.drag_start.y() dist = QApplication.startDragDistance() if not self.draggable or x > dist or y > dist: return drag = QDrag(self) mime = QMimeData() mime.setText(self.__class__.__name__) mime.part = self drag.setMimeData(mime) pixmap = QPixmap.grabWidget(self) pixmap.setAlphaChannel(pixmap) drag.setPixmap(pixmap) drag.setHotSpot(QPoint(drag.pixmap().width() / 2, drag.pixmap().height())) drag.start(Qt.CopyAction)
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 mouseMoveEvent(self, e): if self.drag_start is None: pass x = e.x() - self.drag_start[0] y = e.y() - self.drag_start[1] dist = QApplication.startDragDistance() if (self.draggable is False) or (abs(x) < dist and abs(y) < dist): return drag = QDrag(self) mime = QMimeData() mime.setText(self.__class__.__name__) mime.part = self drag.setMimeData(mime) pixmap = QPixmap.grabWidget(self) pixmap.setAlphaChannel(pixmap) drag.setPixmap(pixmap) drag.setHotSpot(QPoint(drag.pixmap().width() / 2, drag.pixmap().height())) self.dragging = True drag.start(Qt.CopyAction)
def mouseMoveEvent(self, event): drag = QDrag(event.widget()) data = QMimeData() data.setText(self.commit.name()) drag.setMimeData(data) #data.setColorData(GREEN) pixmap = QPixmap(COMMIT_WIDTH, COMMIT_HEIGHT) pixmap.fill(WHITE) painter = QPainter(pixmap) painter.translate(0, 0) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(self.color)) painter.drawPath(self.setup_display(0, 0)) painter.end() pixmap.setMask(pixmap.createHeuristicMask()) drag.setPixmap(pixmap) drag.setHotSpot(QPoint(0, 0)) drag.start()
def mouseMoveEvent(self, event): if not (event.buttons() and Qt.LeftButton): return currentItem = self.currentItem() if(currentItem.isFile()): if(currentItem.isPic()): currentItemName = self.currentItem().getPath() data = QByteArray() stream = QDataStream(data, QIODevice.WriteOnly) stream.writeQString(currentItemName) icon = Icons.image pixmap = icon.pixmap(64, 64) mimeData = QMimeData() mimeData.setText(currentItemName) mimeData.setData('application/x-item', data) drag = QDrag(self) drag.setPixmap(pixmap) drag.setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2)) drag.setMimeData(mimeData) dropAction = drag.start(Qt.CopyAction)
def mimeFromText(self, text): mime = QMimeData() mime.setText(text) return mime
def _mimeDataInput(items): mimeData = QMimeData() text = items[0].text(0) mimeData.setText(text) return mimeData
def _mimeDataAlgorithm(items): item = items[0] if isinstance(item, TreeAlgorithmItem): mimeData = QMimeData() mimeData.setText(item.alg.commandLineName()) return mimeData
def _drag_text ( self, text ): mime_data = QMimeData() mime_data.setText( text ) return mime_data
def createMimeDataFromSelection(self): """Reimplemented to only copy plain text.""" m = QMimeData() m.setText(self.textCursor().selection().toPlainText()) return m