def cut_line(self): """ If no text selected, cut whole current line to clipboard. """ textCursor = self.editor.textCursor() if textCursor.hasSelection(): return textCursor.select(QtGui.QTextCursor.LineUnderCursor) text = textCursor.selectedText() textCursor.insertText('') QtGui.QClipboard().setText(text)
def copy_block_or_selection(self): """ If there's no text selected, copy the current block. """ textCursor = self.editor.textCursor() selection = textCursor.selection() text = selection.toPlainText() if not text: textCursor.select(QtGui.QTextCursor.BlockUnderCursor) selection = textCursor.selection() text = selection.toPlainText() QtGui.QClipboard().setText(text)
def copy_tab_file_path(self, index): """ Copy the current tab's file path (if it has one) to the clipboard. """ data = self.tabData(index) path = data.get('path') if path is None or not path.strip(): print('No file path for "{0}".'.format(data['name'])) return clipboard = QtGui.QClipboard() clipboard.setText(path) print('Path copied to clipboard:') print(path)