def __onCopy(self): """Copy the content as text to clipboard""" content = [] lhsMaxLength = 0 try: item = self.calltraceList.topLevelItem(0) while item is not None: call = '<-' if item.data(0, Qt.UserRole): call = '->' lhs = item.text(1) lhsLength = len(lhs) lhsMaxLength = max(lhsMaxLength, lhsLength) content.append([lhs, lhsLength, call + ' ' + item.text(2)]) item = self.calltraceList.itemBelow(item) for index in range(len(content)): content[index] = \ content[index][0] + \ ' ' * (lhsMaxLength - content[index][1] + 1) + \ content[index][2] QApplication.clipboard().setText('\n'.join(content)) except Exception as exc: logging.error('Error copying the call trace to clipboard: ' + str(exc))
def onCtrlC(self): """Handles copying""" if self.selectedText: QApplication.clipboard().setText(self.selectedText) else: line, _ = self.cursorPosition if self.lines[line]: QApplication.clipboard().setText(self.lines[line] + '\n')
def onCopyFileNameToClipboard(self): """Copies the file name of the current file into the clipboard""" txt = self.__getPathLabelFilePath() if txt.lower(): try: QApplication.clipboard().setText(os.path.basename(txt)) except: pass
def onCopyDirToClipboard(self): """Copies the dir path of the current file into the clipboard""" txt = self.__getPathLabelFilePath() if txt.lower(): try: QApplication.clipboard().setText(os.path.dirname(txt) + os.path.sep) except: pass
def onShiftDel(self): """Triggered when Shift+Del is received""" if self.selectedText: QApplication.clipboard().setText(self.selectedText) self.selectedText = '' else: line, _ = self.cursorPosition if self.lines[line]: QApplication.clipboard().setText(self.lines[line] + '\n') del self.lines[line]
def contextMenuEvent(self, event): """Called just before showing a context menu""" # Accepting needs to suppress the native menu event.accept() isPython = self.isPythonBuffer() readOnly = self.isReadOnly() self.__menuUndo.setEnabled(self.document().isUndoAvailable()) self.__menuRedo.setEnabled(self.document().isRedoAvailable()) self.__menuCut.setEnabled(not readOnly) self.__menuPaste.setEnabled(QApplication.clipboard().text() != "" and not readOnly) fileName = self._parent.getFileName() absFileName = os.path.isabs(fileName) self.__menuOpenAsFile.setEnabled(self.openAsFileAvailable()) self.__menuDownloadAndShow.setEnabled(self.downloadAndShowAvailable()) self.__menuOpenInBrowser.setEnabled(self.downloadAndShowAvailable()) self.__menuHighlightInPrj.setEnabled( absFileName and GlobalData().project.isProjectFile(fileName)) self.__menuHighlightInFS.setEnabled(absFileName) self._menuHighlightInOutline.setEnabled(isPython) self._menuHighlightInOutline.setEnabled(isPython) self.toolsMenu.setEnabled(isPython) if isPython: runEnabled = self._parent.runScriptButton.isEnabled() self.runAct.setEnabled(runEnabled) self.runParamAct.setEnabled(runEnabled) self.profileAct.setEnabled(runEnabled) self.profileParamAct.setEnabled(runEnabled) if absFileName: self.__menuClearEncoding.setEnabled( getFileEncoding(fileName) is not None) else: self.__menuClearEncoding.setEnabled( self.explicitUserEncoding is not None) # Check the proper encoding in the menu encoding = 'undefined' if absFileName: enc = getFileEncoding(fileName) if enc: encoding = enc else: if self.explicitUserEncoding: encoding = self.explicitUserEncoding encoding = getNormalizedEncoding(encoding, False) if absFileName: for act in self.encodingReloadActGrp.actions(): act.setChecked(encoding == getNormalizedEncoding(act.data())) else: self.encodingReloadMenu.setEnabled(False) for act in self.encodingWriteActGrp.actions(): act.setChecked(encoding == getNormalizedEncoding(act.data())) # Show the menu self._menu.popup(event.globalPos())
def onPasteText(self): """Triggered when insert is requested""" if self.mode == self.MODE_OUTPUT: return if self.absCursorPosition < self.lastOutputPos: return # Check what is in the buffer text = QApplication.clipboard().text() if '\n' in text or '\r' in text: return if not self.inputEcho: self.inputBuffer += text return self.paste()
def _contextMenuAboutToShow(self): """IO Console context menu is about to show""" self.__menuUndo.setEnabled(self.document().isUndoAvailable()) self.__menuRedo.setEnabled(self.document().isRedoAvailable()) pasteText = QApplication.clipboard().text() pasteEnable = pasteText != "" and \ '\n' not in pasteText and \ '\r' not in pasteText and \ self.mode != self.MODE_OUTPUT if pasteEnable: if self.absCursorPosition < self.lastOutputPos: pasteEnable = False # Need to make decision about menu items for modifying the input self.__menuCut.setEnabled(self.__isCutDelAvailable()) self.__menuCopy.setEnabled(self.__messages.size > 0) self.__menucopyTimestamp.setEnabled(self.__messages.size > 0) self.__menuPaste.setEnabled(pasteEnable) self.__menuSelectAll.setEnabled(self.__messages.size > 0) self.__menuOpenAsFile.setEnabled(self.openAsFileAvailable()) self.__menuDownloadAndShow.setEnabled(self.downloadAndShowAvailable()) self.__menuOpenInBrowser.setEnabled(self.downloadAndShowAvailable())
def _putMimeToClipboard(value): """Copies the value (string) to a clipboard as mime data""" mimeData = QMimeData() mimeData.setData('text/codimension', value.encode(DEFAULT_ENCODING)) QApplication.clipboard().setMimeData(mimeData)
def copyToClipboard(self): """Copies the rendered scene to the clipboard as an image""" image = self.__getPNG() clip = QApplication.clipboard() clip.setImage(image)
def onCopy(self): """Copies the diagram to the exchange buffer""" QApplication.clipboard().setImage(self.__getImage())
def onPathLabelDoubleClick(self): """Double click on the path label""" txt = self.__getPathLabelFilePath() if txt.lower(): QApplication.clipboard().setText(txt)
def onCtrlShiftC(self): """Copy all with timestamps""" QApplication.clipboard().setText( self.__messages.renderWithTimestamps())