diff -r fb0ef164f536 -r 698ae46f40a4 eric6/QScintilla/MiniEditor.py --- a/eric6/QScintilla/MiniEditor.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/QScintilla/MiniEditor.py Sat May 01 14:27:20 2021 +0200 @@ -9,6 +9,9 @@ import os import re +import contextlib + +import editorconfig from PyQt5.QtCore import ( pyqtSignal, Qt, QSignalMapper, QPoint, QTimer, QFileInfo, QSize, @@ -39,8 +42,6 @@ import Utilities import Preferences -from ThirdParty.EditorConfig import editorconfig - class MiniScintilla(QsciScintillaCompat): """ @@ -67,7 +68,7 @@ @param parent parent widget @type QWidget """ - super(MiniScintilla, self).__init__(parent) + super().__init__(parent) self.mw = parent @@ -94,7 +95,7 @@ if text in matchingPairs: self.delete() - super(MiniScintilla, self).editorCommand(cmd) + super().editorCommand(cmd) def keyPressEvent(self, ev): """ @@ -113,10 +114,7 @@ @type str """ startChar = encString[0] - if len(encString) == 2: - endChar = encString[1] - else: - endChar = startChar + endChar = encString[1] if len(encString) == 2 else startChar sline, sindex, eline, eindex = self.getSelection() replaceText = startChar + self.selectedText() + endChar @@ -129,13 +127,15 @@ # See it is text to insert. if len(txt) and txt >= " ": - if self.hasSelectedText(): - if txt in MiniScintilla.EncloseChars: - encloseSelectedText(MiniScintilla.EncloseChars[txt]) - ev.accept() - return + if ( + self.hasSelectedText() and + txt in MiniScintilla.EncloseChars + ): + encloseSelectedText(MiniScintilla.EncloseChars[txt]) + ev.accept() + return - super(MiniScintilla, self).keyPressEvent(ev) + super().keyPressEvent(ev) else: ev.ignore() @@ -152,14 +152,12 @@ @type QFocusEvent """ self.mw.editorActGrp.setEnabled(True) - try: + with contextlib.suppress(AttributeError): self.setCaretWidth(self.mw.caretWidth) - except AttributeError: - pass self.setCursorFlashTime(QApplication.cursorFlashTime()) - super(MiniScintilla, self).focusInEvent(event) + super().focusInEvent(event) def focusOutEvent(self, event): """ @@ -171,7 +169,7 @@ self.mw.editorActGrp.setEnabled(False) self.setCaretWidth(0) - super(MiniScintilla, self).focusOutEvent(event) + super().focusOutEvent(event) def removeTrailingWhitespace(self): """ @@ -216,7 +214,7 @@ @param parent reference to the parent widget (QWidget) @param name object name of the window (string) """ - super(MiniEditor, self).__init__(parent) + super().__init__(parent) if name is not None: self.setObjectName(name) self.setWindowIcon(UI.PixmapCache.getIcon("editor")) @@ -2740,7 +2738,7 @@ if "[*]" not in self.windowTitle(): self.setWindowTitle(self.tr("[*] - {0}") .format(self.tr("Mini Editor"))) - super(MiniEditor, self).setWindowModified(modified) + super().setWindowModified(modified) def __setCurrentFile(self, fileName): """ @@ -2750,10 +2748,11 @@ """ self.__curFile = fileName - if not self.__curFile: - shownName = self.tr("Untitled") - else: - shownName = self.__strippedName(self.__curFile) + shownName = ( + self.tr("Untitled") + if not self.__curFile else + self.__strippedName(self.__curFile) + ) self.setWindowTitle(self.tr("{0}[*] - {1}") .format(shownName, self.tr("Mini Editor"))) @@ -2862,10 +2861,8 @@ self.__textEdit.setMarginWidth(2, 16) if Preferences.getEditor("FoldingMargin"): folding = Preferences.getEditor("FoldingStyle") - try: + with contextlib.suppress(AttributeError): folding = QsciScintilla.FoldStyle(folding) - except AttributeError: - pass self.__textEdit.setFolding(folding) self.__textEdit.setFoldMarginColors( Preferences.getEditorColour("FoldmarginBackground"), @@ -3399,10 +3396,11 @@ self.__textEdit.SCN_STYLENEEDED.connect(self.__styleNeeded) # get the font for style 0 and set it as the default font - if pyname and pyname.startswith("Pygments|"): - key = 'Scintilla/Guessed/style0/font' - else: - key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) + key = ( + 'Scintilla/Guessed/style0/font' + if pyname and pyname.startswith("Pygments|") else + 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) + ) fdesc = Preferences.Prefs.settings.value(key) if fdesc is not None: font = QFont(fdesc[0], int(fdesc[1])) @@ -3457,10 +3455,10 @@ if not bindName and line0.startswith("#!"): # #! marker detection - if "python3" in line0: - bindName = "dummy.py" - self.filetype = "Python3" - elif "python" in line0: + if ( + "python3" in line0 or + "python" in line0 + ): bindName = "dummy.py" self.filetype = "Python3" elif ("/bash" in line0 or "/sh" in line0): @@ -3549,10 +3547,11 @@ else: wc = re.sub(r'\w', "", wc) pattern = r"\b[\w{0}]+\b".format(re.escape(wc)) - if self.__textEdit.caseSensitive(): - rx = re.compile(pattern) - else: - rx = re.compile(pattern, re.IGNORECASE) + rx = ( + re.compile(pattern) + if self.__textEdit.caseSensitive() else + re.compile(pattern, re.IGNORECASE) + ) text = self.text(line) for match in rx.finditer(text):