--- a/eric6/QScintilla/Shell.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/QScintilla/Shell.py Sat May 01 14:27:20 2021 +0200 @@ -9,8 +9,8 @@ import sys import re - -from enum import Enum +import contextlib +import enum from PyQt5.QtCore import pyqtSignal, pyqtSlot, QFileInfo, Qt, QEvent from PyQt5.QtGui import QClipboard, QPalette, QFont @@ -52,7 +52,7 @@ @param parent parent widget @type QWidget """ - super(ShellAssembly, self).__init__(parent) + super().__init__(parent) self.__shell = Shell(dbs, vm, project, False, self) @@ -92,13 +92,13 @@ return self.__shell -class ShellHistoryStyle(Enum): +class ShellHistoryStyle(enum.Enum): """ Class defining the shell history styles. """ - Disabled = 0 - LinuxStyle = 1 - WindowsStyle = 2 + DISABLED = 0 + LINUXSTYLE = 1 + WINDOWSSTYLE = 2 class Shell(QsciScintillaCompat): @@ -136,7 +136,7 @@ @param parent parent widget @type QWidget """ - super(Shell, self).__init__(parent) + super().__init__(parent) self.setUtf8(True) self.vm = vm @@ -242,7 +242,8 @@ dbs.mainClientExit.connect(self.__writePrompt) self.dbs = dbs - self.__debugUI = None + # will register a method to get the debugger ID to work with + self.__getSelectedDebuggerId = None # Make sure we have prompts. if self.passive: @@ -483,16 +484,13 @@ if Preferences.getEditor("ShowWhitespace"): self.setWhitespaceVisibility( QsciScintilla.WhitespaceVisibility.WsVisible) - try: + with contextlib.suppress(AttributeError): self.setWhitespaceForegroundColor( Preferences.getEditorColour("WhitespaceForeground")) self.setWhitespaceBackgroundColor( Preferences.getEditorColour("WhitespaceBackground")) self.setWhitespaceSize( Preferences.getEditor("WhitespaceSize")) - except AttributeError: - # QScintilla before 2.5 doesn't support this - pass else: self.setWhitespaceVisibility( QsciScintilla.WhitespaceVisibility.WsInvisible) @@ -614,7 +612,17 @@ @param ui reference to the debugger UI object (DebugUI) """ ui.exceptionInterrupt.connect(self.__writePrompt) - self.__debugUI = ui + self.registerDebuggerIdMethod(ui.getSelectedDebuggerId) + + def registerDebuggerIdMethod(self, method): + """ + Public method to register a method to get the debugger ID to send data + to. + + @param method reference to the method + @type function + """ + self.__getSelectedDebuggerId = method def __initialise(self): """ @@ -675,7 +683,7 @@ # determine based on history style if ( self.clientType and - self.__historyStyle == ShellHistoryStyle.WindowsStyle + self.__historyStyle == ShellHistoryStyle.WINDOWSSTYLE ): idx = int(Preferences.Prefs.settings.value( "Shell/HistoryIndexes/" + self.clientType, -1)) @@ -690,7 +698,7 @@ self.__histidx = -1 if ( self.clientType and - self.__historyStyle == ShellHistoryStyle.WindowsStyle + self.__historyStyle == ShellHistoryStyle.WINDOWSSTYLE ): Preferences.Prefs.settings.setValue( "Shell/HistoryIndexes/" + self.clientType, self.__histidx) @@ -842,7 +850,7 @@ @param venvName name of the virtual environment @type str """ - super(Shell, self).clear() + super().clear() if self.passive and not self.dbs.isConnected(): self.__write(self.tr('Passive Debug Mode')) self.__write(self.tr('\nNot connected')) @@ -892,26 +900,26 @@ if ( not self.__windowed and - Preferences.getDebugger("ShowExceptionInShell") + Preferences.getDebugger("ShowExceptionInShell") and + exceptionType ): - if exceptionType: - if stackTrace: - self.__write( - self.tr('Exception "{0}"\n{1}\nFile: {2}, Line: {3}\n') - .format( - exceptionType, - exceptionMessage, - stackTrace[0][0], - stackTrace[0][1] - ) + if stackTrace: + self.__write( + self.tr('Exception "{0}"\n{1}\nFile: {2}, Line: {3}\n') + .format( + exceptionType, + exceptionMessage, + stackTrace[0][0], + stackTrace[0][1] ) - else: - self.__write( - self.tr('Exception "{0}"\n{1}\n') - .format( - exceptionType, - exceptionMessage) - ) + ) + else: + self.__write( + self.tr('Exception "{0}"\n{1}\n') + .format( + exceptionType, + exceptionMessage) + ) def __clientSyntaxError(self, message, filename, lineNo, characterNo): """ @@ -1244,7 +1252,7 @@ lines = QApplication.clipboard().text(QClipboard.Mode.Selection) self.paste(lines) else: - super(Shell, self).mousePressEvent(event) + super().mousePressEvent(event) def wheelEvent(self, evt): """ @@ -1261,7 +1269,7 @@ evt.accept() return - super(Shell, self).wheelEvent(evt) + super().wheelEvent(evt) def event(self, evt): """ @@ -1274,7 +1282,7 @@ self.gestureEvent(evt) return True - return super(Shell, self).event(evt) + return super().event(evt) def gestureEvent(self, evt): """ @@ -1336,11 +1344,11 @@ self.prline, self.prcol = self.getCursorPosition() if self.__echoInput: ac = self.isListActive() - super(Shell, self).keyPressEvent(ev) + super().keyPressEvent(ev) self.incrementalSearchActive = True if ac and self.racEnabled: self.dbs.remoteCompletion( - self.__debugUI.getSelectedDebuggerId(), + self.__getSelectedDebuggerId(), self.completionText + txt ) else: @@ -1375,7 +1383,7 @@ self.SendScintilla(cmd) elif self.racEnabled: self.dbs.remoteCompletion( - self.__debugUI.getSelectedDebuggerId(), + self.__getSelectedDebuggerId(), buf ) @@ -1406,7 +1414,7 @@ if db and ac and self.racEnabled and self.completionText: delta = len(self.text(line)) - oldLength self.dbs.remoteCompletion( - self.__debugUI.getSelectedDebuggerId(), + self.__getSelectedDebuggerId(), self.completionText[:delta] ) @@ -1799,9 +1807,9 @@ if len(self.__history) == self.__maxHistoryEntries: del self.__history[0] self.__history.append(cmd) - if self.__historyStyle == ShellHistoryStyle.LinuxStyle: + if self.__historyStyle == ShellHistoryStyle.LINUXSTYLE: self.__setHistoryIndex(index=-1) - elif self.__historyStyle == ShellHistoryStyle.WindowsStyle: + elif self.__historyStyle == ShellHistoryStyle.WINDOWSSTYLE: if historyIndex is None: if ( self.__histidx - 1 > 0 and @@ -1889,12 +1897,10 @@ return else: self.dbs.remoteStatement( - self.__debugUI.getSelectedDebuggerId(), cmd) + self.__getSelectedDebuggerId(), cmd) while self.inCommandExecution: - try: + with contextlib.suppress(KeyboardInterrupt): QApplication.processEvents() - except KeyboardInterrupt: - pass else: if not self.__echoInput: cmd = self.buff @@ -1962,10 +1968,7 @@ that something was found @rtype tuple of (int, bool) """ - if startIdx == -1: - idx = 0 - else: - idx = startIdx + 1 + idx = 0 if startIdx == -1 else startIdx + 1 while ( idx < len(self.__history) and not self.__history[idx].startswith(txt) @@ -1987,10 +1990,7 @@ that something was found @rtype tuple of (int, bool) """ - if startIdx == -1: - idx = len(self.__history) - 1 - else: - idx = startIdx - 1 + idx = len(self.__history) - 1 if startIdx == -1 else startIdx - 1 while ( idx >= 0 and not self.__history[idx].startswith(txt) @@ -2158,7 +2158,7 @@ if self.inDragDrop: event.acceptProposedAction() else: - super(Shell, self).dragEnterEvent(event) + super().dragEnterEvent(event) def dragMoveEvent(self, event): """ @@ -2169,7 +2169,7 @@ if self.inDragDrop: event.accept() else: - super(Shell, self).dragMoveEvent(event) + super().dragMoveEvent(event) def dragLeaveEvent(self, event): """ @@ -2181,7 +2181,7 @@ self.inDragDrop = False event.accept() else: - super(Shell, self).dragLeaveEvent(event) + super().dragLeaveEvent(event) def dropEvent(self, event): """ @@ -2209,7 +2209,7 @@ self.executeLines(s) del s else: - super(Shell, self).dropEvent(event) + super().dropEvent(event) self.inDragDrop = False @@ -2234,14 +2234,12 @@ self.vm.searchPrevAct.shortcut(), self, self.__searchPrev, self.__searchPrev) - try: + with contextlib.suppress(AttributeError): self.vm.editActGrp.setEnabled(False) self.vm.editorActGrp.setEnabled(True) self.vm.copyActGrp.setEnabled(True) self.vm.viewActGrp.setEnabled(True) self.vm.searchActGrp.setEnabled(False) - except AttributeError: - pass if not self.__windowed: self.__searchShortcut.setEnabled(True) self.__searchNextShortcut.setEnabled(True) @@ -2249,7 +2247,7 @@ self.setCaretWidth(self.caretWidth) self.setCursorFlashTime(QApplication.cursorFlashTime()) - super(Shell, self).focusInEvent(event) + super().focusInEvent(event) def focusOutEvent(self, event): """ @@ -2257,16 +2255,14 @@ @param event the event object (QFocusEvent) """ - try: + with contextlib.suppress(AttributeError): self.vm.editorActGrp.setEnabled(False) - except AttributeError: - pass if not self.__windowed: self.__searchShortcut.setEnabled(False) self.__searchNextShortcut.setEnabled(False) self.__searchPrevShortcut.setEnabled(False) self.setCaretWidth(0) - super(Shell, self).focusOutEvent(event) + super().focusOutEvent(event) def insert(self, txt): """ @@ -2378,7 +2374,7 @@ @return flag indicating if history is enabled @rtype bool """ - return self.__historyStyle != ShellHistoryStyle.Disabled + return self.__historyStyle != ShellHistoryStyle.DISABLED ################################################################# ## Project Support